Browse Source

Also use a fixed argv layout for 4.6 plugins.

Move the enums used for this in the provider header.
upstream/xfce4-panel-4.10.1
Nick Schermer 12 years ago
parent
commit
083d0b9e4f
  1. 12
      common/panel-dbus.h
  2. 6
      common/panel-private.h
  3. 78
      libxfce4panel/libxfce4panel-deprecated.h
  4. 26
      libxfce4panel/xfce-panel-plugin-provider.h
  5. 88
      panel/panel-plugin-external-46.c
  6. 37
      panel/panel-plugin-external.c
  7. 26
      wrapper/main.c

12
common/panel-dbus.h

@ -55,16 +55,4 @@ enum
DBUS_SET_REPLY_ID
};
enum
{
ARGV_0,
ARGV_FILENAME,
ARGV_UNIQUE_ID,
ARGV_SOCKET_ID,
ARGV_NAME,
ARGV_DISPLAY_NAME,
ARGV_COMMENT,
ARGV_ARGUMENTS
};
#endif /* !__PANEL_DBUS_H__ */

6
common/panel-private.h

@ -81,10 +81,4 @@
gdk_color->green / 65535.00, \
gdk_color->blue / 65535.00
/* wrapper exit values */
#define WRAPPER_EXIT_SUCCESS (0)
#define WRAPPER_EXIT_FAILURE (1)
#define WRAPPER_EXIT_PREINIT (2)
#define WRAPPER_EXIT_NO_PROVIDER (3)
#endif /* !__PANEL_PRIVATE_H__ */

78
libxfce4panel/libxfce4panel-deprecated.h

@ -26,6 +26,7 @@
/* #ifndef XFCE_DISABLE_DEPRECATED */
#include <libxfce4panel/xfce-panel-plugin-provider.h>
#include <gdk/gdkx.h>
#include <stdlib.h>
/* #endif *//* !XFCE_DISABLE_DEPRECATED */
G_BEGIN_DECLS
@ -274,56 +275,47 @@ enum /*< skip >*/
gint \
main (gint argc, gchar **argv) \
{ \
GtkWidget *plug; \
GdkScreen *screen; \
GtkWidget *xpp; \
GError *error = NULL; \
gchar *opt_name = NULL; \
gchar *opt_display_name = NULL; \
gint opt_unique_id = -1; \
gchar *opt_comment = NULL; \
gint opt_socket_id = 0; \
gchar **opt_arguments = NULL; \
GOptionEntry option_entries[] = \
{ \
{ "name", 'n', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_name, NULL, NULL }, \
{ "display-name", 'd', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_display_name, NULL, NULL }, \
{ "comment", 'c', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_comment, NULL, NULL }, \
{ "unique-id", 'i', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &opt_unique_id, NULL, NULL }, \
{ "socket-id", 's', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &opt_socket_id, NULL, NULL }, \
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &opt_arguments, NULL, NULL }, \
{ NULL } \
}; \
\
_xpp_atom = gdk_atom_intern_static_string (PANEL_CLIENT_EVENT_ATOM); \
\
if (preinit_func != NULL) \
GtkWidget *plug; \
GdkScreen *screen; \
GtkWidget *xpp; \
const gchar *name; \
const gchar *display_name; \
gint unique_id; \
const gchar *comment; \
GdkNativeWindow socket_id; \
gchar **arguments; \
\
if (G_UNLIKELY (argc < PLUGIN_ARGV_ARGUMENTS)) \
{ \
if (!((XfcePanelPluginPreInit) preinit_func) (argc, argv)) \
return 2; /* WRAPPER_EXIT_PREINIT */ \
g_critical ("Not enough arguments are passed to the plugin"); \
return PLUGIN_EXIT_FAILURE; \
} \
\
if (!gtk_init_with_args (&argc, &argv, "", option_entries, NULL, &error)) \
if (G_UNLIKELY (preinit_func != NULL)) \
{ \
g_critical ("Failed to initialize"); \
return 1 /* WRAPPER_EXIT_FAILURE */; \
if (!((XfcePanelPluginPreInit) preinit_func) (argc, argv)) \
return PLUGIN_EXIT_PREINIT_FAILED; \
} \
\
if (opt_unique_id == -1 || opt_name == NULL || opt_display_name == NULL \
|| opt_comment == NULL || opt_socket_id == 0) \
{ \
g_critical ("Missing argument(s)"); \
return 1 /* WRAPPER_EXIT_FAILURE */; \
} \
unique_id = strtol (argv[PLUGIN_ARGV_UNIQUE_ID], NULL, 0); \
socket_id = strtol (argv[PLUGIN_ARGV_SOCKET_ID], NULL, 0); \
name = argv[PLUGIN_ARGV_NAME]; \
display_name = argv[PLUGIN_ARGV_DISPLAY_NAME]; \
comment = argv[PLUGIN_ARGV_COMMENT]; \
arguments = argv + PLUGIN_ARGV_ARGUMENTS; \
\
gtk_init (&argc, &argv); \
\
if (check_func != NULL) \
{ \
screen = gdk_screen_get_default (); \
if (!((XfcePanelPluginCheck) check_func) (screen)) \
return 3; /* WRAPPER_EXIT_NO_PROVIDER */ \
return PLUGIN_EXIT_CHECK_FAILED; \
} \
\
plug = gtk_plug_new (opt_socket_id); \
_xpp_atom = gdk_atom_intern_static_string (PANEL_CLIENT_EVENT_ATOM); \
\
plug = gtk_plug_new (socket_id); \
g_signal_connect (G_OBJECT (plug), "embedded", \
G_CALLBACK (_xpp_plug_embedded), NULL); \
g_signal_connect (G_OBJECT (plug), "expose-event", \
@ -336,11 +328,11 @@ enum /*< skip >*/
_xpp_set_colormap (plug); \
\
xpp = g_object_new (XFCE_TYPE_PANEL_PLUGIN, \
"name", opt_name, \
"unique-id", opt_unique_id, \
"display-name", opt_display_name, \
"comment", opt_comment, \
"arguments", opt_arguments, NULL); \
"name", name, \
"unique-id", unique_id, \
"display-name", display_name, \
"comment", comment, \
"arguments", arguments, NULL); \
gtk_container_add (GTK_CONTAINER (plug), xpp); \
g_signal_connect_after (G_OBJECT (xpp), "realize", \
G_CALLBACK (_xpp_realize), NULL); \
@ -359,7 +351,7 @@ enum /*< skip >*/
if (GTK_IS_WIDGET (plug)) \
gtk_widget_destroy (plug); \
\
return 0 /* WRAPPER_EXIT_SUCCESS */; \
return PLUGIN_EXIT_SUCCESS; \
}
/* #endif *//* !XFCE_DISABLE_DEPRECATED */

26
libxfce4panel/xfce-panel-plugin-provider.h

@ -67,8 +67,7 @@ struct _XfcePanelPluginProviderIface
const GValue *value);
};
/* signals send from the plugin to the panel (possibly
* through the wrapper) */
/* signals send from the plugin to the panel (possibly through the wrapper) */
typedef enum /*< skip >*/
{
PROVIDER_SIGNAL_MOVE_PLUGIN = 0,
@ -90,6 +89,29 @@ typedef enum /*< skip >*/
}
XfcePanelPluginProviderSignal;
/* plugin exit values */
enum
{
PLUGIN_EXIT_SUCCESS = 0,
PLUGIN_EXIT_FAILURE,
PLUGIN_EXIT_PREINIT_FAILED,
PLUGIN_EXIT_CHECK_FAILED,
PLUGIN_EXIT_NO_PROVIDER
};
/* argument handling in plugin and wrapper */
enum
{
PLUGIN_ARGV_0 = 0,
PLUGIN_ARGV_FILENAME,
PLUGIN_ARGV_UNIQUE_ID,
PLUGIN_ARGV_SOCKET_ID,
PLUGIN_ARGV_NAME,
PLUGIN_ARGV_DISPLAY_NAME,
PLUGIN_ARGV_COMMENT,
PLUGIN_ARGV_ARGUMENTS
};
GType xfce_panel_plugin_provider_get_type (void) G_GNUC_CONST;

88
panel/panel-plugin-external-46.c

@ -105,6 +105,9 @@ struct _PanelPluginExternal46
/* plugin information */
gint unique_id;
/* startup arguments */
gchar **arguments;
/* the module */
PanelModule *module;
@ -130,7 +133,8 @@ enum
{
PROP_0,
PROP_MODULE,
PROP_UNIQUE_ID
PROP_UNIQUE_ID,
PROP_ARGUMENTS
};
typedef struct
@ -187,6 +191,14 @@ panel_plugin_external_46_class_init (PanelPluginExternal46Class *klass)
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class,
PROP_ARGUMENTS,
g_param_spec_boxed ("arguments", NULL, NULL,
G_TYPE_STRV,
G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY));
panel_atom = gdk_atom_intern_static_string (PANEL_CLIENT_EVENT_ATOM);
}
@ -199,6 +211,7 @@ panel_plugin_external_46_init (PanelPluginExternal46 *external)
external->unique_id = -1;
external->module = NULL;
external->queue = NULL;
external->arguments = NULL;
external->plug_embedded = FALSE;
external->n_restarts = 0;
external->show_configure = FALSE;
@ -235,7 +248,7 @@ panel_plugin_external_46_finalize (GObject *object)
{
PanelPluginExternal46 *external = PANEL_PLUGIN_EXTERNAL_46 (object);
GSList *li;
g_message ("external-plugin-46 finalized");
if (external->watch_id != 0)
{
/* remove the child watch and don't leave zomies */
@ -250,6 +263,8 @@ panel_plugin_external_46_finalize (GObject *object)
g_slist_free (external->queue);
}
g_strfreev (external->arguments);
g_object_unref (G_OBJECT (external->module));
(*G_OBJECT_CLASS (panel_plugin_external_46_parent_class)->finalize) (object);
@ -271,6 +286,10 @@ panel_plugin_external_46_get_property (GObject *object,
g_value_set_int (value, external->unique_id);
break;
case PROP_ARGUMENTS:
g_value_set_boxed (value, external->arguments);
break;
case PROP_MODULE:
g_value_set_object (value, external->module);
break;
@ -297,6 +316,10 @@ panel_plugin_external_46_set_property (GObject *object,
external->unique_id = g_value_get_int (value);
break;
case PROP_ARGUMENTS:
external->arguments = g_value_dup_boxed (value);
break;
case PROP_MODULE:
external->module = g_value_dup_object (value);
break;
@ -313,12 +336,13 @@ static void
panel_plugin_external_46_realize (GtkWidget *widget)
{
PanelPluginExternal46 *external = PANEL_PLUGIN_EXTERNAL_46 (widget);
gchar **argv;
GError *error = NULL;
gboolean succeed;
gchar *socket_id, *unique_id;
GdkScreen *screen;
GPid pid;
gchar **argv;
GError *error = NULL;
gboolean succeed;
gchar *socket_id, *unique_id;
GPid pid;
guint argc = PLUGIN_ARGV_ARGUMENTS;
guint i;
/* realize the socket first */
(*GTK_WIDGET_CLASS (panel_plugin_external_46_parent_class)->realize) (widget);
@ -327,25 +351,28 @@ panel_plugin_external_46_realize (GtkWidget *widget)
socket_id = g_strdup_printf ("%d", gtk_socket_get_id (GTK_SOCKET (widget)));
unique_id = g_strdup_printf ("%d", external->unique_id);
/* add the number of arguments to the argc count */
if (G_UNLIKELY (external->arguments != NULL))
argc += g_strv_length (external->arguments);
/* setup the basic argv */
argv = g_new0 (gchar *, 12);
argv[0] = (gchar *) panel_module_get_filename (external->module);
argv[1] = (gchar *) "-n";
argv[2] = (gchar *) panel_module_get_name (external->module);
argv[3] = (gchar *) "-i";
argv[4] = (gchar *) unique_id;
argv[5] = (gchar *) "-d";
argv[6] = (gchar *) panel_module_get_display_name (external->module);
argv[7] = (gchar *) "-c";
argv[8] = (gchar *) panel_module_get_comment (external->module);
argv[9] = (gchar *) "-s";
argv[10] = (gchar *) socket_id;
/* get the widget screen */
screen = gtk_widget_get_screen (widget);
argv = g_new0 (gchar *, argc + 1);
argv[PLUGIN_ARGV_0] = (gchar *) panel_module_get_filename (external->module);
argv[PLUGIN_ARGV_FILENAME] = (gchar *) ""; /* unused, for wrapper only */
argv[PLUGIN_ARGV_UNIQUE_ID] = (gchar *) unique_id;
argv[PLUGIN_ARGV_SOCKET_ID] = (gchar *) socket_id;
argv[PLUGIN_ARGV_NAME] = (gchar *) panel_module_get_name (external->module);
argv[PLUGIN_ARGV_DISPLAY_NAME] = (gchar *) panel_module_get_display_name (external->module);
argv[PLUGIN_ARGV_COMMENT] = (gchar *) panel_module_get_comment (external->module);
/* append the arguments */
if (G_UNLIKELY (external->arguments != NULL))
for (i = 0; external->arguments[i] != NULL; i++)
argv[i + PLUGIN_ARGV_ARGUMENTS] = external->arguments[i];
/* spawn the proccess */
succeed = gdk_spawn_on_screen (screen, NULL, argv, NULL,
succeed = gdk_spawn_on_screen (gtk_widget_get_screen (widget),
NULL, argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD, NULL,
NULL, &pid, &error);
@ -743,9 +770,11 @@ panel_plugin_external_46_child_watch (GPid pid,
switch (WEXITSTATUS (status))
{
case WRAPPER_EXIT_FAILURE:
case WRAPPER_EXIT_NO_PROVIDER:
case WRAPPER_EXIT_PREINIT:
case PLUGIN_EXIT_SUCCESS:
case PLUGIN_EXIT_FAILURE:
case PLUGIN_EXIT_PREINIT_FAILED:
case PLUGIN_EXIT_CHECK_FAILED:
case PLUGIN_EXIT_NO_PROVIDER:
/* wait until everything is settled, then destroy the
* external plugin so it is removed from the configuration */
exo_gtk_object_destroy_later (GTK_OBJECT (external));
@ -773,10 +802,11 @@ panel_plugin_external_46_new (PanelModule *module,
{
panel_return_val_if_fail (PANEL_IS_MODULE (module), NULL);
panel_return_val_if_fail (unique_id != -1, NULL);
/* TODO arguments */
return g_object_new (PANEL_TYPE_PLUGIN_EXTERNAL_46,
"module", module,
"unique-id", unique_id, NULL);
"unique-id", unique_id,
"arguments", arguments, NULL);
}

37
panel/panel-plugin-external.c

@ -397,8 +397,7 @@ panel_plugin_external_realize (GtkWidget *widget)
gboolean succeed;
gchar *socket_id, *unique_id;
guint i;
guint argc = ARGV_ARGUMENTS + 1;
GdkScreen *screen;
guint argc = PLUGIN_ARGV_ARGUMENTS;
GPid pid;
/* realize the socket first */
@ -408,30 +407,28 @@ panel_plugin_external_realize (GtkWidget *widget)
socket_id = g_strdup_printf ("%d", gtk_socket_get_id (GTK_SOCKET (widget)));
unique_id = g_strdup_printf ("%d", external->unique_id);
/* add the number of arguments to the argv count */
/* add the number of arguments to the argc count */
if (G_UNLIKELY (external->arguments != NULL))
argc += g_strv_length (external->arguments);
/* setup the basic argv */
argv = g_new0 (gchar *, argc);
argv[ARGV_0] = (gchar *) WRAPPER_BIN;
argv[ARGV_FILENAME] = (gchar *) panel_module_get_filename (external->module);
argv[ARGV_UNIQUE_ID] = (gchar *) unique_id;
argv[ARGV_SOCKET_ID] = (gchar *) socket_id;
argv[ARGV_NAME] = (gchar *) panel_module_get_name (external->module);
argv[ARGV_DISPLAY_NAME] = (gchar *) panel_module_get_display_name (external->module);
argv[ARGV_COMMENT] = (gchar *) panel_module_get_comment (external->module);
argv = g_new0 (gchar *, argc + 1);
argv[PLUGIN_ARGV_0] = (gchar *) WRAPPER_BIN;
argv[PLUGIN_ARGV_FILENAME] = (gchar *) panel_module_get_filename (external->module);
argv[PLUGIN_ARGV_UNIQUE_ID] = (gchar *) unique_id;
argv[PLUGIN_ARGV_SOCKET_ID] = (gchar *) socket_id;
argv[PLUGIN_ARGV_NAME] = (gchar *) panel_module_get_name (external->module);
argv[PLUGIN_ARGV_DISPLAY_NAME] = (gchar *) panel_module_get_display_name (external->module);
argv[PLUGIN_ARGV_COMMENT] = (gchar *) panel_module_get_comment (external->module);
/* append the arguments */
if (G_UNLIKELY (external->arguments != NULL))
for (i = 0; external->arguments[i] != NULL; i++)
argv[i + ARGV_ARGUMENTS] = external->arguments[i];
/* get the widget screen */
screen = gtk_widget_get_screen (widget);
argv[i + PLUGIN_ARGV_ARGUMENTS] = external->arguments[i];
/* spawn the proccess */
succeed = gdk_spawn_on_screen (screen, NULL, argv, NULL,
succeed = gdk_spawn_on_screen (gtk_widget_get_screen (widget),
NULL, argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD, NULL,
NULL, &pid, &error);
@ -861,9 +858,11 @@ panel_plugin_external_child_watch (GPid pid,
switch (WEXITSTATUS (status))
{
case WRAPPER_EXIT_FAILURE:
case WRAPPER_EXIT_NO_PROVIDER:
case WRAPPER_EXIT_PREINIT:
case PLUGIN_EXIT_SUCCESS:
case PLUGIN_EXIT_FAILURE:
case PLUGIN_EXIT_PREINIT_FAILED:
case PLUGIN_EXIT_CHECK_FAILED:
case PLUGIN_EXIT_NO_PROVIDER:
/* wait until everything is settled, then destroy the
* external plugin so it is removed from the configuration */
exo_gtk_object_destroy_later (GTK_OBJECT (external));

26
wrapper/main.c

@ -171,7 +171,7 @@ main (gint argc, gchar **argv)
gchar process_name[16];
#endif
GModule *library = NULL;
gint retval = WRAPPER_EXIT_FAILURE;
gint retval = PLUGIN_EXIT_FAILURE;
XfcePanelPluginPreInit preinit_func;
DBusGConnection *dbus_gconnection;
DBusGProxy *dbus_gproxy = NULL;
@ -198,20 +198,20 @@ main (gint argc, gchar **argv)
#endif
/* check if we have all the reuiqred arguments */
if (G_UNLIKELY (argc < ARGV_ARGUMENTS))
if (G_UNLIKELY (argc < PLUGIN_ARGV_ARGUMENTS))
{
g_critical ("Not enough arguments are passed to the wrapper");
return WRAPPER_EXIT_FAILURE;
return PLUGIN_EXIT_FAILURE;
}
/* put all arguments in understandable strings */
filename = argv[ARGV_FILENAME];
unique_id = strtol (argv[ARGV_UNIQUE_ID], NULL, 0);
socket_id = strtol (argv[ARGV_SOCKET_ID], NULL, 0);
name = argv[ARGV_NAME];
display_name = argv[ARGV_DISPLAY_NAME];
comment = argv[ARGV_COMMENT];
arguments = argv + ARGV_ARGUMENTS;
filename = argv[PLUGIN_ARGV_FILENAME];
unique_id = strtol (argv[PLUGIN_ARGV_UNIQUE_ID], NULL, 0);
socket_id = strtol (argv[PLUGIN_ARGV_SOCKET_ID], NULL, 0);
name = argv[PLUGIN_ARGV_NAME];
display_name = argv[PLUGIN_ARGV_DISPLAY_NAME];
comment = argv[PLUGIN_ARGV_COMMENT];
arguments = argv + PLUGIN_ARGV_ARGUMENTS;
#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
/* change the process name to something that makes sence */
@ -235,7 +235,7 @@ main (gint argc, gchar **argv)
&& preinit_func != NULL
&& (*preinit_func) (argc, argv) == FALSE)
{
retval = WRAPPER_EXIT_PREINIT;
retval = PLUGIN_EXIT_PREINIT_FAILED;
goto leave;
}
@ -296,7 +296,7 @@ main (gint argc, gchar **argv)
gtk_widget_show (GTK_WIDGET (provider));
/* everything when fine */
retval = WRAPPER_EXIT_SUCCESS;
retval = PLUGIN_EXIT_SUCCESS;
/* enter the main loop */
gtk_main ();
@ -312,7 +312,7 @@ main (gint argc, gchar **argv)
}
else
{
retval = WRAPPER_EXIT_NO_PROVIDER;
retval = PLUGIN_EXIT_NO_PROVIDER;
}
leave:

Loading…
Cancel
Save