diff options
author | Ted Gould <ted@gould.cx> | 2010-08-12 09:17:03 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-08-12 09:17:03 -0500 |
commit | 119941934dcab783d210bb53f3e70672546f023e (patch) | |
tree | a3a8e6eb667115eafeb9c0ac8a37097b7f3954a2 | |
parent | 2189e180cb8b7b2c1c9782b82c5e674d0f989515 (diff) | |
parent | 41550341b50d18b486da80165764e057adcc2460 (diff) | |
download | ayatana-indicator-session-119941934dcab783d210bb53f3e70672546f023e.tar.gz ayatana-indicator-session-119941934dcab783d210bb53f3e70672546f023e.tar.bz2 ayatana-indicator-session-119941934dcab783d210bb53f3e70672546f023e.zip |
Fixing the lock screen functionality to match the new design.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/indicator-session.c | 3 | ||||
-rw-r--r-- | src/lock-helper.c | 85 | ||||
-rw-r--r-- | src/lock-helper.h | 2 | ||||
-rw-r--r-- | src/session-service.c | 44 |
5 files changed, 50 insertions, 85 deletions
diff --git a/configure.ac b/configure.ac index c9110d3..10aba69 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ AC_SUBST(APPLET_LIBS) DBUSMENUGLIB_REQUIRED_VERSION=0.1.1 PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION + dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION gio-unix-2.0 indicator >= $INDICATOR_REQUIRED_VERSION) diff --git a/src/indicator-session.c b/src/indicator-session.c index dc23139..a1f1667 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -122,6 +122,9 @@ indicator_session_init (IndicatorSession *self) dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item); dbusmenu_client_add_type_handler(client, RESTART_ITEM_TYPE, build_restart_item); + GtkAccelGroup * agroup = gtk_accel_group_new(); + dbusmenu_gtkclient_set_accel_group(DBUSMENU_GTKCLIENT(client), agroup); + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); self->service_proxy = dbus_g_proxy_new_for_name(session_bus, INDICATOR_SESSION_DBUS_NAME, diff --git a/src/lock-helper.c b/src/lock-helper.c index ba6b182..9b15070 100644 --- a/src/lock-helper.c +++ b/src/lock-helper.c @@ -176,9 +176,11 @@ build_gss_proxy (void) static gboolean activate_timeout (gpointer data) { + /* Clear the ID for the timeout */ guint * address = (guint *)data; *address = 0; + /* Quit the mainloop */ if (gss_mainloop != NULL) { g_main_loop_quit(gss_mainloop); } @@ -186,22 +188,6 @@ activate_timeout (gpointer data) return FALSE; } -/* Handle errors from activating the screensaver */ -static void -active_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer user_data) -{ - GError * error = NULL; - - dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INVALID); - - if (error != NULL) { - g_warning("Unable to activate screensaver: %s", error->message); - g_error_free(error); - } - - return; -} - /* A fun little function to actually lock the screen. If, that's what you want, let's do it! */ void @@ -212,19 +198,10 @@ lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data) build_gss_proxy(); g_return_if_fail(gss_proxy != NULL); - if (will_lock_screen()) { - dbus_g_proxy_call_no_reply(gss_proxy, - "Lock", - G_TYPE_INVALID, - G_TYPE_INVALID); - } else { - dbus_g_proxy_begin_call(gss_proxy, - "SetActive", - active_cb, NULL, - NULL, - G_TYPE_BOOLEAN, TRUE, - G_TYPE_INVALID); - } + dbus_g_proxy_call_no_reply(gss_proxy, + "Lock", + G_TYPE_INVALID, + G_TYPE_INVALID); if (gss_mainloop == NULL) { gss_mainloop = g_main_loop_new(NULL, FALSE); @@ -253,53 +230,3 @@ lock_screen_setup (gpointer data) return FALSE; } -/* When the GConf key changes we need to adjust the text on - what we're going to do with the menu item */ -static void -lockscreen_update (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data) { - DbusmenuMenuitem * mi = (DbusmenuMenuitem*) data; - const gchar * key = gconf_entry_get_key (entry); - - if(g_strcmp0 (key, GCONF_KEY) == 0) { - if (will_lock_screen()) { - dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); - } else { - dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver")); - } - } -} - -/* Notification handler for lock menuitems. */ -static guint lock_notify = 0; - -/* Sets the menu item to be updating. There can - only be one. So we clear and reset if we get - another. */ -void -lock_screen_update_item (DbusmenuMenuitem * mi) -{ - if (gconf_client == NULL) { - gconf_client = gconf_client_get_default(); - } - - if (lock_notify == 0) { - gconf_client_add_dir (gconf_client, - GCONF_DIR, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - } - - if (lock_notify != 0) { - gconf_client_notify_remove(gconf_client, lock_notify); - lock_notify = 0; - } - - lock_notify = gconf_client_notify_add(gconf_client, - GCONF_KEY, - lockscreen_update, - mi, - NULL, - NULL); - - return; -} diff --git a/src/lock-helper.h b/src/lock-helper.h index 1d707d8..37f1448 100644 --- a/src/lock-helper.h +++ b/src/lock-helper.h @@ -31,6 +31,4 @@ gboolean will_lock_screen (void); void lock_screen (DbusmenuMenuitem * mi, guint timestamp, gpointer data); gboolean lock_screen_setup (gpointer data); -void lock_screen_update_item (DbusmenuMenuitem * mi); - #endif /* LOCK_HELPER_H__ */ diff --git a/src/session-service.c b/src/session-service.c index 231acad..1d8cd3a 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -36,6 +36,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libdbusmenu-glib/server.h> #include <libdbusmenu-glib/menuitem.h> #include <libdbusmenu-glib/client.h> +#include <libdbusmenu-gtk/menuitem.h> #include <libindicator/indicator-service.h> @@ -61,6 +62,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define LOCKDOWN_KEY_USER LOCKDOWN_DIR "/disable_user_switching" #define LOCKDOWN_KEY_SCREENSAVER LOCKDOWN_DIR "/disable_lock_screen" +#define KEYBINDING_DIR "/apps/gnome_settings_daemon/keybindings" +#define KEY_LOCK_SCREEN KEYBINDING_DIR "/screensaver" + typedef struct _ActivateData ActivateData; struct _ActivateData { @@ -119,6 +123,29 @@ lockdown_changed (GConfClient *client, return; } +static void +keybinding_changed (GConfClient *client, + guint cnxd_id, + GConfEntry *entry, + gpointer user_data) +{ + GConfValue *value = gconf_entry_get_value (entry); + const gchar *key = gconf_entry_get_key (entry); + + if (value == NULL || key == NULL) { + return; + } + + if (g_strcmp0 (key, KEY_LOCK_SCREEN) == 0) { + g_debug("Keybinding changed to: %s", gconf_value_get_string(value)); + if (lock_menuitem != NULL) { + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, gconf_value_get_string(value)); + } + } + + return; +} + /* Ensures that we have a GConf client and if we build one set up the signal handler. */ static void @@ -126,8 +153,12 @@ ensure_gconf_client (void) { if (!gconf_client) { gconf_client = gconf_client_get_default (); + gconf_client_add_dir(gconf_client, LOCKDOWN_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_notify_add(gconf_client, LOCKDOWN_DIR, lockdown_changed, NULL, NULL, NULL); + + gconf_client_add_dir(gconf_client, KEYBINDING_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + gconf_client_notify_add(gconf_client, KEYBINDING_DIR, keybinding_changed, NULL, NULL, NULL); } return; } @@ -516,14 +547,19 @@ rebuild_items (DbusmenuMenuitem *root, /* Lock screen item */ if (can_lockscreen) { lock_menuitem = dbusmenu_menuitem_new(); - if (will_lock_screen()) { - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); + dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Lock Screen")); + + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); } else { - dbusmenu_menuitem_property_set(lock_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _("Start Screensaver")); + g_debug("Unable to get lock screen shortcut."); } + g_signal_connect(G_OBJECT(lock_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(lock_screen), NULL); dbusmenu_menuitem_child_append(root, lock_menuitem); - lock_screen_update_item(lock_menuitem); } /* Set to NULL just incase we don't end up building one */ |