Add support for monitors "All" to span panel over all monitors.
[lxde/lxpanel.git] / src / plugin.c
CommitLineData
16fb8c2e 1/**
8c9c4b55 2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
a99ee9e1
JH
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
a52c2257
HJYP
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
b31cb1d2 23#include "private.h"
a52c2257
HJYP
24
25#include <gdk-pixbuf/gdk-pixbuf.h>
26#include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
27#include <gdk/gdk.h>
28#include <string.h>
29#include <stdlib.h>
30
a52c2257
HJYP
31#include "misc.h"
32#include "bg.h"
a52c2257 33
239cb032 34#include <glib-object.h>
3b847d8b
AG
35#include <glib/gi18n.h>
36#include <libfm/fm-gtk.h>
a52c2257
HJYP
37
38//#define DEBUG
39#include "dbg.h"
40
2918994e 41static void plugin_class_unref(PluginClass * pc);
239cb032 42
752ee4e2
AG
43GQuark lxpanel_plugin_qinit;
44GQuark lxpanel_plugin_qconf;
17fab6e5 45GQuark lxpanel_plugin_qdata;
50928868 46GQuark lxpanel_plugin_qsize;
17fab6e5
AG
47static GHashTable *_all_types = NULL;
48
2918994e 49/* Dynamic parameter for static (built-in) plugins must be FALSE so we will not try to unload them */
9dd114c4 50#define REGISTER_STATIC_PLUGIN_CLASS(pc) \
a52c2257 51do {\
22242ed4 52 extern PluginClass pc;\
9dd114c4 53 register_plugin_class(&pc, FALSE);\
a52c2257
HJYP
54} while (0)
55
191694fb 56static inline const LXPanelPluginInit *_find_plugin(const char *name)
17fab6e5
AG
57{
58 return g_hash_table_lookup(_all_types, name);
59}
60
752ee4e2 61static GtkWidget *_old_plugin_config(LXPanel *panel, GtkWidget *instance)
17fab6e5 62{
191694fb 63 const LXPanelPluginInit *init = PLUGIN_CLASS(instance);
17fab6e5
AG
64 Plugin * plugin;
65
131514c9 66 g_return_val_if_fail(init != NULL && init->new_instance == NULL, NULL);
17fab6e5
AG
67 plugin = lxpanel_plugin_get_data(instance);
68 if (plugin->class->config)
752ee4e2 69 plugin->class->config(plugin, GTK_WINDOW(panel));
131514c9 70 return NULL;
17fab6e5
AG
71}
72
a7bd16a4 73static void _old_plugin_reconfigure(LXPanel *panel, GtkWidget *instance)
17fab6e5 74{
191694fb 75 const LXPanelPluginInit *init = PLUGIN_CLASS(instance);
17fab6e5
AG
76 Plugin * plugin;
77
78 g_return_if_fail(init != NULL && init->new_instance == NULL);
79 plugin = lxpanel_plugin_get_data(instance);
80 if (plugin->class->panel_configuration_changed)
81 plugin->class->panel_configuration_changed(plugin);
82}
83
2918994e 84/* Register a PluginClass. */
85static void register_plugin_class(PluginClass * pc, gboolean dynamic)
a52c2257 86{
17fab6e5
AG
87 LXPanelPluginInit *init = g_new0(LXPanelPluginInit, 1);
88 init->_reserved1 = pc;
89 init->name = pc->name;
90 init->description = pc->description;
91 if (pc->config)
92 init->config = _old_plugin_config;
93 if (pc->panel_configuration_changed)
94 init->reconfigure = _old_plugin_reconfigure;
95 init->one_per_system = pc->one_per_system;
96 init->expand_available = pc->expand_available;
97 init->expand_default = pc->expand_default;
a52c2257 98 pc->dynamic = dynamic;
17fab6e5 99 g_hash_table_insert(_all_types, g_strdup(pc->type), init);
a52c2257
HJYP
100}
101
2918994e 102/* Load a dynamic plugin. */
17fab6e5 103static void plugin_load_dynamic(const char * type, const gchar * path)
6a6ad54e 104{
2918994e 105 PluginClass * pc = NULL;
106
107 /* Load the external module. */
108 GModule * m = g_module_open(path, G_MODULE_BIND_LAZY);
109 if (m != NULL)
110 {
111 /* Formulate the name of the expected external variable of type PluginClass. */
112 char class_name[128];
113 g_snprintf(class_name, sizeof(class_name), "%s_plugin_class", type);
114
115 /* Validate that the external variable is of type PluginClass. */
116 gpointer tmpsym;
117 if (( ! g_module_symbol(m, class_name, &tmpsym)) /* Ensure symbol is present */
118 || ((pc = tmpsym) == NULL)
119 || (pc->structure_size != sizeof(PluginClass)) /* Then check versioning information */
120 || (pc->structure_version != PLUGINCLASS_VERSION)
121 || (strcmp(type, pc->type) != 0)) /* Then and only then access other fields; check name */
122 {
123 g_module_close(m);
06e29ce1 124 g_warning("%s.so is not a lxpanel plugin", type);
17fab6e5 125 return;
2918994e 126 }
127
128 /* Register the newly loaded and valid plugin. */
129 pc->gmodule = m;
130 register_plugin_class(pc, TRUE);
17fab6e5 131 pc->count = 1;
6a6ad54e 132 }
a52c2257
HJYP
133}
134
2918994e 135/* Unreference a dynamic plugin. */
136static void plugin_class_unref(PluginClass * pc)
6a6ad54e 137{
2918994e 138 pc->count -= 1;
139
140 /* If the reference count drops to zero, unload the plugin if it is dynamic and has declared itself unloadable. */
141 if ((pc->count == 0)
142 && (pc->dynamic)
143 && ( ! pc->not_unloadable))
144 {
6a6ad54e
HJYP
145 g_module_close(pc->gmodule);
146 }
147}
148
17fab6e5
AG
149/* Loads all available old type plugins. Should be removed in future releases. */
150static void plugin_get_available_classes(void)
6a6ad54e 151{
6a6ad54e 152#ifndef DISABLE_PLUGINS_LOADING
2918994e 153 GDir * dir = g_dir_open(PACKAGE_LIB_DIR "/lxpanel/plugins", 0, NULL);
154 if (dir != NULL)
155 {
156 const char * file;
157 while ((file = g_dir_read_name(dir)) != NULL)
158 {
159 if (g_str_has_suffix(file, ".so"))
160 {
161 char * type = g_strndup(file, strlen(file) - 3);
17fab6e5 162 if (_find_plugin(type) == NULL)
2918994e 163 {
164 /* If it has not been loaded, do it. If successful, add it to the result. */
165 char * path = g_build_filename(PACKAGE_LIB_DIR "/lxpanel/plugins", file, NULL );
17fab6e5 166 plugin_load_dynamic(type, path);
2918994e 167 g_free(path);
6a6ad54e 168 }
2918994e 169 g_free(type);
6a6ad54e 170 }
6a6ad54e 171 }
2918994e 172 g_dir_close(dir);
6a6ad54e
HJYP
173 }
174#endif
16fb8c2e 175}
4542c20d 176
2918994e 177/* Recursively set the background of all widgets on a panel background configuration change. */
a7bd16a4 178void plugin_widget_set_background(GtkWidget * w, LXPanel * panel)
4542c20d 179{
2918994e 180 if (w != NULL)
4542c20d 181 {
a7bd16a4 182 Panel *p = panel->priv;
09fa171b 183 if (gtk_widget_get_has_window(w))
4542c20d 184 {
2918994e 185 if ((p->background) || (p->transparent))
186 {
09fa171b
AG
187#if GTK_CHECK_VERSION(2, 20, 0)
188 if (gtk_widget_get_realized(w))
189#else
2918994e 190 if (GTK_WIDGET_REALIZED(w))
09fa171b 191#endif
964b8b7e 192 {
a7bd16a4 193 _panel_determine_background_pixmap(panel, w);
175f73d1 194 gdk_window_invalidate_rect(gtk_widget_get_window(w), NULL, TRUE);
964b8b7e 195 }
2918994e 196 }
197 else
198 {
199 /* Set background according to the current GTK style. */
200 gtk_widget_set_app_paintable(w, FALSE);
09fa171b
AG
201#if GTK_CHECK_VERSION(2, 20, 0)
202 if (gtk_widget_get_realized(w))
203#else
2918994e 204 if (GTK_WIDGET_REALIZED(w))
09fa171b 205#endif
1a571d96 206 {
175f73d1
AG
207 gdk_window_set_back_pixmap(gtk_widget_get_window(w), NULL, TRUE);
208 gtk_style_set_background(gtk_widget_get_style(w),
209 gtk_widget_get_window(w),
210 GTK_STATE_NORMAL);
1a571d96 211 }
2918994e 212 }
4542c20d 213 }
2918994e 214
964b8b7e 215 /* Special handling to get tray icons redrawn. */
2918994e 216 if (GTK_IS_SOCKET(w))
217 {
218 gtk_widget_hide(w);
964b8b7e 219 gdk_window_process_all_updates();
2918994e 220 gtk_widget_show(w);
964b8b7e 221 gdk_window_process_all_updates();
2918994e 222 }
4542c20d 223
2918994e 224 /* Recursively process all children of a container. */
225 if (GTK_IS_CONTAINER(w))
a7bd16a4 226 gtk_container_foreach(GTK_CONTAINER(w), (GtkCallback) plugin_widget_set_background, panel);
4542c20d
HJYP
227 }
228}
229
9dd114c4 230/* Handler for "button_press_event" signal with Plugin as parameter.
231 * External so can be used from a plugin. */
ffdd4b7b 232static gboolean lxpanel_plugin_button_press_event(GtkWidget *plugin, GdkEventButton *event, LXPanel *panel)
9dd114c4 233{
1639d6b3
AG
234 if (event->button == 3 && /* right button */
235 (event->state & gtk_accelerator_get_default_mod_mask()) == 0) /* no key */
9dd114c4 236 {
e56f2fdd 237 GtkMenu* popup = (GtkMenu*)lxpanel_get_plugin_menu(panel, plugin, FALSE);
9dd114c4 238 gtk_menu_popup(popup, NULL, NULL, NULL, NULL, event->button, event->time);
239 return TRUE;
17fab6e5 240 }
9dd114c4 241 return FALSE;
4542c20d 242}
2918994e 243
17fab6e5
AG
244/* for old plugins compatibility */
245gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin)
246{
e56f2fdd 247 return lxpanel_plugin_button_press_event(plugin->pwid, event, PLUGIN_PANEL(plugin->pwid));
17fab6e5
AG
248}
249
2918994e 250/* Helper for position-calculation callback for popup menus. */
a7bd16a4 251void lxpanel_plugin_popup_set_position_helper(LXPanel * p, GtkWidget * near, GtkWidget * popup, gint * px, gint * py)
2918994e 252{
2918994e 253 gint x, y;
175f73d1 254 GtkAllocation allocation;
d9523b89 255 GtkAllocation popup_req;
d6101d43
AG
256
257 /* Get the allocation of the popup menu. */
d9523b89
AG
258 gtk_widget_realize(popup);
259 gtk_widget_get_allocation(popup, &popup_req);
50aa486e
AG
260 if (gtk_widget_is_toplevel(popup))
261 {
262 GdkRectangle extents;
263 /* FIXME: can we wait somehow for WM drawing decorations? */
d9523b89 264 gdk_window_process_all_updates();
50aa486e
AG
265 gdk_window_get_frame_extents(gtk_widget_get_window(popup), &extents);
266 popup_req.width = extents.width;
267 popup_req.height = extents.height;
268 }
175f73d1 269
d6101d43 270 /* Get the origin of the requested-near widget in screen coordinates. */
175f73d1
AG
271 gtk_widget_get_allocation(near, &allocation);
272 gdk_window_get_origin(gtk_widget_get_window(near), &x, &y);
d9523b89
AG
273 if (!gtk_widget_get_has_window(near))
274 {
275 /* For non-window widgets allocation is given within the screen */
276 x += allocation.x;
277 y += allocation.y;
278 }
2918994e 279
280 /* Dispatch on edge to lay out the popup menu with respect to the button.
281 * Also set "push-in" to avoid any case where it might flow off screen. */
a7bd16a4 282 switch (p->priv->edge)
2918994e 283 {
175f73d1 284 case EDGE_TOP: y += allocation.height; break;
d6101d43 285 case EDGE_BOTTOM: y -= popup_req.height; break;
175f73d1 286 case EDGE_LEFT: x += allocation.width; break;
d6101d43 287 case EDGE_RIGHT: x -= popup_req.width; break;
2918994e 288 }
d6101d43
AG
289
290 /* Push onscreen. */
291 int screen_width = gdk_screen_width();
292 int screen_height = gdk_screen_height();
d9523b89
AG
293 x = CLAMP(x, 0, screen_width - popup_req.width);
294 y = CLAMP(y, 0, screen_height - popup_req.height);
295 /* FIXME: take monitor area into account not just screen */
d6101d43 296
2918994e 297 *px = x;
298 *py = y;
299}
4ec924bc 300
d6101d43 301/* for old plugins compatibility -- popup_req is ignored here */
17fab6e5
AG
302void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py)
303{
a7bd16a4 304 lxpanel_plugin_popup_set_position_helper(p->panel->topgwin, near, popup, px, py);
17fab6e5
AG
305}
306
4ec924bc
MJ
307/* Adjust the position of a popup window to ensure that it is not hidden by the panel.
308 * It is observed that some window managers do not honor the strut that is set on the panel. */
17fab6e5 309void lxpanel_plugin_adjust_popup_position(GtkWidget * popup, GtkWidget * parent)
4ec924bc 310{
d9523b89 311 gint x, y;
4ec924bc 312
d9523b89
AG
313 /* Calculate desired position for the popup. */
314 lxpanel_plugin_popup_set_position_helper(PLUGIN_PANEL(parent), parent,
315 popup, &x, &y);
4ec924bc 316 /* Move the popup to position. */
175f73d1 317 gdk_window_move(gtk_widget_get_window(popup), x, y);
4ec924bc 318}
17fab6e5
AG
319
320/* for old plugins compatibility */
321void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin)
322{
323 lxpanel_plugin_adjust_popup_position(popup, plugin->pwid);
324}
325
3b847d8b
AG
326/* Open a specified path in a file manager. */
327static gboolean _open_dir_in_file_manager(GAppLaunchContext* ctx, GList* folder_infos,
328 gpointer user_data, GError** err)
329{
330 FmFileInfo *fi = folder_infos->data; /* only first is used */
331 GAppInfo *app = g_app_info_get_default_for_type("inode/directory", TRUE);
332 GFile *gf;
333 gboolean ret;
334
335 if (app == NULL)
336 {
337 g_set_error_literal(err, G_SHELL_ERROR, G_SHELL_ERROR_EMPTY_STRING,
338 _("No file manager is configured."));
339 return FALSE;
340 }
341 gf = fm_path_to_gfile(fm_file_info_get_path(fi));
342 folder_infos = g_list_prepend(NULL, gf);
343 ret = fm_app_info_launch(app, folder_infos, ctx, err);
344 g_list_free(folder_infos);
345 g_object_unref(gf);
346 g_object_unref(app);
347 return ret;
348}
349
a7bd16a4 350gboolean lxpanel_launch_path(LXPanel *panel, FmPath *path)
3b847d8b
AG
351{
352 return fm_launch_path_simple(NULL, NULL, path, _open_dir_in_file_manager, NULL);
353}
354
2f1173de 355void lxpanel_plugin_show_config_dialog(GtkWidget* plugin)
131514c9 356{
191694fb 357 const LXPanelPluginInit *init = PLUGIN_CLASS(plugin);
a7bd16a4
AG
358 LXPanel *panel = PLUGIN_PANEL(plugin);
359 GtkWidget *dlg = panel->priv->plugin_pref_dialog;
131514c9
AG
360
361 if (dlg && g_object_get_data(G_OBJECT(dlg), "generic-config-plugin") == plugin)
362 return; /* configuration dialog is already shown for this widget */
2f1173de 363 g_return_if_fail(panel != NULL);
752ee4e2 364 dlg = init->config(panel, plugin);
131514c9
AG
365 if (dlg)
366 _panel_show_config_dialog(panel, plugin, dlg);
367}
368
17fab6e5
AG
369#if GLIB_CHECK_VERSION(2, 32, 0)
370static GRecMutex _mutex;
371#else
372static GStaticRecMutex _mutex = G_STATIC_REC_MUTEX_INIT;
373#endif
374
8dfa5918 375#ifndef DISABLE_PLUGINS_LOADING
17fab6e5
AG
376FM_MODULE_DEFINE_TYPE(lxpanel_gtk, LXPanelPluginInit, 1)
377
378static gboolean fm_module_callback_lxpanel_gtk(const char *name, gpointer init, int ver)
379{
380 /* ignore ver for now, only 1 exists */
381 return lxpanel_register_plugin_type(name, init);
382}
8dfa5918 383#endif
17fab6e5
AG
384
385static gboolean old_plugins_loaded = FALSE;
386
387void _prepare_modules(void)
388{
389 _all_types = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
390 lxpanel_plugin_qdata = g_quark_from_static_string("LXPanel::plugin-data");
391 lxpanel_plugin_qinit = g_quark_from_static_string("LXPanel::plugin-init");
392 lxpanel_plugin_qconf = g_quark_from_static_string("LXPanel::plugin-conf");
50928868 393 lxpanel_plugin_qsize = g_quark_from_static_string("LXPanel::plugin-size");
8dfa5918 394#ifndef DISABLE_PLUGINS_LOADING
17fab6e5
AG
395 fm_modules_add_directory(PACKAGE_LIB_DIR "/lxpanel/plugins");
396 fm_module_register_lxpanel_gtk();
8dfa5918 397#endif
17fab6e5
AG
398}
399
400void _unload_modules(void)
401{
402 GHashTableIter iter;
403 gpointer key, val;
404
17fab6e5
AG
405 g_hash_table_iter_init(&iter, _all_types);
406 while(g_hash_table_iter_next(&iter, &key, &val))
407 {
191694fb 408 register const LXPanelPluginInit *init = val;
17fab6e5
AG
409 if (init->new_instance == NULL) /* old type of plugin */
410 {
411 plugin_class_unref(init->_reserved1);
412 g_free(val);
413 }
414 }
415 g_hash_table_destroy(_all_types);
d6ca4fc5
AG
416#ifndef DISABLE_PLUGINS_LOADING
417 fm_module_unregister_type("lxpanel_gtk");
418#endif
17fab6e5
AG
419 old_plugins_loaded = FALSE;
420}
421
191694fb 422gboolean lxpanel_register_plugin_type(const char *name, const LXPanelPluginInit *init)
17fab6e5 423{
191694fb 424 const LXPanelPluginInit *data;
17fab6e5
AG
425
426 /* validate it */
427 if (init->new_instance == NULL || name == NULL || name[0] == '\0')
428 return FALSE;
429#if GLIB_CHECK_VERSION(2, 32, 0)
430 g_rec_mutex_lock(&_mutex);
431#else
432 g_static_rec_mutex_lock(&_mutex);
433#endif
434 /* test if it's registered already */
435 data = _find_plugin(name);
436 if (data == NULL)
437 {
438 if (init->init)
439 init->init();
191694fb 440 g_hash_table_insert(_all_types, g_strdup(name), (gpointer)init);
17fab6e5
AG
441 }
442#if GLIB_CHECK_VERSION(2, 32, 0)
443 g_rec_mutex_unlock(&_mutex);
444#else
445 g_static_rec_mutex_unlock(&_mutex);
446#endif
447 return (data == NULL);
448}
449
450static void _old_plugin_save_hook(const config_setting_t * setting, FILE * f, gpointer user_data)
451{
452 Plugin *pl = user_data;
453 PluginClass *pc = pl->class;
454 if (pc->save)
455 pc->save(pl, f);
456}
457
458/* This is called right before Plugin instance is destroyed */
459static void _old_plugin_destroy(gpointer data)
460{
461 Plugin *pl = data;
462
17fab6e5
AG
463 plugin_class_unref(pl->class);
464
465 /* Free the Plugin structure. */
466 g_free(pl);
467}
468
fcbe8a69
AG
469static void _on_old_widget_destroy(GtkWidget *widget, Plugin *pl)
470{
471 /* Never let run it again. */
472 g_signal_handlers_disconnect_by_func(widget, _on_old_widget_destroy, pl);
473 /* Run the destructor before destroying the top level widget.
474 * This prevents problems with the plugin destroying child widgets. */
475 pl->class->destructor(pl);
476}
477
50928868
AG
478static void on_size_allocate(GtkWidget *widget, GdkRectangle *allocation, LXPanel *p)
479{
480 GdkRectangle *alloc;
481
482 alloc = g_object_get_qdata(G_OBJECT(widget), lxpanel_plugin_qsize);
483 if (alloc->x == allocation->x && alloc->y == allocation->y &&
484 alloc->width == allocation->width && alloc->height == allocation->height)
485 return; /* not changed */
486 *alloc = *allocation;
487 /* g_debug("size-allocate on %s", PLUGIN_CLASS(widget)->name); */
488 _panel_queue_update_background(p);
de5a8e6c 489// _queue_panel_calculate_size(p);
50928868 490}
de5a8e6c 491
a7bd16a4 492GtkWidget *lxpanel_add_plugin(LXPanel *p, const char *name, config_setting_t *cfg, gint at)
17fab6e5 493{
191694fb 494 const LXPanelPluginInit *init;
17fab6e5 495 GtkWidget *widget;
761af06c 496 config_setting_t *s, *pconf;
17fab6e5
AG
497 gint expand, padding = 0, border = 0, i;
498
499 CHECK_MODULES();
500 if (!old_plugins_loaded)
501 plugin_get_available_classes();
502 old_plugins_loaded = TRUE;
503 init = _find_plugin(name);
504 if (init == NULL)
505 return NULL;
506 /* prepare widget settings */
507 if (!init->expand_available)
508 expand = 0;
509 else if ((s = config_setting_get_member(cfg, "expand")))
510 expand = config_setting_get_int(s);
511 else
512 expand = init->expand_default;
513 s = config_setting_get_member(cfg, "padding");
514 if (s)
515 padding = config_setting_get_int(s);
516 s = config_setting_get_member(cfg, "border");
517 if (s)
518 border = config_setting_get_int(s);
519 /* prepare config and create it if need */
520 s = config_setting_add(cfg, "", PANEL_CONF_TYPE_LIST);
761af06c
AG
521 for (i = 0; (pconf = config_setting_get_elem(s, i)); i++)
522 if (strcmp(config_setting_get_name(pconf), "Config") == 0)
17fab6e5 523 break;
761af06c
AG
524 if (!pconf)
525 pconf = config_setting_add(s, "Config", PANEL_CONF_TYPE_GROUP);
17fab6e5
AG
526 /* If this plugin can only be instantiated once, count the instantiation.
527 * This causes the configuration system to avoid displaying the plugin as one that can be added. */
528 if (init->new_instance) /* new style of plugin */
529 {
761af06c 530 widget = init->new_instance(p, pconf);
17fab6e5
AG
531 if (widget == NULL)
532 return widget;
1639d6b3
AG
533 /* always connect lxpanel_plugin_button_press_event() */
534 g_signal_connect(widget, "button-press-event",
535 G_CALLBACK(lxpanel_plugin_button_press_event), p);
e56f2fdd
AG
536 if (init->button_press_event)
537 g_signal_connect(widget, "button-press-event",
538 G_CALLBACK(init->button_press_event), p);
17fab6e5
AG
539 }
540 else
541 {
542 Plugin *pl = g_new0(Plugin, 1);
543 PluginClass *pc = init->_reserved1;
761af06c 544 char *conf = config_setting_to_string(pconf), *fp;
17fab6e5
AG
545
546 pl->class = pc;
a7bd16a4 547 pl->panel = p->priv;
17fab6e5
AG
548 widget = NULL;
549 fp = &conf[9]; /* skip "Config {\n" */
550 /* g_debug("created conf: %s",conf); */
551 /* Call the constructor.
552 * It is responsible for parsing the parameters, and setting "pwid" to the top level widget. */
553 if (pc->constructor(pl, &fp))
554 widget = pl->pwid;
555 g_free(conf);
556
557 if (widget == NULL) /* failed */
558 {
559 g_free(pl);
560 return widget;
561 }
562
563 pc->count += 1;
fcbe8a69 564 g_signal_connect(widget, "destroy", G_CALLBACK(_on_old_widget_destroy), pl);
761af06c 565 config_setting_set_save_hook(pconf, _old_plugin_save_hook, pl);
17fab6e5
AG
566 lxpanel_plugin_set_data(widget, pl, _old_plugin_destroy);
567 }
1e6368db 568 gtk_widget_set_name(widget, name);
a7bd16a4 569 gtk_box_pack_start(GTK_BOX(p->priv->box), widget, expand, TRUE, padding);
17fab6e5 570 gtk_container_set_border_width(GTK_CONTAINER(widget), border);
50928868 571 g_signal_connect(widget, "size-allocate", G_CALLBACK(on_size_allocate), p);
17fab6e5
AG
572 gtk_widget_show(widget);
573 g_object_set_qdata(G_OBJECT(widget), lxpanel_plugin_qconf, cfg);
191694fb 574 g_object_set_qdata(G_OBJECT(widget), lxpanel_plugin_qinit, (gpointer)init);
50928868
AG
575 g_object_set_qdata_full(G_OBJECT(widget), lxpanel_plugin_qsize,
576 g_new0(GdkRectangle, 1), g_free);
17fab6e5
AG
577 return widget;
578}
579
580/* transfer none - note that not all fields are valid there */
581GHashTable *lxpanel_get_all_types(void)
582{
583 return _all_types;
584}