9433ae85461f0636ce8fdf1c226ddb1681f29e15
[debian/lxpanel.git] / plugins / space.c
1 /**
2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
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
19 #include <stdlib.h>
20
21 #include <glib/gi18n.h>
22
23 #include "plugin.h"
24
25 /* Private context for space plugin. */
26 typedef struct {
27 LXPanel *panel; /* The panel and settings are required to apply config */
28 config_setting_t *settings;
29 int size; /* Size of spacer */
30 } SpacePlugin;
31
32 static gboolean space_apply_configuration(gpointer user_data);
33
34 /* Plugin constructor. */
35 static GtkWidget *space_constructor(LXPanel *panel, config_setting_t *settings)
36 {
37 /* Allocate plugin context and set into Plugin private data pointer. */
38 SpacePlugin * sp = g_new0(SpacePlugin, 1);
39 GtkWidget * p;
40
41 /* Load parameters from the configuration file. */
42 config_setting_lookup_int(settings, "Size", &sp->size);
43
44 /* Save construction pointers */
45 sp->panel = panel;
46 sp->settings = settings;
47
48 /* Default the size parameter. */
49 if (sp->size == 0)
50 sp->size = 2;
51
52 /* Allocate top level widget and set into Plugin widget pointer. */
53 p = gtk_event_box_new();
54 lxpanel_plugin_set_data(p, sp, g_free);
55 gtk_widget_set_has_window(p,FALSE);
56 gtk_widget_add_events(p, GDK_BUTTON_PRESS_MASK);
57 gtk_container_set_border_width(GTK_CONTAINER(p), 0);
58
59 /* Apply the configuration and show the widget. */
60 space_apply_configuration(p);
61 return p;
62 }
63
64 /* Callback when the configuration dialog has recorded a configuration change. */
65 static gboolean space_apply_configuration(gpointer user_data)
66 {
67 GtkWidget * p = user_data;
68 SpacePlugin * sp = lxpanel_plugin_get_data(p);
69
70 /* Apply settings. */
71 if (panel_get_orientation(sp->panel) == GTK_ORIENTATION_HORIZONTAL)
72 gtk_widget_set_size_request(p, sp->size, 2);
73 else
74 gtk_widget_set_size_request(p, 2, sp->size);
75 /* Save config values */
76 config_group_set_int(sp->settings, "Size", sp->size);
77 return FALSE;
78 }
79
80 /* Callback when the configuration dialog is to be shown. */
81 static GtkWidget *space_configure(LXPanel *panel, GtkWidget *instance)
82 {
83 SpacePlugin * sp = lxpanel_plugin_get_data(instance);
84 GtkWidget * dlg;
85
86 dlg = lxpanel_generic_config_dlg(_("Spacer"), panel,
87 space_apply_configuration, instance,
88 _("Size"), &sp->size, CONF_TYPE_INT, NULL);
89 gtk_widget_set_size_request(dlg, 200, -1); /* Improve geometry */
90 return dlg;
91 }
92
93 /* Plugin descriptor. */
94 LXPanelPluginInit lxpanel_static_plugin_space = {
95 .name = N_("Spacer"),
96 .description = N_("Allocate space"),
97
98 /* Stretch is available but not default for this plugin. */
99 .expand_available = TRUE,
100
101 .new_instance = space_constructor,
102 .config = space_configure,
103 };