Migrate built-in "pager" plugin to new APIs.
[lxde/lxpanel.git] / src / plugins / pager.c
CommitLineData
365bfaec
AG
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
0c86059b 31#include "plugin.h"
365bfaec 32
365bfaec 33
0c86059b 34static void on_realize(GtkWidget *p, Panel *panel)
365bfaec 35{
0c86059b
AG
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}
365bfaec 47
0c86059b
AG
48static GtkWidget *pager_constructor(Panel *panel, config_setting_t *settings)
49{
50 GtkWidget *p, *w;
365bfaec 51
0c86059b
AG
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);
365bfaec 56
0c86059b
AG
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);
365bfaec 60
0c86059b 61 gtk_widget_show(w);
365bfaec 62
0c86059b
AG
63 gtk_container_set_border_width(GTK_CONTAINER(p), 2);
64 gtk_container_add(GTK_CONTAINER(p), w);
365bfaec 65
0c86059b 66 return p;
365bfaec
AG
67}
68
0c86059b 69static void pager_panel_configuration_changed(Panel *panel, GtkWidget *p)
365bfaec 70{
0c86059b 71 on_realize(p, panel);
365bfaec
AG
72}
73
0c86059b 74LXPanelPluginInit lxpanel_static_plugin_pager = {
365bfaec 75 .name = N_("Desktop Pager"),
365bfaec
AG
76 .description = N_("Simple pager plugin"),
77
0c86059b
AG
78 .new_instance = pager_constructor,
79 .reconfigure = pager_panel_configuration_changed
365bfaec 80};