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