summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2012-11-06 17:47:05 -0500
committerColin Walters <walters@verbum.org>2012-11-06 21:05:03 -0500
commit32b0b2d85629ae765543df1d940a5ca3c37dcec1 (patch)
tree8445fb219a417458ade23b9ad71d2946e553afea
parent882d41ae99ed71e7cff1b9dffde44c7111d8d893 (diff)
downloadgnome-settings-daemon-wip/gnome-session-isactive.tar.gz
[wip] Port to gnome-session's SessionIsActive propertywip/gnome-session-isactive
Rather than maintaining the systemd code here, monitor gnome-session's SessionIsActive property. This allows us to drop the compile-time dependency on systemd. The power plugin is declared dependent on systemd at runtime, but the rest of the code should operate in more "basic functionality" mode.
-rw-r--r--configure.ac3
-rw-r--r--gnome-settings-daemon/gnome-settings-session.c233
-rw-r--r--gnome-settings-daemon/gnome-settings-session.h32
-rw-r--r--plugins/automount/gsd-automount-manager.c28
-rw-r--r--plugins/color/gsd-color-manager.c33
-rw-r--r--plugins/power/gsd-power-manager.c24
6 files changed, 52 insertions, 301 deletions
diff --git a/configure.ac b/configure.ac
index 7ebefe09..0128a6fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,6 @@ PKG_CHECK_MODULES(SETTINGS_DAEMON,
gmodule-2.0
gthread-2.0
gsettings-desktop-schemas >= 3.5.90
- libsystemd-login
)
PKG_CHECK_MODULES(SETTINGS_PLUGIN,
@@ -228,7 +227,7 @@ PKG_CHECK_MODULES(SOUND, [libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG libpulse-m
# ---------------------------------------------------------------------------
# Power
# ---------------------------------------------------------------------------
-PKG_CHECK_MODULES(POWER, upower-glib >= $UPOWER_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION libcanberra-gtk3 libnotify x11 xext)
+PKG_CHECK_MODULES(POWER, libsystemd-login upower-glib >= $UPOWER_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION libcanberra-gtk3 libnotify x11 xext)
if test x$have_gudev != xno; then
PKG_CHECK_MODULES(BACKLIGHT_HELPER,
diff --git a/gnome-settings-daemon/gnome-settings-session.c b/gnome-settings-daemon/gnome-settings-session.c
index e404a34f..226c12b2 100644
--- a/gnome-settings-daemon/gnome-settings-session.c
+++ b/gnome-settings-daemon/gnome-settings-session.c
@@ -30,239 +30,6 @@
#include "gnome-settings-session.h"
-typedef struct
-{
- GSource source;
- GPollFD pollfd;
- sd_login_monitor *monitor;
-} SdSource;
-
-static gboolean
-sd_source_prepare (GSource *source,
- gint *timeout)
-{
- *timeout = -1;
- return FALSE;
-}
-
-static gboolean
-sd_source_check (GSource *source)
-{
- SdSource *sd_source = (SdSource *)source;
-
- return sd_source->pollfd.revents != 0;
-}
-
-static gboolean
-sd_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-
-{
- SdSource *sd_source = (SdSource *)source;
- gboolean ret;
-
- g_warn_if_fail (callback != NULL);
-
- ret = (*callback) (user_data);
-
- sd_login_monitor_flush (sd_source->monitor);
- return ret;
-}
-
-static void
-sd_source_finalize (GSource *source)
-{
- SdSource *sd_source = (SdSource*)source;
-
- sd_login_monitor_unref (sd_source->monitor);
-}
-
-static GSourceFuncs sd_source_funcs = {
- sd_source_prepare,
- sd_source_check,
- sd_source_dispatch,
- sd_source_finalize
-};
-
-static GSource *
-sd_source_new (void)
-{
- GSource *source;
- SdSource *sd_source;
- int ret;
-
- source = g_source_new (&sd_source_funcs, sizeof (SdSource));
- sd_source = (SdSource *)source;
-
- if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
- {
- g_printerr ("Error getting login monitor: %d", ret);
- }
- else
- {
- sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
- sd_source->pollfd.events = G_IO_IN;
- g_source_add_poll (source, &sd_source->pollfd);
- }
-
- return source;
-}
-
-static void gnome_settings_session_finalize (GObject *object);
-
-#define GNOME_SETTINGS_SESSION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_SETTINGS_SESSION, GnomeSettingsSessionPrivate))
-
-struct GnomeSettingsSessionPrivate
-{
- GSource *sd_source;
- gchar *session_id;
- GnomeSettingsSessionState state;
-};
-
-enum {
- PROP_0,
- PROP_STATE,
- PROP_LAST
-};
-
-G_DEFINE_TYPE (GnomeSettingsSession, gnome_settings_session, G_TYPE_OBJECT)
-
-GnomeSettingsSessionState
-gnome_settings_session_get_state (GnomeSettingsSession *session)
-{
- g_return_val_if_fail (GNOME_IS_SETTINGS_SESSION (session),
- GNOME_SETTINGS_SESSION_STATE_UNKNOWN);
- return session->priv->state;
-}
-
-static void
-gnome_settings_session_set_state (GnomeSettingsSession *session,
- gboolean active)
-{
- GnomeSettingsSessionState state;
-
- state = active ? GNOME_SETTINGS_SESSION_STATE_ACTIVE
- : GNOME_SETTINGS_SESSION_STATE_INACTIVE;
- if (session->priv->state != state) {
- session->priv->state = state;
- g_object_notify (G_OBJECT (session), "state");
- }
-}
-
-static void
-gnome_settings_session_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GnomeSettingsSession *session = GNOME_SETTINGS_SESSION (object);
-
- switch (prop_id) {
- case PROP_STATE:
- g_value_set_enum (value, session->priv->state);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-GType
-gnome_settings_session_state_get_type (void)
-{
- static GType etype = 0;
- if (etype == 0) {
- static const GEnumValue values[] = {
- { GNOME_SETTINGS_SESSION_STATE_UNKNOWN,
- "unknown", "Unknown" },
- { GNOME_SETTINGS_SESSION_STATE_ACTIVE,
- "active", "Active" },
- { GNOME_SETTINGS_SESSION_STATE_INACTIVE,
- "inactive", "Inactive" },
- { 0, NULL, NULL }
- };
- etype = g_enum_register_static ("GnomeSettingsSessionState", values);
- }
- return etype;
-}
-
-static void
-gnome_settings_session_class_init (GnomeSettingsSessionClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = gnome_settings_session_get_property;
- object_class->finalize = gnome_settings_session_finalize;
- g_type_class_add_private (klass, sizeof (GnomeSettingsSessionPrivate));
-
- g_object_class_install_property (object_class,
- PROP_STATE,
- g_param_spec_enum ("state",
- "The session state",
- NULL,
- GNOME_TYPE_SETTINGS_SESSION_STATE,
- GNOME_SETTINGS_SESSION_STATE_UNKNOWN,
- G_PARAM_READABLE));
-}
-
-static gboolean
-sessions_changed (gpointer user_data)
-{
- GnomeSettingsSession *session = user_data;
- gboolean active;
-
- active = sd_session_is_active (session->priv->session_id);
- gnome_settings_session_set_state (session, active);
-
- return TRUE;
-}
-
-static void
-gnome_settings_session_init (GnomeSettingsSession *session)
-{
- session->priv = GNOME_SETTINGS_SESSION_GET_PRIVATE (session);
-
- sd_pid_get_session (getpid(), &session->priv->session_id);
-
- session->priv->sd_source = sd_source_new ();
- g_source_set_callback (session->priv->sd_source, sessions_changed, session, NULL);
- g_source_attach (session->priv->sd_source, NULL);
-
- sessions_changed (session);
-}
-
-static void
-gnome_settings_session_finalize (GObject *object)
-{
- GnomeSettingsSession *session;
-
- session = GNOME_SETTINGS_SESSION (object);
-
- g_free (session->priv->session_id);
-
- if (session->priv->sd_source != NULL) {
- g_source_destroy (session->priv->sd_source);
- g_source_unref (session->priv->sd_source);
- }
-
- G_OBJECT_CLASS (gnome_settings_session_parent_class)->finalize (object);
-}
-
-static GnomeSettingsSession *session;
-
-GnomeSettingsSession *
-gnome_settings_session_new (void)
-{
- if (session != NULL) {
- g_object_ref (session);
- } else {
- session = g_object_new (GNOME_TYPE_SETTINGS_SESSION, NULL);
- g_object_add_weak_pointer ((GObject*)session, (gpointer*)&session);
- }
-
- return session;
-}
-
#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager"
#define GNOME_SESSION_DBUS_OBJECT "/org/gnome/SessionManager"
#define GNOME_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
diff --git a/gnome-settings-daemon/gnome-settings-session.h b/gnome-settings-daemon/gnome-settings-session.h
index 1f7580da..0c9a1b79 100644
--- a/gnome-settings-daemon/gnome-settings-session.h
+++ b/gnome-settings-daemon/gnome-settings-session.h
@@ -26,38 +26,6 @@
G_BEGIN_DECLS
-#define GNOME_TYPE_SETTINGS_SESSION (gnome_settings_session_get_type ())
-#define GNOME_SETTINGS_SESSION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNOME_TYPE_SETTINGS_SESSION, GnomeSettingsSession))
-#define GNOME_SETTINGS_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNOME_TYPE_SETTINGS_SESSION, GnomeSettingsSessionClass))
-#define GNOME_IS_SETTINGS_SESSION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNOME_TYPE_SETTINGS_SESSION))
-#define GNOME_IS_SETTINGS_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNOME_TYPE_SETTINGS_SESSION))
-#define GNOME_SETTINGS_SESSION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNOME_TYPE_SETTINGS_SESSION, GnomeSettingsSessionClass))
-#define GNOME_TYPE_SETTINGS_SESSION_STATE (gnome_settings_session_state_get_type())
-
-typedef struct GnomeSettingsSessionPrivate GnomeSettingsSessionPrivate;
-
-typedef struct
-{
- GObject parent;
- GnomeSettingsSessionPrivate *priv;
-} GnomeSettingsSession;
-
-typedef struct
-{
- GObjectClass parent_class;
-} GnomeSettingsSessionClass;
-
-typedef enum {
- GNOME_SETTINGS_SESSION_STATE_UNKNOWN,
- GNOME_SETTINGS_SESSION_STATE_ACTIVE,
- GNOME_SETTINGS_SESSION_STATE_INACTIVE,
-} GnomeSettingsSessionState;
-
-GType gnome_settings_session_get_type (void);
-GType gnome_settings_session_state_get_type (void);
-GnomeSettingsSession *gnome_settings_session_new (void);
-GnomeSettingsSessionState gnome_settings_session_get_state (GnomeSettingsSession *session);
-
GDBusProxy *gnome_settings_session_get_session_proxy (void);
G_END_DECLS
diff --git a/plugins/automount/gsd-automount-manager.c b/plugins/automount/gsd-automount-manager.c
index 7912f191..d8e9e075 100644
--- a/plugins/automount/gsd-automount-manager.c
+++ b/plugins/automount/gsd-automount-manager.c
@@ -42,7 +42,7 @@ struct GsdAutomountManagerPrivate
GVolumeMonitor *volume_monitor;
unsigned int automount_idle_id;
- GnomeSettingsSession *session;
+ GDBusProxy *session;
gboolean session_is_active;
gboolean screensaver_active;
guint ss_watch_id;
@@ -288,17 +288,21 @@ mount_added_callback (GVolumeMonitor *monitor,
static void
-session_state_changed (GnomeSettingsSession *session, GParamSpec *pspec, gpointer user_data)
+session_props_changed (GDBusProxy *session, GVariant *v, char **props, gpointer user_data)
{
GsdAutomountManager *manager = user_data;
GsdAutomountManagerPrivate *p = manager->priv;
+ GVariant *active_v = NULL;
+ gboolean is_active;
- if (gnome_settings_session_get_state (session) == GNOME_SETTINGS_SESSION_STATE_ACTIVE) {
- p->session_is_active = TRUE;
- }
- else {
- p->session_is_active = FALSE;
- }
+ active_v = g_dbus_proxy_get_cached_property (session, "SessionIsActive");
+ if (!active_v)
+ return;
+
+ g_variant_get (active_v, "(b)", &is_active);
+ g_variant_unref (active_v);
+ g_printerr ("AUTOMOUNT: session is active: %d -> %d\n", p->session_is_active, is_active);
+ p->session_is_active = is_active;
if (!p->session_is_active) {
if (p->volume_queue != NULL) {
@@ -311,10 +315,10 @@ session_state_changed (GnomeSettingsSession *session, GParamSpec *pspec, gpointe
static void
do_initialize_session (GsdAutomountManager *manager)
{
- manager->priv->session = gnome_settings_session_new ();
- g_signal_connect (manager->priv->session, "notify::state",
- G_CALLBACK (session_state_changed), manager);
- session_state_changed (manager->priv->session, NULL, manager);
+ manager->priv->session = gnome_settings_session_get_session_proxy ();
+ g_signal_connect (manager->priv->session, "g-properties-changed",
+ G_CALLBACK (session_props_changed), manager);
+ session_props_changed (manager->priv->session, NULL, NULL, manager);
}
#define SCREENSAVER_NAME "org.gnome.ScreenSaver"
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index 999b88c4..df6d32ef 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -47,7 +47,7 @@
struct GsdColorManagerPrivate
{
- GnomeSettingsSession *session;
+ GDBusProxy *session;
CdClient *client;
GSettings *settings;
GcmProfileStore *profile_store;
@@ -55,7 +55,7 @@ struct GsdColorManagerPrivate
GnomeRRScreen *x11_screen;
GHashTable *edid_cache;
GdkWindow *gdk_window;
- GnomeSettingsSessionState session_state;
+ gboolean session_is_active;
GHashTable *device_assign_hash;
};
@@ -2213,17 +2213,26 @@ gcm_session_sensor_removed_cb (CdClient *client,
}
static void
-gcm_session_active_changed_cb (GnomeSettingsSession *session,
- GParamSpec *pspec,
+gcm_session_active_changed_cb (GDBusProxy *session,
+ GVariant *changed,
+ char **invalidated,
GsdColorManager *manager)
{
- GnomeSettingsSessionState state_new;
GsdColorManagerPrivate *priv = manager->priv;
+ GVariant *active_v = NULL;
+ gboolean is_active;
/* not yet connected to the daemon */
if (!cd_client_get_connected (priv->client))
return;
+ active_v = g_dbus_proxy_get_cached_property (session, "SessionIsActive");
+ if (!active_v)
+ return;
+
+ g_variant_get (active_v, "(b)", &is_active);
+ g_variant_unref (active_v);
+
/* When doing the fast-user-switch into a new account, load the
* new users chosen profiles.
*
@@ -2231,15 +2240,13 @@ gcm_session_active_changed_cb (GnomeSettingsSession *session,
* loaded, then we'll get a change from unknown to active
* and we want to avoid reprobing the devices for that.
*/
- state_new = gnome_settings_session_get_state (session);
- if (priv->session_state != GNOME_SETTINGS_SESSION_STATE_UNKNOWN &&
- state_new == GNOME_SETTINGS_SESSION_STATE_ACTIVE) {
+ if (is_active && !priv->session_is_active) {
g_warning ("Done switch to new account, reload devices");
cd_client_get_devices (manager->priv->client, NULL,
gcm_session_get_devices_cb,
manager);
}
- priv->session_state = state_new;
+ priv->session_is_active = is_active;
}
static void
@@ -2259,11 +2266,9 @@ gsd_color_manager_init (GsdColorManager *manager)
priv = manager->priv = GSD_COLOR_MANAGER_GET_PRIVATE (manager);
/* track the active session */
- priv->session = gnome_settings_session_new ();
- priv->session_state = gnome_settings_session_get_state (priv->session);
- g_signal_connect (priv->session, "notify::state",
- G_CALLBACK (gcm_session_active_changed_cb),
- manager);
+ priv->session = gnome_settings_session_get_session_proxy ();
+ g_signal_connect (priv->session, "g-properties-changed",
+ G_CALLBACK (gcm_session_active_changed_cb), manager);
/* set the _ICC_PROFILE atoms on the root screen */
priv->gdk_window = gdk_screen_get_root_window (gdk_screen_get_default ());
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index bf211f51..520b13f3 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -162,7 +162,7 @@ typedef enum {
struct GsdPowerManagerPrivate
{
- GnomeSettingsSession *session;
+ GDBusProxy *session;
gboolean lid_is_closed;
GSettings *settings;
GSettings *settings_screensaver;
@@ -2895,7 +2895,8 @@ idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode)
GError *error = NULL;
gint idle_percentage;
GsdPowerActionType action_type;
- GnomeSettingsSessionState state;
+ GVariant *active_v;
+ gboolean is_active = FALSE;
if (mode == manager->priv->current_idle_mode)
return;
@@ -2906,8 +2907,14 @@ idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode)
return;
/* ensure we're still on an active console */
- state = gnome_settings_session_get_state (manager->priv->session);
- if (state == GNOME_SETTINGS_SESSION_STATE_INACTIVE) {
+ active_v = g_dbus_proxy_get_cached_property (manager->priv->session_proxy,
+ "SessionIsActive");
+ if (active_v) {
+ g_variant_get (active_v, "(b)", &is_active);
+ g_variant_unref (active_v);
+ }
+
+ if (!is_active) {
g_debug ("ignoring state transition to %s as inactive",
idle_mode_to_string (mode));
return;
@@ -3513,8 +3520,9 @@ engine_settings_key_changed_cb (GSettings *settings,
}
static void
-engine_session_active_changed_cb (GnomeSettingsSession *session,
- GParamSpec *pspec,
+engine_session_active_changed_cb (GDBusProxy *session,
+ GVariant *changed,
+ char **invalidated,
GsdPowerManager *manager)
{
/* when doing the fast-user-switch into a new account,
@@ -3951,8 +3959,8 @@ gsd_power_manager_start (GsdPowerManager *manager,
inhibit_suspend (manager);
/* track the active session */
- manager->priv->session = gnome_settings_session_new ();
- g_signal_connect (manager->priv->session, "notify::state",
+ manager->priv->session = gnome_settings_session_get_session_proxy ();
+ g_signal_connect (manager->priv->session, "g-properties-changed",
G_CALLBACK (engine_session_active_changed_cb),
manager);