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