Rename panel, plugin, and plugin_class to Panel, Plugin, and
[lxde/lxpanel.git] / src / plugins / deskno / deskno.c
CommitLineData
a52c2257
HJYP
1// reused dclock.c and variables from pager.c
2// 11/23/04 by cmeury
3
4#include <sys/types.h>
5#include <stdio.h>
6#include <stdlib.h>
e7cb732b 7#include <glib/gi18n.h>
a52c2257
HJYP
8
9#include "panel.h"
10#include "misc.h"
11#include "plugin.h"
12
13// #define DEBUG
14#include "dbg.h"
15
16typedef struct {
17 GtkWidget *main;
18 GtkWidget *namew;
19 GtkTooltips *tip;
20} deskno;
21
22static void
23clicked( GtkWidget *widget, gpointer data)
24{
25 int desknum = get_net_current_desktop();
26 int desks = get_net_number_of_desktops();
27 int newdesk;
28
29 ENTER;
30 if(desknum == (desks - 1))
4542c20d 31 newdesk = 0;
a52c2257 32 else
4542c20d 33 newdesk = desknum + 1;
a52c2257
HJYP
34 g_assert(data != NULL);
35 Xclimsg(GDK_ROOT_WINDOW(), a_NET_CURRENT_DESKTOP, newdesk, 0, 0, 0, 0);
36 RET();
37}
38
39
40
41static gint
42name_update(GtkWidget *widget, deskno *dc)
43{
44 char buffer [15];
45 int n;
46 int desknum = get_net_current_desktop() + 1;
47
48 ENTER;
49 n = sprintf(buffer, "<b>%d</b>", desknum);
50 gtk_label_set_markup (GTK_LABEL(dc->namew), buffer) ;
51 RET(TRUE);
52}
53
54
55static int
22242ed4 56deskno_constructor(Plugin *p, char** fp)
a52c2257
HJYP
57{
58 deskno *dc;
59 GtkWidget *button;
4542c20d 60
a52c2257
HJYP
61 ENTER;
62 dc = g_new0(deskno, 1);
63 g_return_val_if_fail(dc != NULL, 0);
64 p->priv = dc;
4542c20d 65
a52c2257
HJYP
66 dc->main = gtk_event_box_new();
67 dc->tip = gtk_tooltips_new();
68 button = gtk_button_new();
69 gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
70 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (clicked), (gpointer) dc);
71 dc->namew = gtk_label_new("ww");
72 gtk_container_add(GTK_CONTAINER(button), dc->namew);
a52c2257
HJYP
73 name_update(button, dc);
74 g_signal_connect (G_OBJECT (fbev), "current_desktop", G_CALLBACK (name_update), (gpointer) dc);
a52c2257 75
4542c20d
HJYP
76 p->pwid = button;
77 gtk_widget_show_all(p->pwid);
a52c2257 78
4542c20d 79 RET(1);
a52c2257
HJYP
80}
81
82
83static void
22242ed4 84deskno_destructor(Plugin *p)
a52c2257
HJYP
85{
86 deskno *dc = (deskno *)p->priv;
87
88 ENTER;
89 dc = (deskno *) p->priv;
4542c20d 90 g_signal_handlers_disconnect_by_func(G_OBJECT (fbev), name_update, dc);
a52c2257
HJYP
91 g_free(dc);
92 RET();
93}
94
22242ed4 95PluginClass deskno_plugin_class = {
a52c2257
HJYP
96 fname: NULL,
97 count: 0,
98
99 type : "deskno",
ce522551 100 name : N_("Desktop No / Workspace Name"),
a52c2257 101 version: "0.6",
e7cb732b 102 description : N_("Display workspace number, by cmeury@users.sf.net"),
a52c2257
HJYP
103
104 constructor : deskno_constructor,
105 destructor : deskno_destructor,
9c97f69e
HJYP
106 config : NULL,
107 save : NULL
a52c2257 108};