Dragging of taskbar buttons
[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 36 WnckPager *pager = WNCK_PAGER(gtk_bin_get_child(GTK_BIN(p)));
4da53742 37 int rows, r, h = panel_get_height(panel);
0c86059b
AG
38
39 /* set geometry */
40 wnck_pager_set_orientation(pager, panel_get_orientation(panel));
4da53742
AG
41 if (panel_get_orientation(panel) == GTK_ORIENTATION_VERTICAL)
42 h *= ((gfloat) gdk_screen_height() / (gfloat) gdk_screen_width());
43 rows = h / (panel_get_icon_size(panel) * 2) + 1; /* min */
44 r = (h - 4) / panel_get_icon_size(panel); /* max */
0c86059b
AG
45 /* g_debug("pager for height %d and icon size %d: %d to %d",panel_get_height(panel),panel_get_icon_size(panel),r,rows); */
46 rows = MAX(rows, r);
47 wnck_pager_set_n_rows(pager, rows);
48}
365bfaec 49
4da53742
AG
50static void on_size_allocate(GtkWidget *p, GdkRectangle *allocation, Panel *panel)
51{
52 /* g_debug("pager: on_size_allocate(): %dx%d", allocation->width, allocation->height); */
53 on_realize(p, panel);
54}
55
0c86059b
AG
56static GtkWidget *pager_constructor(Panel *panel, config_setting_t *settings)
57{
58 GtkWidget *p, *w;
365bfaec 59
0c86059b
AG
60 w = wnck_pager_new(NULL);
61 g_return_val_if_fail(w != NULL, 0);
62 p = gtk_event_box_new();
09fa171b 63 gtk_widget_set_has_window(p, FALSE);
365bfaec 64
0c86059b
AG
65 /* we cannot configure pager until it added into widgets hierarchy */
66 g_signal_connect(p, "realize", G_CALLBACK(on_realize), panel);
4da53742 67 g_signal_connect(p, "size-allocate", G_CALLBACK(on_size_allocate), panel);
0c86059b 68 wnck_pager_set_display_mode(WNCK_PAGER(w), WNCK_PAGER_DISPLAY_CONTENT);
365bfaec 69
0c86059b 70 gtk_widget_show(w);
365bfaec 71
0c86059b
AG
72 gtk_container_set_border_width(GTK_CONTAINER(p), 2);
73 gtk_container_add(GTK_CONTAINER(p), w);
365bfaec 74
0c86059b 75 return p;
365bfaec
AG
76}
77
0c86059b 78static void pager_panel_configuration_changed(Panel *panel, GtkWidget *p)
365bfaec 79{
0c86059b 80 on_realize(p, panel);
365bfaec
AG
81}
82
ae4e6dc6
AG
83static LXPanelPluginInit wnck_pager = {
84 .name = N_("Desktop Pager"),
85 .description = N_("Simple pager plugin"),
86
87 .superseded = TRUE,
88 .new_instance = pager_constructor,
89 .reconfigure = pager_panel_configuration_changed
90};
91
92static void pager_wnck_init(void)
93{
94 lxpanel_register_plugin_type("wnckpager", &wnck_pager);
95}
96
0c86059b 97LXPanelPluginInit lxpanel_static_plugin_pager = {
365bfaec 98 .name = N_("Desktop Pager"),
365bfaec
AG
99 .description = N_("Simple pager plugin"),
100
ae4e6dc6 101 .init = pager_wnck_init,
0c86059b
AG
102 .new_instance = pager_constructor,
103 .reconfigure = pager_panel_configuration_changed
365bfaec 104};