Author: benny
Date: 2007-01-14 18:27:38 +0000 (Sun, 14 Jan 2007)
New Revision: 24451

Modified:
   thunar/trunk/ChangeLog
   thunar/trunk/thunar-vfs/thunar-vfs-exec.c
   thunar/trunk/thunar-vfs/thunar-vfs-exec.h
   thunar/trunk/thunar-vfs/thunar-vfs-info.c
   thunar/trunk/thunar-vfs/thunar-vfs-mime-handler.c
Log:
2007-01-14      Benedikt Meurer <[EMAIL PROTECTED]>

        * thunar-vfs/thunar-vfs-exec.c: Improve startup notification handling,
          based on a patch from Gregoire Gentil <[EMAIL PROTECTED]>.
        * thunar-vfs/thunar-vfs-exec.{c,h}, thunar-vfs/thunar-vfs-info.c,
          thunar-vfs/thunar-vfs-mime-handler.c: Allow to pass in icon_name
          of the application to start, which can be used by window managers
          that detailed support startup notification feedback.




Modified: thunar/trunk/ChangeLog
===================================================================
--- thunar/trunk/ChangeLog      2007-01-14 18:23:09 UTC (rev 24450)
+++ thunar/trunk/ChangeLog      2007-01-14 18:27:38 UTC (rev 24451)
@@ -1,5 +1,14 @@
 2007-01-14     Benedikt Meurer <[EMAIL PROTECTED]>
 
+       * thunar-vfs/thunar-vfs-exec.c: Improve startup notification handling,
+         based on a patch from Gregoire Gentil <[EMAIL PROTECTED]>.
+       * thunar-vfs/thunar-vfs-exec.{c,h}, thunar-vfs/thunar-vfs-info.c,
+         thunar-vfs/thunar-vfs-mime-handler.c: Allow to pass in icon_name
+         of the application to start, which can be used by window managers
+         that detailed support startup notification feedback.
+
+2007-01-14     Benedikt Meurer <[EMAIL PROTECTED]>
+
        * thunar-vfs/thunar-vfs-io-local.c(_thunar_vfs_io_local_listdir):
          Use g_list_free_1() instead of g_list_free1().
 

Modified: thunar/trunk/thunar-vfs/thunar-vfs-exec.c
===================================================================
--- thunar/trunk/thunar-vfs/thunar-vfs-exec.c   2007-01-14 18:23:09 UTC (rev 
24450)
+++ thunar/trunk/thunar-vfs/thunar-vfs-exec.c   2007-01-14 18:27:38 UTC (rev 
24451)
@@ -41,6 +41,7 @@
 
 #include <thunar-vfs/thunar-vfs-exec.h>
 #include <thunar-vfs/thunar-vfs-path-private.h>
+#include <thunar-vfs/thunar-vfs-private.h>
 #include <thunar-vfs/thunar-vfs-alias.h>
 
 #ifdef GDK_WINDOWING_X11
@@ -273,28 +274,37 @@
 /* the max. timeout for an application to startup */
 #define TVSN_STARTUP_TIMEOUT (30 * 1000)
 
+typedef struct
+{
+  SnLauncherContext *sn_launcher;
+  guint              timeout_id;
+  guint              watch_id;
+  GPid               pid;
+} TvsnStartupData;
+
 static gboolean
 tvsn_startup_timeout (gpointer data)
 {
-  SnLauncherContext *sn_launcher = data;
-  GTimeVal           now;
-  gdouble            elapsed;
-  glong              tv_sec;
-  glong              tv_usec;
+  TvsnStartupData *startup_data = data;
+  GTimeVal         now;
+  gdouble          elapsed;
+  glong            tv_sec;
+  glong            tv_usec;
 
   GDK_THREADS_ENTER ();
 
   /* determine the amount of elapsed time */
   g_get_current_time (&now);
-  sn_launcher_context_get_last_active_time (sn_launcher, &tv_sec, &tv_usec);
+  sn_launcher_context_get_last_active_time (startup_data->sn_launcher, 
&tv_sec, &tv_usec);
   elapsed = (((gdouble) now.tv_sec - tv_sec) * G_USEC_PER_SEC + (now.tv_usec - 
tv_usec)) / 1000.0;
 
   /* check if the timeout was reached */
   if (elapsed >= TVSN_STARTUP_TIMEOUT)
     {
       /* abort the startup notification */
-      sn_launcher_context_complete (sn_launcher);
-      sn_launcher_context_unref (sn_launcher);
+      sn_launcher_context_complete (startup_data->sn_launcher);
+      sn_launcher_context_unref (startup_data->sn_launcher);
+      startup_data->sn_launcher = NULL;
     }
 
   GDK_THREADS_LEAVE ();
@@ -303,6 +313,44 @@
   return (elapsed < TVSN_STARTUP_TIMEOUT);
 }
 
+static void
+tvsn_startup_timeout_destroy (gpointer data)
+{
+  TvsnStartupData *startup_data = data;
+
+  _thunar_vfs_return_if_fail (startup_data->sn_launcher == NULL);
+
+  /* cancel the watch (if any) */
+  if (startup_data->watch_id != 0)
+    g_source_remove (startup_data->watch_id);
+
+  /* close the PID */
+  g_spawn_close_pid (startup_data->pid);
+
+  /* release the startup data */
+  _thunar_vfs_slice_free (TvsnStartupData, startup_data);
+}
+
+static void
+tvsn_startup_watch (GPid     pid,
+                    gint     status,
+                    gpointer data)
+{
+  TvsnStartupData *startup_data = data;
+
+  _thunar_vfs_return_if_fail (startup_data->sn_launcher != NULL);
+  _thunar_vfs_return_if_fail (startup_data->watch_id != 0);
+  _thunar_vfs_return_if_fail (startup_data->pid == pid);
+
+  /* abort the startup notification (application exited) */
+  sn_launcher_context_complete (startup_data->sn_launcher);
+  sn_launcher_context_unref (startup_data->sn_launcher);
+  startup_data->sn_launcher = NULL;
+
+  /* cancel the startup notification timeout */
+  g_source_remove (startup_data->timeout_id);
+}
+
 static gint
 tvsn_get_active_workspace_number (GdkScreen *screen)
 {
@@ -365,6 +413,7 @@
  * @envp              : child's environment vector or %NULL to inherit 
parent's.
  * @flags             : flags from #GSpawnFlags.
  * @startup_notify    : whether to use startup notification.
+ * @icon_name         : application icon or %NULL.
  * @error             : return location for errors or %NULL.
  *
  * Like gdk_spawn_on_screen(), but also supports startup notification
@@ -379,17 +428,20 @@
                            gchar      **envp,
                            GSpawnFlags  flags,
                            gboolean     startup_notify,
+                           const gchar *icon_name,
                            GError     **error)
 {
 #ifdef HAVE_LIBSTARTUP_NOTIFICATION
   SnLauncherContext *sn_launcher = NULL;
-  extern char      **environ;
+  TvsnStartupData   *startup_data;
+  extern gchar     **environ;
   SnDisplay         *sn_display = NULL;
   gint               sn_workspace;
   gint               n, m;
 #endif
   gboolean           succeed;
   gchar            **sn_envp = envp;
+  GPid               pid;
 
 #ifdef HAVE_LIBSTARTUP_NOTIFICATION
   /* initialize the sn launcher context */
@@ -409,6 +461,7 @@
               sn_workspace = tvsn_get_active_workspace_number (screen);
               sn_launcher_context_set_binary_name (sn_launcher, argv[0]);
               sn_launcher_context_set_workspace (sn_launcher, sn_workspace);
+              sn_launcher_context_set_icon_name (sn_launcher, (icon_name != 
NULL) ? icon_name : "applications-other");
               sn_launcher_context_initiate (sn_launcher, g_get_prgname (), 
argv[0], CurrentTime);
 
               /* setup the child environment */
@@ -422,13 +475,16 @@
                   sn_envp[m++] = g_strdup (envp[n]);
               sn_envp[m++] = g_strconcat ("DESKTOP_STARTUP_ID=", 
sn_launcher_context_get_startup_id (sn_launcher), NULL);
               sn_envp[m] = NULL;
+
+              /* we want to watch the child process */
+              flags |= G_SPAWN_DO_NOT_REAP_CHILD;
             }
         }
     }
 #endif
 
   /* try to spawn the new process */
-  succeed = gdk_spawn_on_screen (screen, working_directory, argv, sn_envp, 
flags, NULL, NULL, NULL, error);
+  succeed = gdk_spawn_on_screen (screen, working_directory, argv, sn_envp, 
flags, NULL, NULL, &pid, error);
 
 #ifdef HAVE_LIBSTARTUP_NOTIFICATION
   /* handle the sn launcher context */
@@ -443,7 +499,12 @@
       else
         {
           /* schedule a startup notification timeout */
-          g_timeout_add (TVSN_STARTUP_TIMEOUT, tvsn_startup_timeout, 
sn_launcher);
+          startup_data = _thunar_vfs_slice_new (TvsnStartupData);
+          startup_data->sn_launcher = sn_launcher;
+          startup_data->timeout_id = g_timeout_add_full (G_PRIORITY_LOW, 
TVSN_STARTUP_TIMEOUT, tvsn_startup_timeout,
+                                                         startup_data, 
tvsn_startup_timeout_destroy);
+          startup_data->watch_id = g_child_watch_add_full (G_PRIORITY_LOW, 
pid, tvsn_startup_watch, startup_data, NULL);
+          startup_data->pid = pid;
         }
     }
 

Modified: thunar/trunk/thunar-vfs/thunar-vfs-exec.h
===================================================================
--- thunar/trunk/thunar-vfs/thunar-vfs-exec.h   2007-01-14 18:23:09 UTC (rev 
24450)
+++ thunar/trunk/thunar-vfs/thunar-vfs-exec.h   2007-01-14 18:27:38 UTC (rev 
24451)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2005 Benedikt Meurer <[EMAIL PROTECTED]>
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -41,6 +41,7 @@
                                     gchar         **envp,
                                     GSpawnFlags     flags,
                                     gboolean        startup_notify,
+                                    const gchar    *icon_name,
                                     GError        **error) G_GNUC_INTERNAL;
 
 gboolean thunar_vfs_exec_sync      (const gchar    *command_line,

Modified: thunar/trunk/thunar-vfs/thunar-vfs-info.c
===================================================================
--- thunar/trunk/thunar-vfs/thunar-vfs-info.c   2007-01-14 18:23:09 UTC (rev 
24450)
+++ thunar/trunk/thunar-vfs/thunar-vfs-info.c   2007-01-14 18:27:38 UTC (rev 
24451)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2005-2006 Benedikt Meurer <[EMAIL PROTECTED]>
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -332,7 +332,7 @@
                          GError             **error)
 {
   ThunarVfsPath *parent;
-  const gchar   *icon;
+  const gchar   *icon = NULL;
   const gchar   *name;
   const gchar   *type;
   const gchar   *url;
@@ -453,7 +453,7 @@
         }
 
       /* execute the command */
-      result = thunar_vfs_exec_on_screen (screen, directory, argv, NULL, 
G_SPAWN_SEARCH_PATH, startup_notify, error);
+      result = thunar_vfs_exec_on_screen (screen, directory, argv, NULL, 
G_SPAWN_SEARCH_PATH, startup_notify, icon, error);
 
       /* release the working directory */
       g_free (directory);

Modified: thunar/trunk/thunar-vfs/thunar-vfs-mime-handler.c
===================================================================
--- thunar/trunk/thunar-vfs/thunar-vfs-mime-handler.c   2007-01-14 18:23:09 UTC 
(rev 24450)
+++ thunar/trunk/thunar-vfs/thunar-vfs-mime-handler.c   2007-01-14 18:27:38 UTC 
(rev 24451)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2005-2006 Benedikt Meurer <[EMAIL PROTECTED]>
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -286,7 +286,8 @@
 
   /* try to spawn the application */
   result = thunar_vfs_exec_on_screen (screen, working_directory, argv, envp, 
G_SPAWN_SEARCH_PATH,
-                                      mime_handler->flags & 
THUNAR_VFS_MIME_HANDLER_SUPPORTS_STARTUP_NOTIFY, error);
+                                      mime_handler->flags & 
THUNAR_VFS_MIME_HANDLER_SUPPORTS_STARTUP_NOTIFY,
+                                      mime_handler->icon, error);
 
   /* cleanup */
   g_free (working_directory);

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to