Merging upstream version 0.8.0 (Closes: #639729, #761971).
[debian/lxpanel.git] / plugins / separator.c
CommitLineData
00916e98
AG
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 "plugin.h"
20
21#include <glib/gi18n.h>
22
23/* Plugin constructor. */
24static GtkWidget *separator_constructor(LXPanel *panel, config_setting_t *settings)
25{
26 GtkWidget *instance, *sep;
27
28 /* Allocate top level widget and set into Plugin widget pointer. */
29 instance = gtk_event_box_new();
30 gtk_widget_set_has_window(instance, FALSE);
00916e98
AG
31
32 /* Allocate separator as a child of top level. */
33 sep = panel_separator_new(panel);
34 gtk_container_add(GTK_CONTAINER(instance), sep);
35 gtk_widget_show(sep);
36
37 /* Show the widget and return. */
38 return instance;
39}
40
41/* Callback when panel configuration changes. */
42static void separator_reconfigure(LXPanel *panel, GtkWidget *instance)
43{
44 /* Determine if the orientation changed in a way that requires action. */
45 GtkWidget * sep = gtk_bin_get_child(GTK_BIN(instance));
46 if (GTK_IS_VSEPARATOR(sep))
47 {
48 if (panel_get_orientation(panel) == GTK_ORIENTATION_HORIZONTAL)
49 return;
50 }
51 else
52 {
53 if (panel_get_orientation(panel) == GTK_ORIENTATION_VERTICAL)
54 return;
55 }
56
57 /* If the orientation changed, recreate the separator. */
58 gtk_widget_destroy(sep);
59 sep = panel_separator_new(panel);
60 gtk_widget_show(sep);
61 gtk_container_add(GTK_CONTAINER(instance), sep);
62}
63
64/* Plugin descriptor. */
65LXPanelPluginInit lxpanel_static_plugin_separator = {
66 .name = N_("Separator"),
67 .description = N_("Add a separator to the panel"),
68
69 .new_instance = separator_constructor,
70 .reconfigure = separator_reconfigure
71};