Author: jasper
Date: 2007-05-17 08:57:00 +0000 (Thu, 17 May 2007)
New Revision: 25718

Modified:
   xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h
   xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin.h
Log:
Add _EXTERNAL_FULL variant of plugin registration macros, to allow external 
plugins to call g_thread_init() before gtk_init() is run. Could be useful for 
other things as well. Should allow Brian to fix bug #3141.

Modified: xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h
===================================================================
--- xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h   2007-05-15 
22:44:59 UTC (rev 25717)
+++ xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin-iface.h   2007-05-17 
08:57:00 UTC (rev 25718)
@@ -49,14 +49,36 @@
 typedef void (*XfcePanelPluginFunc) (XfcePanelPlugin *plugin);
 
 /**
+ * XfcePanelPluginPreInit:
+ * @argc : number of arguments to the plugin
+ * @argv : argument array
+ *
+ * Callback function that is run in an external plugin before gtk_init(). It 
+ * should return %FALSE if the plugin is not available for whatever reason. 
+ * The function can be given as argument to one of the registration macros.
+ *
+ * The main purpose of this callback is to allow multithreaded plugins to call
+ * g_thread_init().
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ *
+ * See also: XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL()
+ **/
+typedef gboolean (*XfcePanelPluginPreInit) (int argc, char **argv);
+
+/**
  * XfcePanelPluginCheck:
+ * @screen : the #GdkScreen the panel is running on
  *
  * Callback function that is run before creating a plugin. It should return
- * if the plugin is not available for whatever reason. It should be given as
- * the argument to the registration macros.
+ * %FALSE if the plugin is not available for whatever reason. The function 
+ * can be given as argument to one of the registration macros.
  *
- * See also: XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK() and
- *           XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK()
+ * Returns: %TRUE if the plugin can be started, %FALSE otherwise.
+ *
+ * See also: XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK(),
+ *           XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK() and
+ *           XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL()
  **/
 typedef gboolean (*XfcePanelPluginCheck) (GdkScreen *screen);
 

Modified: xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin.h
===================================================================
--- xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin.h 2007-05-15 22:44:59 UTC 
(rev 25717)
+++ xfce4-panel/trunk/libxfce4panel/xfce-panel-plugin.h 2007-05-17 08:57:00 UTC 
(rev 25718)
@@ -39,27 +39,8 @@
  *
  * See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
  **/
-#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(construct)             \
-    gint                                                           \
-    main (gint argc, gchar **argv)                                 \
-    {                                                              \
-        GtkWidget *plugin;                                         \
-                                                                   \
-        gtk_init (&argc, &argv);                                   \
-                                                                   \
-        plugin = xfce_external_panel_plugin_new (argc, argv,       \
-                     (XfcePanelPluginFunc)construct);              \
-                                                                   \
-        if (G_UNLIKELY (plugin == NULL))                           \
-            return 1;                                              \
-                                                                   \
-        g_signal_connect_after (G_OBJECT (plugin), "destroy",      \
-                                G_CALLBACK (gtk_main_quit), NULL); \
-        gtk_widget_show (plugin);                                  \
-                                                                   \
-        gtk_main ();                                               \
-        return 0;                                                  \
-    }
+#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(construct) \
+               XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL(construct,NULL,NULL)
 
 /**
  * XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK
@@ -75,30 +56,67 @@
  *
  * See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
  **/
-#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK(construct,check) \
-    gint                                                                \
-    main (gint argc, gchar **argv)                                      \
-    {                                                                   \
-        GtkWidget            *plugin;                                   \
-        XfcePanelPluginCheck  test = (XfcePanelPluginCheck)check;       \
-                                                                        \
-        gtk_init (&argc, &argv);                                        \
-                                                                        \
-        if (G_UNLIKELY (test(gdk_screen_get_default()) == FALSE))       \
-            return 2;                                                   \
-                                                                        \
-        plugin = xfce_external_panel_plugin_new (argc, argv,            \
-                     (XfcePanelPluginFunc)construct);                   \
-                                                                        \
-        if (G_UNLIKELY (plugin == NULL))                                \
-            return 1;                                                   \
-                                                                        \
-        g_signal_connect_after (G_OBJECT (plugin), "destroy",           \
-                                G_CALLBACK (gtk_main_quit), NULL);      \
-        gtk_widget_show (plugin);                                       \
-                                                                        \
-        gtk_main ();                                                    \
-        return 0;                                                       \
+#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK(construct,check)        
\
+               XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL(construct,NULL,check)
+
+/**
+ * XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL
+ * @construct : name of a function that can be cast to #XfcePanelPluginFunc
+ * @init      : name of a function that can be case to #XfcePanelPluginPreInit
+ *             or NULL
+ * @check     : name of a function that can be cast to #XfcePanelPluginCheck
+ *             or NULL
+ *
+ * Registers and initializes the plugin. This is the only thing that is
+ * required to create a panel plugin.
+ *
+ * The @init argument should be a function that takes two parameters:
+ *
+ *   gboolean init( int argc, char **argv );
+ *
+ * The @check functions is run aftern gtk_init() and before creating the 
+ * plugin; it takes one argument and should return FALSE if plugin creation 
+ * is not possible:
+ *
+ *   gboolean check( GdkScreen *screen );
+ *
+ * See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
+ **/
+#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL(construct,init,check)         
\
+    gint                                                                       
\
+    main (gint argc, gchar **argv)                                             
\
+    {                                                                          
\
+        GtkWidget              *plugin;                                        
 \
+       XfcePanelPluginFunc     create  = (XfcePanelPluginFunc)construct        
\
+        XfcePanelPluginPreInit  preinit = (XfcePanelPluginPreInit)init;        
        \
+        XfcePanelPluginCheck    test    = (XfcePanelPluginCheck)check;         
\
+                                                                               
\
+       if ( init )                                                             
\
+       {                                                                       
\
+           if (G_UNLIKELY (init(argc,argv) == FALSE))                          
\
+               return 3;                                                       
\
+       }                                                                       
\
+                                                                               
\
+        gtk_init (&argc, &argv);                                               
\
+                                                                               
\
+       if ( test )                                                             
\
+       {                                                                       
\
+           if (G_UNLIKELY (test(gdk_screen_get_default()) == FALSE))           
\
+               return 2;                                                       
\
+       }                                                                       
\
+                                                                               
\
+        plugin = xfce_external_panel_plugin_new (argc, argv, create);          
\
+                                                                               
\
+        if (G_UNLIKELY (plugin == NULL))                                       
\
+            return 1;                                                          
\
+                                                                               
\
+        g_signal_connect_after (G_OBJECT (plugin), "destroy",                  
\
+                                G_CALLBACK (gtk_main_quit), NULL);             
\
+                                                                               
\
+        gtk_widget_show (plugin);                                              
\
+        gtk_main ();                                                           
\
+                                                                               
\
+        return 0;                                                              
\
     }
 
 /**

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

Reply via email to