9addfd0296167d4042b50969185c529a26ad607f
[lxde/lxpanel.git] / src / plugins / pager.c
1 /* pager.c -- pager module of lxpanel project
2 *
3 * Copyright (C) 2009 Dongxu Li <song6song@sourceforge.net>
4 *
5 * This file is part of lxpanel.
6 *
7 * lxpanel is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * lxpanel is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with sawfish; see the file COPYING. If not, write to
19 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA.
21 */
22
23 #include <gtk/gtk.h>
24
25 #include <glib/gi18n.h>
26 #ifndef WNCK_I_KNOW_THIS_IS_UNSTABLE
27 #define WNCK_I_KNOW_THIS_IS_UNSTABLE
28 #endif
29 #include <libwnck/libwnck.h>
30
31 #include "plugin.h"
32
33
34 static void on_realize(GtkWidget *p, Panel *panel)
35 {
36 WnckPager *pager = WNCK_PAGER(gtk_bin_get_child(GTK_BIN(p)));
37 int rows, r;
38
39 /* set geometry */
40 wnck_pager_set_orientation(pager, panel_get_orientation(panel));
41 rows = panel_get_height(panel) / (panel_get_icon_size(panel) * 2) + 1; /* min */
42 r = (panel_get_height(panel) - 4) / panel_get_icon_size(panel); /* max */
43 /* g_debug("pager for height %d and icon size %d: %d to %d",panel_get_height(panel),panel_get_icon_size(panel),r,rows); */
44 rows = MAX(rows, r);
45 wnck_pager_set_n_rows(pager, rows);
46 }
47
48 static GtkWidget *pager_constructor(Panel *panel, config_setting_t *settings)
49 {
50 GtkWidget *p, *w;
51
52 w = wnck_pager_new(NULL);
53 g_return_val_if_fail(w != NULL, 0);
54 p = gtk_event_box_new();
55 GTK_WIDGET_SET_FLAGS(p, GTK_NO_WINDOW);
56
57 /* we cannot configure pager until it added into widgets hierarchy */
58 g_signal_connect(p, "realize", G_CALLBACK(on_realize), panel);
59 wnck_pager_set_display_mode(WNCK_PAGER(w), WNCK_PAGER_DISPLAY_CONTENT);
60
61 gtk_widget_show(w);
62
63 gtk_container_set_border_width(GTK_CONTAINER(p), 2);
64 gtk_container_add(GTK_CONTAINER(p), w);
65
66 return p;
67 }
68
69 static void pager_panel_configuration_changed(Panel *panel, GtkWidget *p)
70 {
71 on_realize(p, panel);
72 }
73
74 LXPanelPluginInit lxpanel_static_plugin_pager = {
75 .name = N_("Desktop Pager"),
76 .description = N_("Simple pager plugin"),
77
78 .new_instance = pager_constructor,
79 .reconfigure = pager_panel_configuration_changed
80 };