[Xfce4-commits] <libxfce4ui:master> Add startup notification support for shortcuts.

Nick Schermer noreply at xfce.org
Tue Nov 2 21:00:01 CET 2010


Updating branch refs/heads/master
         to c2ff4990dd3afb837c30d1724dec68c6de5b9ada (commit)
       from 8972f54c5d6ec20b6a07c8cf22e42d8b66257874 (commit)

commit c2ff4990dd3afb837c30d1724dec68c6de5b9ada
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Nov 2 20:51:45 2010 +0100

    Add startup notification support for shortcuts.

 libxfce4kbd-private/Makefile.am                 |   25 ++++++++++++++-
 libxfce4kbd-private/xfce-shortcuts-grabber.c    |   11 ++++--
 libxfce4kbd-private/xfce-shortcuts-marshal.list |    1 +
 libxfce4kbd-private/xfce-shortcuts-provider.c   |   38 +++++++++++++++++++++--
 libxfce4kbd-private/xfce-shortcuts-provider.h   |    4 ++-
 5 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/libxfce4kbd-private/Makefile.am b/libxfce4kbd-private/Makefile.am
index 4ea4e7b..abff01e 100644
--- a/libxfce4kbd-private/Makefile.am
+++ b/libxfce4kbd-private/Makefile.am
@@ -19,6 +19,10 @@ libxfce4kbd_headers = \
 	xfce-shortcut-dialog.h \
 	xfce-shortcuts.h
 
+libxfce4kbd_built_sources = \
+	xfce-shortcuts-marshal.c \
+	xfce-shortcuts-marshal.h
+
 libxfce4kbd_private_includedir = \
 	$(includedir)/xfce4/libxfce4kbd-private-$(LIBXFCE4KBD_PRIVATE_VERSION_API)/libxfce4kbd-private
 
@@ -27,7 +31,8 @@ libxfce4kbd_private_include_HEADERS = \
 
 libxfce4kbd_private_2_la_SOURCES = \
 	$(libxfce4kbd_headers) \
-  xfce-shortcuts-provider.c \
+	$(libxfce4kbd_built_sources) \
+	xfce-shortcuts-provider.c \
 	xfce-shortcuts-grabber.c \
 	xfce-shortcut-dialog.c \
 	xfce-shortcuts.c
@@ -62,8 +67,24 @@ settings_DATA = xfce4-keyboard-shortcuts.xml
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libxfce4kbd-private-2.pc
 
+if MAINTAINER_MODE
+xfce-shortcuts-marshal.h: xfce-shortcuts-marshal.list Makefile
+	$(AM_V_GEN) glib-genmarshal --prefix=_xfce_shortcuts_marshal --internal --header $< > $@
+
+xfce-shortcuts-marshal.c: xfce-shortcuts-marshal.list Makefile xfce-shortcuts-marshal.h
+	$(AM_V_GEN) echo "#include \"xfce-shortcuts-marshal.h\"" > $@ \
+	&& glib-genmarshal --prefix=_xfce_shortcuts_marshal --body $< >> $@
+
+DISTCLEANFILES = \
+	$(libxfce4kbd_built_sources)
+
+BUILT_SOURCES = \
+	$(libxfce4kbd_built_sources)
+endif
+
 EXTRA_DIST = \
-	$(settings_DATA)
+	$(settings_DATA) \
+	xfce-shortcuts-marshal.list
 
 # required for gtk-doc
 dist-hook: all
diff --git a/libxfce4kbd-private/xfce-shortcuts-grabber.c b/libxfce4kbd-private/xfce-shortcuts-grabber.c
index 6379432..c79a59c 100644
--- a/libxfce4kbd-private/xfce-shortcuts-grabber.c
+++ b/libxfce4kbd-private/xfce-shortcuts-grabber.c
@@ -36,6 +36,7 @@
 #include <libxfce4util/libxfce4util.h>
 
 #include <libxfce4kbd-private/xfce-shortcuts-grabber.h>
+#include <libxfce4kbd-private/xfce-shortcuts-marshal.h>
 
 
 
@@ -151,10 +152,10 @@ xfce_shortcuts_grabber_class_init (XfceShortcutsGrabberClass *klass)
                 0,
                 NULL,
                 NULL,
-                g_cclosure_marshal_VOID__STRING,
+                _xfce_shortcuts_marshal_VOID__STRING_INT,
                 G_TYPE_NONE,
-                1,
-                G_TYPE_STRING);
+                2,
+                G_TYPE_STRING, G_TYPE_INT);
 }
 
 
@@ -591,6 +592,7 @@ xfce_shortcuts_grabber_event_filter (GdkXEvent            *gdk_xevent,
 {
   struct EventKeyFindContext context;
   XEvent                    *xevent;
+  gint                       timestamp;
 
   g_return_val_if_fail (XFCE_IS_SHORTCUTS_GRABBER (grabber), GDK_FILTER_CONTINUE);
 
@@ -602,11 +604,12 @@ xfce_shortcuts_grabber_event_filter (GdkXEvent            *gdk_xevent,
   context.grabber = grabber;
   context.xevent = (XKeyEvent *) xevent;
   context.result = NULL;
+  timestamp = context.xevent->time;
 
   g_hash_table_foreach (grabber->priv->keys, (GHFunc) find_event_key, &context);
 
   if (G_LIKELY (context.result != NULL))
-    g_signal_emit_by_name (grabber, "shortcut-activated", context.result);
+    g_signal_emit_by_name (grabber, "shortcut-activated", context.result, timestamp);
 
   return GDK_FILTER_CONTINUE;
 }
diff --git a/libxfce4kbd-private/xfce-shortcuts-marshal.list b/libxfce4kbd-private/xfce-shortcuts-marshal.list
new file mode 100644
index 0000000..75d5d82
--- /dev/null
+++ b/libxfce4kbd-private/xfce-shortcuts-marshal.list
@@ -0,0 +1 @@
+VOID:STRING,INT
diff --git a/libxfce4kbd-private/xfce-shortcuts-provider.c b/libxfce4kbd-private/xfce-shortcuts-provider.c
index 97780ea..054cf40 100644
--- a/libxfce4kbd-private/xfce-shortcuts-provider.c
+++ b/libxfce4kbd-private/xfce-shortcuts-provider.c
@@ -85,6 +85,7 @@ struct _XfceShortcutsProviderContext
   XfceShortcutsProvider *provider;
   GList                 *list;
   const gchar           *base_property;
+  GHashTable            *properties;
 };
 
 
@@ -295,6 +296,9 @@ xfce_shortcuts_provider_property_changed (XfconfChannel         *channel,
     }
   g_free (override_property);
 
+  if (g_str_has_suffix (property, "/startup-notify"))
+    return;
+
   shortcut = property + strlen (provider->priv->custom_base_property) + strlen ("/");
 
   if (G_VALUE_TYPE (value) != G_TYPE_INVALID)
@@ -457,6 +461,8 @@ _xfce_shortcuts_provider_get_shortcut (const gchar                  *property,
   XfceShortcut *sc;
   const gchar  *shortcut;
   const gchar  *command;
+  const GValue *snotify;
+  gchar        *snotify_prop;
 
   g_return_val_if_fail (context != NULL, TRUE);
   g_return_val_if_fail (XFCE_IS_SHORTCUTS_PROVIDER (context->provider), TRUE);
@@ -468,9 +474,13 @@ _xfce_shortcuts_provider_get_shortcut (const gchar                  *property,
     return FALSE;
 
   shortcut = property + strlen (context->provider->priv->custom_base_property) + strlen ("/");
+
   command = g_value_get_string (value);
 
-  if (G_LIKELY (shortcut != NULL && command != NULL && g_utf8_strlen (shortcut, -1) > 0 && g_utf8_strlen (command, -1) > 0))
+  if (G_LIKELY (shortcut != NULL
+      && command != NULL
+      && g_utf8_strlen (shortcut, -1) > 0
+      && g_utf8_strlen (command, -1) > 0))
     {
       sc = g_slice_new0 (XfceShortcut);
 
@@ -478,6 +488,14 @@ _xfce_shortcuts_provider_get_shortcut (const gchar                  *property,
       sc->shortcut = g_strdup (shortcut);
       sc->command = g_strdup (command);
 
+      /* Lookup startup notify in the hash table */
+      snotify_prop = g_strconcat (property, "/startup-notify", NULL);
+      snotify = g_hash_table_lookup (context->properties, snotify_prop);
+      if (snotify != NULL)
+        sc->snotify = g_value_get_boolean (snotify);
+      else
+        sc->snotify = FALSE;
+
       context->list = g_list_append (context->list, sc);
     }
 
@@ -499,6 +517,7 @@ xfce_shortcuts_provider_get_shortcuts (XfceShortcutsProvider *provider)
 
   context.provider = provider;
   context.list = NULL;
+  context.properties = properties;
 
   if (G_LIKELY (properties != NULL))
     g_hash_table_foreach (properties, (GHFunc) _xfce_shortcuts_provider_get_shortcut, &context);
@@ -516,6 +535,8 @@ xfce_shortcuts_provider_get_shortcut (XfceShortcutsProvider *provider,
   gchar        *base_property;
   gchar        *property;
   gchar        *command;
+  gchar        *property2;
+  gboolean      snotify;
 
   g_return_val_if_fail (XFCE_IS_SHORTCUTS_PROVIDER (provider), NULL);
   g_return_val_if_fail (XFCONF_IS_CHANNEL (provider->priv->channel), NULL);
@@ -530,10 +551,14 @@ xfce_shortcuts_provider_get_shortcut (XfceShortcutsProvider *provider,
 
   if (G_LIKELY (command != NULL))
     {
+      property2 = g_strconcat (property, "/startup-notify", NULL);
+      snotify = xfconf_channel_get_bool (provider->priv->channel, property2, FALSE);
+
       sc = g_slice_new0 (XfceShortcut);
       sc->command = command;
       sc->property_name = g_strdup (property);
       sc->shortcut = g_strdup (shortcut);
+      sc->snotify = snotify;
     }
 
   g_free (property);
@@ -571,9 +596,11 @@ xfce_shortcuts_provider_has_shortcut (XfceShortcutsProvider *provider,
 void
 xfce_shortcuts_provider_set_shortcut (XfceShortcutsProvider *provider,
                                       const gchar           *shortcut,
-                                      const gchar           *command)
+                                      const gchar           *command,
+                                      gboolean               snotify)
 {
   gchar *property;
+  gchar *property2;
 
   g_return_if_fail (XFCE_IS_SHORTCUTS_PROVIDER (provider));
   g_return_if_fail (XFCONF_IS_CHANNEL (provider->priv->channel));
@@ -586,11 +613,16 @@ xfce_shortcuts_provider_set_shortcut (XfceShortcutsProvider *provider,
   property = g_strconcat (provider->priv->custom_base_property, "/", shortcut, NULL);
 
   if (xfconf_channel_has_property (provider->priv->channel, property))
-    xfconf_channel_reset_property (provider->priv->channel, property, FALSE);
+    xfconf_channel_reset_property (provider->priv->channel, property, TRUE);
+
+  property2 = g_strconcat (property, "/startup-notify", NULL);
+  xfconf_channel_set_bool (provider->priv->channel, property2, snotify);
+  g_free (property2);
 
   xfconf_channel_set_string (provider->priv->channel, property, command);
 
   g_free (property);
+
 }
 
 
diff --git a/libxfce4kbd-private/xfce-shortcuts-provider.h b/libxfce4kbd-private/xfce-shortcuts-provider.h
index 3de2c30..ed79539 100644
--- a/libxfce4kbd-private/xfce-shortcuts-provider.h
+++ b/libxfce4kbd-private/xfce-shortcuts-provider.h
@@ -54,7 +54,8 @@ gboolean                xfce_shortcuts_provider_has_shortcut      (XfceShortcuts
                                                                    const gchar           *shortcut);
 void                    xfce_shortcuts_provider_set_shortcut      (XfceShortcutsProvider *provider,
                                                                    const gchar           *shortcut,
-                                                                   const gchar           *command);
+                                                                   const gchar           *command,
+                                                                   gboolean               snotify);
 void                    xfce_shortcuts_provider_reset_shortcut    (XfceShortcutsProvider *provider,
                                                                    const gchar           *shortcut);
 
@@ -80,6 +81,7 @@ struct _XfceShortcut
   gchar *property_name;
   gchar *shortcut;
   gchar *command;
+  guint  snotify : 1;
 };
 
 G_END_DECLS



More information about the Xfce4-commits mailing list