Browse Source

* Update plugins to not wait for realize signal, because plugin construction is now delayed until after this signal

* Add API to allow extra check before plugin creation and update systray to use it (bug #1482). Not sure if it will work properly for external plugins.

(Old svn revision: 20349)
upstream/xfce4-panel-4.10.1
Jasper Huijsmans 17 years ago
parent
commit
a703eaf36d
  1. 12
      libxfce4panel/xfce-panel-plugin-iface.h
  2. 61
      libxfce4panel/xfce-panel-plugin.h
  3. 31
      panel/panel-item-manager.c
  4. 9
      panel/panel-item-manager.h
  5. 6
      panel/panel.c
  6. 11
      plugins/iconbox/iconbox.c
  7. 19
      plugins/launcher/launcher.c
  8. 22
      plugins/pager/pager.c
  9. 48
      plugins/systray/systray.c
  10. 22
      plugins/tasklist/tasklist.c

12
libxfce4panel/xfce-panel-plugin-iface.h

@ -51,6 +51,18 @@ typedef struct _XfcePanelPluginInterface XfcePanelPluginInterface;
**/
typedef void (*XfcePanelPluginFunc) (XfcePanelPlugin *plugin);
/**
* XfcePanelPluginCheck:
*
* 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.
*
* See also: XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK() and
* XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK()
**/
typedef gboolean (*XfcePanelPluginCheck) (GdkScreen *screen);
GType xfce_panel_plugin_get_type (void) G_GNUC_CONST;

61
libxfce4panel/xfce-panel-plugin.h

@ -53,6 +53,38 @@
return 0; \
}
/**
* XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_WITH_CHECK
* @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
* 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; \
}
/**
* XFCE_PANEL_PLUGIN_REGISTER_INTERNAL
* @construct : name of a function that can be cast to an #XfcePanelPluginFunc
@ -73,4 +105,33 @@
return (XfcePanelPluginFunc)construct; \
}
/**
* XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK
* @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
* required to create a panel plugin. The @check function is run before
* creating the plugin, and should return FALSE if plugin creation is not
* possible.
*
* This macro is for plugins implemented as a loadable module. Generally it is
* preferred to create an external plugin, for which you have to use
* XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL() .
*
* See also: <link linkend="XfcePanelPlugin">Panel Plugin interface</link>
**/
#define XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK(construct,check) \
XfcePanelPluginFunc \
xfce_panel_plugin_get_construct (void) \
{ \
return (XfcePanelPluginFunc)construct; \
} \
XfcePanelPluginCheck \
xfce_panel_plugin_get_check (void) \
{ \
return (XfcePanelPluginCheck)check; \
}
#endif /* _XFCE_PANEL_PLUGIN_H */

31
panel/panel-item-manager.c

@ -63,6 +63,7 @@ struct _XfcePanelItemClass
/* for loadable modules only */
GModule *gmodule;
XfcePanelPluginFunc construct;
XfcePanelPluginCheck check;
};
static GHashTable *plugin_classes = NULL;
@ -330,8 +331,9 @@ _decrease_use_count (GtkWidget *item, XfcePanelItemClass *class)
}
GtkWidget *
xfce_panel_item_manager_create_item (const char *name, const char *id,
int size, XfceScreenPosition position)
xfce_panel_item_manager_create_item (GdkScreen *screen, const char *name,
const char *id, int size,
XfceScreenPosition position)
{
XfcePanelItemClass *class;
GtkWidget *item = NULL;
@ -351,6 +353,7 @@ xfce_panel_item_manager_create_item (const char *name, const char *id,
{
gpointer symbol;
XfcePanelPluginFunc (*get_construct) (void);
XfcePanelPluginCheck (*get_check) (void);
if (!(class->gmodule = g_module_open (class->file, 0)))
{
@ -372,11 +375,29 @@ xfce_panel_item_manager_create_item (const char *name, const char *id,
get_construct = symbol;
class->construct = get_construct ();
if (g_module_symbol (class->gmodule,
"xfce_panel_plugin_get_check", &symbol))
{
get_check = symbol;
class->check = get_check ();
}
else
{
class->check = NULL;
}
}
item = xfce_internal_panel_plugin_new (class->plugin_name, id,
class->name, size, position,
class->construct);
if (!class->check || class->check(screen) == TRUE )
{
item = xfce_internal_panel_plugin_new (class->plugin_name,
id,
class->name,
size,
position,
class->construct);
}
}
if (item)

9
panel/panel-item-manager.h

@ -41,10 +41,11 @@ void xfce_panel_item_manager_init (void);
void xfce_panel_item_manager_cleanup (void);
GtkWidget *xfce_panel_item_manager_create_item (const char *name,
const char *id,
int size,
XfceScreenPosition position);
GtkWidget *xfce_panel_item_manager_create_item (GdkScreen *screen,
const char *name,
const char *id,
int size,
XfceScreenPosition position);
/* for 'Add Item' dialog */
GPtrArray *xfce_panel_item_manager_get_item_info_list (void);

6
panel/panel.c

@ -810,11 +810,13 @@ panel_create_item (Panel *panel, const char *name, const char *id)
{
PanelPrivate *priv;
GtkWidget *item = NULL;
XfceMonitor *xmon;
priv = panel->priv;
xmon = panel_app_get_monitor (priv->monitor);
if ((item = xfce_panel_item_manager_create_item (name, id,
priv->size, priv->screen_position)) != NULL)
if ((item = xfce_panel_item_manager_create_item (xmon->screen,
name, id, priv->size, priv->screen_position)) != NULL)
{
g_signal_connect (item, "menu-deactivated",
G_CALLBACK (panel_menu_deactivated), panel);

11
plugins/iconbox/iconbox.c

@ -670,13 +670,6 @@ iconbox_screen_changed (GtkWidget *plugin, GdkScreen *screen, Iconbox *ib)
iconbox_init_icons (ib);
}
static void
iconbox_realize (GtkWidget *plugin, Iconbox *ib)
{
iconbox_screen_changed (GTK_WIDGET (plugin),
gtk_widget_get_screen (plugin), ib);
}
static void
iconbox_construct (XfcePanelPlugin *plugin)
{
@ -748,7 +741,9 @@ iconbox_construct (XfcePanelPlugin *plugin)
g_signal_connect (plugin, "screen-changed",
G_CALLBACK (iconbox_screen_changed), iconbox);
g_signal_connect (plugin, "realize", G_CALLBACK (iconbox_realize), iconbox);
iconbox_screen_changed (GTK_WIDGET (plugin),
gtk_widget_get_screen (GTK_WIDGET (plugin)),
iconbox);
}
/* -------------------------------------------------------------------- *

19
plugins/launcher/launcher.c

@ -153,6 +153,9 @@ launcher_construct (XfcePanelPlugin *plugin)
xfce_panel_plugin_menu_show_configure (plugin);
g_signal_connect (plugin, "configure-plugin",
G_CALLBACK (launcher_configure), launcher);
launcher_set_screen_position (launcher,
xfce_panel_plugin_get_screen_position (plugin));
}
/* -------------------------------------------------------------------- *
@ -1172,19 +1175,6 @@ plugin_icon_theme_changed (GtkWidget *w, gpointer ignored,
/* Create Launcher Plugin Contents */
static void
plugin_realized (XfcePanelPlugin *plugin, LauncherPlugin *launcher)
{
if (!GTK_WIDGET_REALIZED (launcher->iconbutton))
{
gtk_widget_realize (launcher->box);
gtk_widget_realize (launcher->iconbutton);
}
launcher_set_screen_position (launcher,
xfce_panel_plugin_get_screen_position (plugin));
}
static LauncherPlugin *
launcher_new (XfcePanelPlugin *plugin)
{
@ -1270,9 +1260,6 @@ launcher_new (XfcePanelPlugin *plugin)
g_signal_connect (launcher->arrowbutton, "drag-leave",
G_CALLBACK (launcher_menu_drag_leave), launcher);
g_signal_connect (plugin, "realize", G_CALLBACK (plugin_realized),
launcher);
/* configuration */
launcher_read_rc_file (plugin, launcher);

22
plugins/pager/pager.c

@ -155,19 +155,6 @@ pager_write_rc_file (XfcePanelPlugin *plugin, Pager *pager)
xfce_rc_close (rc);
}
static void
pager_realize (XfcePanelPlugin *plugin, Pager *pager)
{
GdkScreen *screen;
int screen_idx;
screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
screen_idx = gdk_screen_get_number (screen);
pager->screen = netk_screen_get (screen_idx);
netk_pager_set_screen (NETK_PAGER (pager->pager), pager->screen);
}
/* create widgets and connect to signals */
static void
pager_n_workspaces_changed (NetkScreen * screen, NetkWorkspace * ws,
@ -211,6 +198,8 @@ pager_screen_changed (GtkWidget *plugin, GdkScreen *screen, Pager *pager)
static void
pager_construct (XfcePanelPlugin *plugin)
{
GdkScreen *screen;
int screen_idx;
Pager *pager = g_new0 (Pager, 1);
g_signal_connect (plugin, "orientation-changed",
@ -225,16 +214,15 @@ pager_construct (XfcePanelPlugin *plugin)
g_signal_connect (plugin, "save",
G_CALLBACK (pager_write_rc_file), pager);
g_signal_connect (plugin, "realize",
G_CALLBACK (pager_realize), pager);
xfce_panel_plugin_menu_show_configure (plugin);
g_signal_connect (plugin, "configure-plugin",
G_CALLBACK (pager_properties_dialog), pager);
pager->plugin = plugin;
pager->screen = netk_screen_get_default ();
screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
screen_idx = gdk_screen_get_number (screen);
pager->screen = netk_screen_get (screen_idx);
pager_read_rc_file (plugin, pager);

48
plugins/systray/systray.c

@ -48,20 +48,38 @@ Systray;
static void systray_properties_dialog (XfcePanelPlugin *plugin,
Systray *systray);
static void systray_free_data (XfcePanelPlugin *plugin, Systray *systray);
static void systray_construct (XfcePanelPlugin *plugin);
static gboolean systray_check (GdkScreen *screen);
/* -------------------------------------------------------------------- *
* Systray *
* -------------------------------------------------------------------- */
static gboolean
systray_check (GdkScreen *screen)
{
Screen *scr = GDK_SCREEN_XSCREEN (screen);
if (xfce_system_tray_check_running (scr))
{
xfce_info (_("There is already a system tray running on this "
"screen"));
return FALSE;
}
return TRUE;
}
static gboolean
register_tray (Systray * systray)
{
GError *error = NULL;
Screen *scr = GDK_SCREEN_XSCREEN (gtk_widget_get_screen (systray->frame));
if (xfce_system_tray_check_running (scr))
if (!systray_check (gtk_widget_get_screen (systray->frame)))
{
xfce_info (_("There is already a system tray running on this "
"screen"));
@ -108,12 +126,28 @@ message_new (XfceSystemTray * tray, GtkWidget * icon, glong id,
g_print ("++ notification: %s\n", text);
}
static gboolean
systray_remove (Systray *systray)
{
GtkWidget *widget = GTK_WIDGET (systray->plugin);
systray_free_data (systray->plugin, systray);
gtk_widget_destroy (widget);
return FALSE;
}
static void
systray_start (Systray *systray)
{
if (!systray->tray_registered)
{
systray->tray_registered = register_tray (systray);
if (!systray->tray_registered)
{
g_idle_add ((GSourceFunc)systray_remove, systray);
}
}
}
@ -133,7 +167,8 @@ systray_stop (Systray *systray)
/* Register with the panel */
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (systray_construct);
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK (systray_construct,
systray_check);
/* Interface Implementation */
@ -235,12 +270,6 @@ systray_write_rc_file (XfcePanelPlugin *plugin, Systray *systray)
xfce_rc_close (rc);
}
static void
frame_realize (GtkWidget *frame, Systray *systray)
{
systray_start (systray);
}
/* create widgets and connect to signals */
static void
systray_construct (XfcePanelPlugin *plugin)
@ -312,8 +341,7 @@ systray_construct (XfcePanelPlugin *plugin)
g_signal_connect (systray->tray, "message_new", G_CALLBACK (message_new),
systray);
g_signal_connect (systray->frame, "realize", G_CALLBACK (frame_realize),
systray);
systray_start (systray);
}
/* -------------------------------------------------------------------- *

22
plugins/tasklist/tasklist.c

@ -198,19 +198,6 @@ tasklist_write_rc_file (XfcePanelPlugin *plugin, Tasklist *tasklist)
xfce_rc_close (rc);
}
static void
tasklist_realize (XfcePanelPlugin *plugin, Tasklist *tasklist)
{
GdkScreen *screen;
int screen_idx;
screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
screen_idx = gdk_screen_get_number (screen);
netk_tasklist_set_screen (NETK_TASKLIST (tasklist->list),
netk_screen_get (screen_idx));
}
/* create widgets and connect to signals */
static gboolean
handle_expose (GtkWidget *widget, GdkEventExpose *ev, Tasklist *tasklist)
@ -251,6 +238,8 @@ tasklist_screen_changed (GtkWidget *plugin, GdkScreen *screen,
static void
tasklist_construct (XfcePanelPlugin *plugin)
{
GdkScreen *screen;
int screen_idx;
Tasklist *tasklist = g_new0 (Tasklist, 1);
tasklist->plugin = plugin;
@ -267,9 +256,6 @@ tasklist_construct (XfcePanelPlugin *plugin)
g_signal_connect (plugin, "save",
G_CALLBACK (tasklist_write_rc_file), tasklist);
g_signal_connect (plugin, "realize",
G_CALLBACK (tasklist_realize), tasklist);
xfce_panel_plugin_menu_show_configure (plugin);
g_signal_connect (plugin, "configure-plugin",
G_CALLBACK (tasklist_properties_dialog), tasklist);
@ -296,7 +282,9 @@ tasklist_construct (XfcePanelPlugin *plugin)
g_signal_connect (tasklist->handle, "expose-event",
G_CALLBACK (handle_expose), tasklist);
tasklist->list = netk_tasklist_new (netk_screen_get_default ());
screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
screen_idx = gdk_screen_get_number (screen);
tasklist->list = netk_tasklist_new (netk_screen_get (screen_idx));
gtk_widget_show (tasklist->list);
gtk_box_pack_start (GTK_BOX (tasklist->box), tasklist->list,
TRUE, TRUE, 0);

Loading…
Cancel
Save