GTK+2 panel 

GTK+2 panel Git Source Tree

Root/gppanel.c

1#include "gppanel.h"
2
3#include <string.h>
4#include <X11/Xlib.h>
5#include <X11/Xatom.h>
6#include <gdk/gdkx.h>
7
8
9typedef enum
10{
11 GP_PANEL_EDGE_TOP,
12 GP_PANEL_EDGE_BOTTOM
13} GpPanelEdge;
14
15
16static voidgp_panel_realize(GtkWidget*widget,
17 gpointer user_data);
18static gbooleangp_panel_configure(GtkWidget*widget,
19 GdkEventConfigure*event,
20 gpointer user_data);
21
22
23GpPanel *
24gp_panel_new (const gchar *xml_file,
25 const gchar *top_id,
26 const gchar *bottom_id)
27{
28 GpPanel *panel;
29
30 panel = g_new0 (GpPanel, 1);
31
32 if (xml_file != NULL)
33 panel->xml_file = g_strdup (xml_file);
34 else
35 panel->xml_file = g_strjoin (G_DIR_SEPARATOR_S,
36 g_get_user_config_dir (),
37 "gladepanel",
38 "default.glade",
39 NULL);
40
41 panel->top_id = g_strdup (top_id ? top_id : "GP_PANEL_TOP");
42 panel->bottom_id = g_strdup (bottom_id ? bottom_id : "GP_PANEL_BOTTOM");
43 return panel;
44}
45
46gboolean
47gp_panel_show (GpPanel *panel)
48{
49 GladeXML *xml;
50
51 g_return_val_if_fail (panel != NULL, FALSE);
52
53 xml = glade_xml_new (panel->xml_file, NULL, NULL);
54 if (xml == NULL)
55 {
56 gp_panel_destroy (panel);
57 return FALSE;
58 }
59
60 panel->top_panel = glade_xml_get_widget (xml, panel->top_id);
61 panel->bottom_panel = glade_xml_get_widget (xml, panel->bottom_id);
62
63 if (panel->top_panel == NULL && panel->bottom_panel == NULL)
64 {
65 g_warning ("No `%s' or `%s' widget found", panel->top_id, panel->bottom_id);
66 return FALSE;
67 }
68
69 glade_xml_signal_autoconnect (xml);
70
71 if (panel->top_panel != NULL)
72 {
73 g_signal_connect (panel->top_panel, "realize",
74G_CALLBACK (gp_panel_realize), GINT_TO_POINTER (GP_PANEL_EDGE_TOP));
75 g_signal_connect (panel->top_panel, "configure-event",
76G_CALLBACK (gp_panel_configure), GINT_TO_POINTER (GP_PANEL_EDGE_TOP));
77 gtk_widget_show_all (panel->top_panel);
78 }
79
80 if (panel->bottom_panel != NULL)
81 {
82 g_signal_connect (panel->bottom_panel, "realize",
83G_CALLBACK (gp_panel_realize), GINT_TO_POINTER (GP_PANEL_EDGE_BOTTOM));
84 g_signal_connect (panel->bottom_panel, "configure-event",
85G_CALLBACK (gp_panel_configure), GINT_TO_POINTER (GP_PANEL_EDGE_BOTTOM));
86 gtk_widget_show_all (panel->bottom_panel);
87 }
88
89 g_object_unref (xml);
90 return TRUE;
91}
92
93void
94gp_panel_destroy (GpPanel *panel)
95{
96 g_return_if_fail (panel != NULL);
97
98 g_free (panel->top_id);
99 g_free (panel->bottom_id);
100
101 if (panel->top_panel != NULL)
102 gtk_widget_destroy (panel->top_panel);
103
104 if (panel->bottom_panel != NULL)
105 gtk_widget_destroy (panel->bottom_panel);
106
107 g_free (panel);
108}
109
110
111static void
112gp_panel_realize (GtkWidget *widget,
113 gpointer user_data)
114{
115 GpPanelEdge edge;
116 GdkGeometry geometry;
117
118 edge = (GpPanelEdge) GPOINTER_TO_INT (user_data);
119
120 gtk_window_set_decorated (GTK_WINDOW (widget), FALSE);
121 gtk_window_set_type_hint (GTK_WINDOW (widget), GDK_WINDOW_TYPE_HINT_DOCK);
122 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (widget), TRUE);
123 gtk_window_set_skip_pager_hint (GTK_WINDOW (widget), TRUE);
124
125 geometry.min_width = geometry.max_width = geometry.base_width = gdk_screen_width ();
126 geometry.min_height = geometry.max_height = geometry.base_height = -1;
127 gtk_window_set_geometry_hints (GTK_WINDOW (widget), widget, &geometry,
128 GDK_HINT_MIN_SIZE|GDK_HINT_MAX_SIZE|GDK_HINT_BASE_SIZE);
129
130 switch (edge)
131 {
132 case GP_PANEL_EDGE_TOP:
133 gtk_window_move (GTK_WINDOW (widget), 0, 0);
134 break;
135 case GP_PANEL_EDGE_BOTTOM:
136 gtk_window_set_gravity (GTK_WINDOW (widget), GDK_GRAVITY_SOUTH_WEST);
137 gtk_window_move (GTK_WINDOW (widget), 0, gdk_screen_height ());
138 break;
139 default:
140 g_return_if_reached ();
141 }
142
143 gtk_window_set_resizable (GTK_WINDOW (widget), FALSE);
144 gtk_window_stick (GTK_WINDOW (widget));
145}
146
147/**
148 * Configure the display
149 *
150 * This code is XLib dependant. Basically, set the struts for the given panel.
151 */
152static gboolean
153gp_panel_configure (GtkWidget *widget,
154 GdkEventConfigure *event,
155 gpointer user_data)
156{
157 GpPanelEdge edge;
158 Display *display;
159 Window window;
160 Atom strut, strut_partial;
161 long data[12];
162 int result;
163
164 if (!GTK_WIDGET_REALIZED (widget))
165 return FALSE;
166
167 edge = (GpPanelEdge) GPOINTER_TO_INT (user_data);
168 display = GDK_DISPLAY ();
169 window = GDK_WINDOW_XID (widget->window);
170 strut = XInternAtom (display, "_NET_WM_STRUT", FALSE);
171 strut_partial = XInternAtom (display, "_NET_WM_STRUT_PARTIAL", FALSE);
172 memset (data, 0, sizeof (data));
173
174 switch (edge)
175 {
176 case GP_PANEL_EDGE_TOP:
177 data[2] = event->height;
178 data[8] = event->x;
179 data[9] = event->width;
180 break;
181 case GP_PANEL_EDGE_BOTTOM:
182 data[3] = event->height;
183 data[10] = event->x;
184 data[11] = event->width;
185 break;
186 default:
187 g_return_val_if_reached (FALSE);
188 }
189
190 XChangeProperty (display, window, strut, XA_CARDINAL, 32,
191 PropModeReplace, (unsigned char *) data, 4);
192 XChangeProperty (display, window, strut_partial, XA_CARDINAL, 32,
193 PropModeReplace, (unsigned char *) data, 12);
194
195 return FALSE;
196}

Archive Download this file

Branches

Tags