[Xfce4-commits] <xfce4-panel:devel> Properly spawn preferred apps with startup notify.

Nick Schermer noreply at xfce.org
Sun Feb 14 21:36:01 CET 2010


Updating branch refs/heads/devel
         to 51a19c5e799276cd6497bc9c59515ec53ac31c65 (commit)
       from cea9874cd4faf7a44b6f06e125ac521ef41191ce (commit)

commit 51a19c5e799276cd6497bc9c59515ec53ac31c65
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Feb 14 21:30:55 2010 +0100

    Properly spawn preferred apps with startup notify.
    
    Without startup notify focus stealing is broken, so work
    around that with this code that extacts the binary names
    from the exo helper desktop files and tries to spawn it.

 plugins/directorymenu/directorymenu.c |   78 ++++++++++++++++++++++++++++++---
 1 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/plugins/directorymenu/directorymenu.c b/plugins/directorymenu/directorymenu.c
index a22b8a5..f1c3d3e 100644
--- a/plugins/directorymenu/directorymenu.c
+++ b/plugins/directorymenu/directorymenu.c
@@ -23,6 +23,7 @@
 #include <gio/gio.h>
 #include <exo/exo.h>
 #include <libxfce4ui/libxfce4ui.h>
+#include <libxfce4util/libxfce4util.h>
 #include <libxfce4panel/libxfce4panel.h>
 #include <common/panel-xfconf.h>
 #include <common/panel-builder.h>
@@ -604,19 +605,82 @@ directory_menu_plugin_menu_open (GtkWidget   *mi,
                                  GFile       *dir,
                                  const gchar *category)
 {
-  GError *error = NULL;
-  gchar  *path;
+  GError       *error = NULL;
+  gchar        *working_dir;
+  XfceRc       *rc, *helperrc;
+  const gchar  *value;
+  gchar        *filename;
+  gchar       **binaries = NULL;
+  guint         i;
+  gboolean      result = FALSE;
+  gchar        *argv[2];
+
+  /* try to work around the exo code and get the direct command */
+  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/helpers.rc", TRUE);
+  if (G_LIKELY (rc != NULL))
+    {
+      value = xfce_rc_read_entry_untranslated (rc, category, NULL);
+      if (G_LIKELY (value != NULL))
+        {
+          filename = g_strconcat ("xfce4/helpers/", value, ".desktop", NULL);
+          helperrc = xfce_rc_config_open (XFCE_RESOURCE_DATA, filename, TRUE);
+          g_free (filename);
+
+          if (G_LIKELY (helperrc != NULL))
+            {
+              /* only try our custom stuff if startup notify is supported */
+              if (xfce_rc_read_bool_entry (helperrc, "StartupNotify", FALSE))
+                {
+                  value = xfce_rc_read_entry_untranslated (helperrc, "X-XFCE-Binaries", NULL);
+                  if (value != NULL)
+                    binaries = g_strsplit (value, ";", -1);
+                }
 
-  path = g_file_get_path (dir);
-  if (!exo_execute_preferred_application_on_screen (category, NULL, path, NULL,
-                                                    gtk_widget_get_screen (mi),
-                                                    &error))
+              xfce_rc_close (helperrc);
+            }
+        }
+
+      xfce_rc_close (rc);
+    }
+
+  working_dir = g_file_get_path (dir);
+
+  /* if there are binaries, there is a helper that
+   * supports startup notification, try to spawn one */
+  if (binaries != NULL)
+    {
+      for (i = 0; binaries[i] != NULL; i++)
+        {
+          filename = g_find_program_in_path (binaries[i]);
+          if (filename == NULL)
+            continue;
+
+          argv[0] = filename;
+          argv[1] = NULL;
+
+          /* try to spawn the program, if this fails we try exo for
+           * a decent error message */
+          result = xfce_spawn_on_screen (gtk_widget_get_screen (mi),
+                                         working_dir, argv, NULL, 0, TRUE,
+                                         gtk_get_current_event_time (),
+                                         NULL, NULL);
+          g_free (filename);
+          break;
+        }
+
+      g_strfreev (binaries);
+    }
+
+  if (!result
+      && !exo_execute_preferred_application_on_screen (category, NULL, working_dir, NULL,
+                                                       gtk_widget_get_screen (mi), &error))
     {
       xfce_dialog_show_error (NULL, error,
           _("Failed to open preferred application category \"%s\""), category);
       g_error_free (error);
     }
-  g_free (path);
+
+  g_free (working_dir);
 }
 
 



More information about the Xfce4-commits mailing list