[Xfce4-commits] r25719 - xfce4-panel/branches/xfce_4_4/libxfce4panel

Jasper Huijsmans jasper at xfce.org
Thu May 17 10:58:02 CEST 2007


Author: jasper
Date: 2007-05-17 08:58:02 +0000 (Thu, 17 May 2007)
New Revision: 25719

Modified:
   xfce4-panel/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin-iface.h
   xfce4-panel/branches/xfce_4_4/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/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin-iface.h
===================================================================
--- xfce4-panel/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin-iface.h	2007-05-17 08:57:00 UTC (rev 25718)
+++ xfce4-panel/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin-iface.h	2007-05-17 08:58:02 UTC (rev 25719)
@@ -52,17 +52,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 that the plugin should be run on.
+ * @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.
  *
- * Returns: %TRUE if the plugin can be started, %FALSE other wise.
+ * Returns: %TRUE if the plugin can be started, %FALSE otherwise.
  *
- * See also: XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK() and
- *           XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK()
+ * 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/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin.h
===================================================================
--- xfce4-panel/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin.h	2007-05-17 08:57:00 UTC (rev 25718)
+++ xfce4-panel/branches/xfce_4_4/libxfce4panel/xfce-panel-plugin.h	2007-05-17 08:58:02 UTC (rev 25719)
@@ -33,57 +33,89 @@
  * XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL
  * @construct : name of a function that can be cast to an #XfcePanelPluginFunc
  *
- * Registers and initializes the plugin. This is the only thing that is 
+ * Registers and initializes the plugin. This is the only thing that is
  * required to create a panel plugin.
  *
  * See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
  **/
-#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(construct) \
-    int \
-    main (int argc, char **argv) \
-    { \
-        GtkWidget *plugin; \
-        gtk_init (&argc, &argv); \
-        plugin = xfce_external_panel_plugin_new (argc, argv, \
-                     (XfcePanelPluginFunc)construct); \
-        if (!plugin) return 1; \
-        g_signal_connect_after (plugin, "destroy", \
-                                G_CALLBACK (exit), 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
- * @construct : name of a function that can be cast to an 
+ * @construct : name of a function that can be cast to an
  *              #XfcePanelPluginFunc
  * @check     : name of a function that can be cast to an
  *              #XfcePanelPluginCheck
  *
- * Registers and initializes the plugin. This is the only thing that is 
+ * Registers and initializes the plugin. This is the only thing that is
  * required to create a panel plugin. The @check functions is run before
  * creating the plugin, and should return FALSE if plugin creation is not
  * possible.
  *
  * See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
  **/
-#define XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK(construct,check) \
-    int \
-    main (int argc, char **argv) \
-    { \
-        GtkWidget *plugin; \
-        XfcePanelPluginCheck test = (XfcePanelPluginCheck)check; \
-        gtk_init (&argc, &argv); \
-        if (!test(gdk_screen_get_default())) return 2; \
-        plugin = xfce_external_panel_plugin_new (argc, argv, \
-                     (XfcePanelPluginFunc)construct); \
-        if (!plugin) return 1; \
-        g_signal_connect_after (plugin, "destroy", \
-                                G_CALLBACK (exit), 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;                                                  		\
     }
 
 /**



More information about the Xfce4-commits mailing list