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

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


Updating branch refs/heads/master
         to 5e95801c1b2209b5c95ed8b9d72120b7a31b30a9 (commit)
       from e124e7e741aa994fbd52eac9f02c6e0e27732844 (commit)

commit 5e95801c1b2209b5c95ed8b9d72120b7a31b30a9
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Nov 2 20:53:16 2010 +0100

    Add startup notification support for keyboard shortcuts.

 dialogs/keyboard-settings/command-dialog.c         |   51 ++++++++---------
 dialogs/keyboard-settings/command-dialog.h         |    4 +-
 dialogs/keyboard-settings/xfce-keyboard-settings.c |   59 ++++++++++++++-----
 xfce4-settings-helper/keyboard-shortcuts.c         |   31 ++++++++---
 4 files changed, 93 insertions(+), 52 deletions(-)

diff --git a/dialogs/keyboard-settings/command-dialog.c b/dialogs/keyboard-settings/command-dialog.c
index fae53e8..4e1c26d 100644
--- a/dialogs/keyboard-settings/command-dialog.c
+++ b/dialogs/keyboard-settings/command-dialog.c
@@ -32,11 +32,10 @@
 
 
 
-static void command_dialog_dispose         (GObject             *object);
-static void command_dialog_finalize        (GObject             *object);
 static void command_dialog_create_contents (CommandDialog      *dialog,
                                             const gchar        *shortcut,
-                                            const gchar        *action);
+                                            const gchar        *action,
+                                            gboolean            snotify);
 static void command_dialog_button_clicked  (CommandDialog      *dialog);
 
 
@@ -52,6 +51,7 @@ struct _CommandDialog
 
   GtkWidget *entry;
   GtkWidget *button;
+  GtkWidget *sn_option;
 };
 
 
@@ -63,11 +63,7 @@ G_DEFINE_TYPE (CommandDialog, command_dialog, XFCE_TYPE_TITLED_DIALOG)
 static void
 command_dialog_class_init (CommandDialogClass *klass)
 {
-  GObjectClass *gobject_class;
 
-  gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->dispose = command_dialog_dispose;
-  gobject_class->finalize = command_dialog_finalize;
 }
 
 
@@ -81,31 +77,16 @@ command_dialog_init (CommandDialog *dialog)
 
 
 
-static void
-command_dialog_dispose (GObject *object)
-{
-  (*G_OBJECT_CLASS (command_dialog_parent_class)->dispose) (object);
-}
-
-
-
-static void
-command_dialog_finalize (GObject *object)
-{
-  (*G_OBJECT_CLASS (command_dialog_parent_class)->finalize) (object);
-}
-
-
-
 GtkWidget*
 command_dialog_new (const gchar *shortcut,
-                    const gchar *action)
+                    const gchar *action,
+                    gboolean     snotify)
 {
   CommandDialog *dialog;
 
   dialog = COMMAND_DIALOG (g_object_new (TYPE_COMMAND_DIALOG, NULL));
 
-  command_dialog_create_contents (dialog, shortcut, action);
+  command_dialog_create_contents (dialog, shortcut, action, snotify);
 
   return GTK_WIDGET (dialog);
 }
@@ -115,7 +96,8 @@ command_dialog_new (const gchar *shortcut,
 static void
 command_dialog_create_contents (CommandDialog *dialog,
                                 const gchar   *shortcut,
-                                const gchar   *action)
+                                const gchar   *action,
+                                gboolean       snotify)
 {
   GtkWidget *button;
   GtkWidget *table;
@@ -140,7 +122,7 @@ command_dialog_create_contents (CommandDialog *dialog,
   gtk_widget_grab_default (button);
   gtk_widget_show (button);
 
-  table = gtk_table_new (2, 2, FALSE);
+  table = gtk_table_new (3, 2, FALSE);
   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
   gtk_table_set_col_spacings (GTK_TABLE (table), 12);
   gtk_container_set_border_width (GTK_CONTAINER (table), 6);
@@ -177,6 +159,11 @@ command_dialog_create_contents (CommandDialog *dialog,
   gtk_box_pack_start (GTK_BOX (hbox), dialog->button, FALSE, TRUE, 0);
   gtk_widget_show (dialog->button);
 
+  dialog->sn_option = gtk_check_button_new_with_mnemonic (_("Use _startup notification"));
+  gtk_table_attach (GTK_TABLE (table), dialog->sn_option, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->sn_option), snotify);
+  gtk_widget_show (dialog->sn_option);
+
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 }
 
@@ -191,6 +178,16 @@ command_dialog_get_command (CommandDialog *dialog)
 
 
 
+
+gboolean
+command_dialog_get_snotify (CommandDialog *dialog)
+{
+  g_return_val_if_fail (IS_COMMAND_DIALOG (dialog), FALSE);
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->sn_option));
+}
+
+
+
 gint
 command_dialog_run (CommandDialog *dialog,
                     GtkWidget     *parent)
diff --git a/dialogs/keyboard-settings/command-dialog.h b/dialogs/keyboard-settings/command-dialog.h
index 6887ae0..0f084da 100644
--- a/dialogs/keyboard-settings/command-dialog.h
+++ b/dialogs/keyboard-settings/command-dialog.h
@@ -39,8 +39,10 @@ typedef struct _CommandDialog      CommandDialog;
 GType       command_dialog_get_type     (void) G_GNUC_CONST;
 
 GtkWidget  *command_dialog_new          (const gchar   *shortcut,
-                                         const gchar   *action);
+                                         const gchar   *action,
+                                         gboolean       snotify);
 const char *command_dialog_get_command  (CommandDialog *dialog);
+gboolean    command_dialog_get_snotify  (CommandDialog *dialog);
 gint        command_dialog_run          (CommandDialog *dialog,
                                          GtkWidget     *parent);
 
diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c
index bc3c336..6689c6f 100644
--- a/dialogs/keyboard-settings/xfce-keyboard-settings.c
+++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c
@@ -48,9 +48,6 @@
 
 #define CUSTOM_BASE_PROPERTY         "/commands/custom"
 
-#define COMMAND_COLUMN  0
-#define SHORTCUT_COLUMN 1
-
 
 
 #define XFCE_KEYBOARD_SETTINGS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFCE_TYPE_KEYBOARD_SETTINGS, XfceKeyboardSettingsPrivate))
@@ -59,6 +56,14 @@
 
 enum
 {
+  COMMAND_COLUMN,
+  SHORTCUT_COLUMN,
+  SNOTIFY_COLUMN,
+  N_COLUMNS
+};
+
+enum
+{
     XKB_COMBO_DESCRIPTION = 0,
     XKB_COMBO_MODELS,
     XKB_COMBO_NUM_COLUMNS
@@ -282,7 +287,7 @@ xfce_keyboard_settings_constructed (GObject *object)
   g_signal_connect (kbd_shortcuts_view, "row-activated", G_CALLBACK (xfce_keyboard_settings_row_activated), settings);
 
   /* Create list store for keyboard shortcuts */
-  list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+  list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store), COMMAND_COLUMN, GTK_SORT_ASCENDING);
   gtk_tree_view_set_model (GTK_TREE_VIEW (kbd_shortcuts_view), GTK_TREE_MODEL (list_store));
 
@@ -483,13 +488,18 @@ _xfce_keyboard_settings_load_shortcut (XfceShortcut         *shortcut,
   g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
   g_return_if_fail (shortcut != NULL);
 
-  DBG ("property = %s, shortcut = %s, command = %s", shortcut->property_name, shortcut->shortcut, shortcut->command);
+  DBG ("property = %s, shortcut = %s, command = %s, snotify = %s",
+       shortcut->property_name, shortcut->shortcut,
+       shortcut->command, shortcut->snotify ? "true" : "false");
 
   tree_view = gtk_builder_get_object (GTK_BUILDER (settings), "kbd_shortcuts_view");
   tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
 
   gtk_list_store_append (GTK_LIST_STORE (tree_model), &iter);
-  gtk_list_store_set (GTK_LIST_STORE (tree_model), &iter, COMMAND_COLUMN, shortcut->command, SHORTCUT_COLUMN, shortcut->shortcut, -1);
+  gtk_list_store_set (GTK_LIST_STORE (tree_model), &iter,
+                      COMMAND_COLUMN, shortcut->command,
+                      SHORTCUT_COLUMN, shortcut->shortcut,
+                      SNOTIFY_COLUMN, shortcut->snotify, -1);
 }
 
 
@@ -525,6 +535,7 @@ xfce_keyboard_settings_edit_shortcut (XfceKeyboardSettings *settings,
   gchar        *shortcut;
   gchar        *command;
   gint          response;
+  gboolean      snotify;
 
   g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
@@ -536,9 +547,12 @@ xfce_keyboard_settings_edit_shortcut (XfceKeyboardSettings *settings,
   if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path)))
     {
       /* Read current shortcut from the activated row */
-      gtk_tree_model_get (model, &iter, COMMAND_COLUMN, &command, SHORTCUT_COLUMN, &shortcut, -1);
+      gtk_tree_model_get (model, &iter,
+                          COMMAND_COLUMN, &command,
+                          SHORTCUT_COLUMN, &shortcut,
+                          SNOTIFY_COLUMN, &snotify, -1);
 
-      DBG ("shortcut = %s, command = %s", shortcut, command);
+      DBG ("shortcut = %s, command = %s, snotify = %s", shortcut, command, snotify ? "true" : "false");
 
       /* Request a new shortcut from the user */
       dialog = xfce_shortcut_dialog_new ("commands", command, command);
@@ -554,7 +568,7 @@ xfce_keyboard_settings_edit_shortcut (XfceKeyboardSettings *settings,
           new_shortcut = xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (dialog));
 
           /* Save new shortcut to the settings */
-          xfce_shortcuts_provider_set_shortcut (settings->priv->provider, new_shortcut, command);
+          xfce_shortcuts_provider_set_shortcut (settings->priv->provider, new_shortcut, command, snotify);
         }
 
       /* Destroy the shortcut dialog */
@@ -580,6 +594,8 @@ xfce_keyboard_settings_edit_command (XfceKeyboardSettings *settings,
   gchar        *shortcut;
   gchar        *command;
   gint          response;
+  gboolean      snotify;
+  gboolean      new_snotify;
 
   g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
@@ -591,24 +607,30 @@ xfce_keyboard_settings_edit_command (XfceKeyboardSettings *settings,
   if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path)))
     {
       /* Read shortcut and current command from the activated row */
-      gtk_tree_model_get (model, &iter, COMMAND_COLUMN, &command, SHORTCUT_COLUMN, &shortcut, -1);
+      gtk_tree_model_get (model, &iter,
+                          COMMAND_COLUMN, &command,
+                          SHORTCUT_COLUMN, &shortcut,
+                          SNOTIFY_COLUMN, &snotify, -1);
 
       /* Request a new command from the user */
-      dialog = command_dialog_new (shortcut, command);
+      dialog = command_dialog_new (shortcut, command, snotify);
       response = command_dialog_run (COMMAND_DIALOG (dialog), GTK_WIDGET (tree_view));
 
       if (G_LIKELY (response == GTK_RESPONSE_OK))
         {
           /* Get the command entered by the user */
           new_command = command_dialog_get_command (COMMAND_DIALOG (dialog));
+          new_snotify = command_dialog_get_snotify (COMMAND_DIALOG (dialog));
 
-          if (g_strcmp0 (command, new_command) != 0)
+          if (g_strcmp0 (command, new_command) != 0
+              || snotify != new_snotify)
             {
               /* Remove the row because we add new one from the shortcut-added signal */
               gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
               /* Save settings */
-              xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, new_command);
+              xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut,
+                                                    new_command, new_snotify);
             }
         }
 
@@ -746,7 +768,10 @@ xfce_keyboard_settings_shortcut_added (XfceShortcutsProvider *provider,
   if (G_LIKELY (sc != NULL))
     {
       gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-      gtk_list_store_set (GTK_LIST_STORE (model), &iter, SHORTCUT_COLUMN, shortcut, COMMAND_COLUMN, sc->command, -1);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                          SHORTCUT_COLUMN, shortcut,
+                          COMMAND_COLUMN, sc->command,
+                          SNOTIFY_COLUMN, sc->snotify, -1);
 
       xfce_shortcut_free (sc);
     }
@@ -809,11 +834,12 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
   const gchar *command;
   gboolean     finished = FALSE;
   gint         response;
+  gboolean     snotify;
 
   g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
 
   /* Create command dialog */
-  command_dialog = command_dialog_new (NULL, NULL);
+  command_dialog = command_dialog_new (NULL, NULL, FALSE);
 
   /* Run command dialog until a vaild (non-empty) command is entered or the dialog is cancelled */
   do
@@ -833,6 +859,7 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
     {
       /* Get the command */
       command = command_dialog_get_command (COMMAND_DIALOG (command_dialog));
+      snotify = command_dialog_get_snotify (COMMAND_DIALOG (command_dialog));
 
       /* Hide the command dialog */
       gtk_widget_hide (command_dialog);
@@ -852,7 +879,7 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
           shortcut = xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (shortcut_dialog));
 
           /* Save the new shortcut to xfconf */
-          xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, command);
+          xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, command, snotify);
         }
 
       /* Destroy the shortcut dialog */
diff --git a/xfce4-settings-helper/keyboard-shortcuts.c b/xfce4-settings-helper/keyboard-shortcuts.c
index 0ae735e..aabd084 100644
--- a/xfce4-settings-helper/keyboard-shortcuts.c
+++ b/xfce4-settings-helper/keyboard-shortcuts.c
@@ -72,6 +72,7 @@ static void            xfce_keyboard_shortcuts_helper_shortcut_removed   (XfceSh
                                                                           XfceKeyboardShortcutsHelper      *helper);
 static void            xfce_keyboard_shortcuts_helper_shortcut_activated (XfceShortcutsGrabber             *grabber,
                                                                           const gchar                      *shortcut,
+                                                                          gint                              timestamp,
                                                                           XfceKeyboardShortcutsHelper      *helper);
 static void            xfce_keyboard_shortcuts_helper_load_shortcuts     (XfceKeyboardShortcutsHelper      *helper);
 
@@ -185,7 +186,7 @@ xfce_keyboard_shortcuts_helper_set_property (GObject      *object,
 
 
 
-static void 
+static void
 xfce_keyboard_shortcuts_helper_shortcut_added (XfceShortcutsProvider       *provider,
                                                const gchar                 *shortcut,
                                                XfceKeyboardShortcutsHelper *helper)
@@ -240,11 +241,13 @@ xfce_keyboard_shortcuts_helper_load_shortcuts (XfceKeyboardShortcutsHelper *help
 static void
 xfce_keyboard_shortcuts_helper_shortcut_activated (XfceShortcutsGrabber        *grabber,
                                                    const gchar                 *shortcut,
+                                                   gint                         timestamp,
                                                    XfceKeyboardShortcutsHelper *helper)
 {
-  XfceShortcut *sc;
-  GdkScreen    *screen;
-  GError       *error = NULL;
+  XfceShortcut  *sc;
+  GError        *error = NULL;
+  gchar        **argv;
+  gboolean       succeed;
 
   g_return_if_fail (XFCE_IS_KEYBOARD_SHORTCUTS_HELPER (helper));
   g_return_if_fail (XFCE_IS_SHORTCUTS_PROVIDER (helper->provider));
@@ -261,11 +264,23 @@ xfce_keyboard_shortcuts_helper_shortcut_activated (XfceShortcutsGrabber        *
   if (G_UNLIKELY (sc == NULL))
     return;
 
-  DBG ("command = %s", sc->command);
+  DBG ("command = %s, snotify = %s (time = %d)",
+       sc->command, sc->snotify ? "true" : "false", timestamp);
+
+  /* Handle the argv ourselfs, because xfce_spawn_command_line_on_screen() does
+   * not accept a custom timestamp for startup notification */
+  succeed = g_shell_parse_argv (sc->command, NULL, &argv, &error);
+  if (G_LIKELY (succeed))
+    {
+      succeed = xfce_spawn_on_screen_with_child_watch (xfce_gdk_screen_get_active (NULL),
+                                                       NULL, argv, NULL,
+                                                       G_SPAWN_SEARCH_PATH, sc->snotify,
+                                                       timestamp, NULL, NULL, &error);
+
+      g_strfreev (argv);
+    }
 
-  /* Spawn command on active screen */
-  screen = xfce_gdk_screen_get_active (NULL);
-  if (!xfce_spawn_command_line_on_screen (screen, sc->command, FALSE, FALSE, &error))
+  if (!succeed)
     {
       g_error ("Failed to spawn command \"%s\": %s", sc->command, error->message);
       g_error_free (error);



More information about the Xfce4-commits mailing list