aboutsummaryrefslogtreecommitdiff
path: root/src/core/eggtrayicon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/eggtrayicon.c')
-rw-r--r--src/core/eggtrayicon.c470
1 files changed, 240 insertions, 230 deletions
diff --git a/src/core/eggtrayicon.c b/src/core/eggtrayicon.c
index 6d7a02f7..da2ee0e4 100644
--- a/src/core/eggtrayicon.c
+++ b/src/core/eggtrayicon.c
@@ -55,16 +55,14 @@
55#include <X11/Xatom.h> 55#include <X11/Xatom.h>
56 56
57G_BEGIN_DECLS 57G_BEGIN_DECLS
58
59#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ()) 58#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ())
60#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon)) 59#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon))
61#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) 60#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
62#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON)) 61#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON))
63#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON)) 62#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON))
64#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) 63#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
65 64typedef struct _EggTrayIcon EggTrayIcon;
66typedef struct _EggTrayIcon EggTrayIcon; 65typedef struct _EggTrayIconClass EggTrayIconClass;
67typedef struct _EggTrayIconClass EggTrayIconClass;
68 66
69struct _EggTrayIcon 67struct _EggTrayIcon
70{ 68{
@@ -86,73 +84,74 @@ struct _EggTrayIconClass
86 GtkPlugClass parent_class; 84 GtkPlugClass parent_class;
87}; 85};
88 86
89GType egg_tray_icon_get_type (void); 87GType egg_tray_icon_get_type (void);
90 88
91#if GTK_CHECK_VERSION(2,1,0) 89#if GTK_CHECK_VERSION(2,1,0)
92EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen *screen, 90EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen * screen,
93 const gchar *name); 91 const gchar * name);
94#endif 92#endif
95 93
96EggTrayIcon *egg_tray_icon_new (const gchar *name); 94EggTrayIcon *egg_tray_icon_new (const gchar * name);
97 95
98guint egg_tray_icon_send_message (EggTrayIcon *icon, 96guint egg_tray_icon_send_message (EggTrayIcon * icon,
99 gint timeout, 97 gint timeout,
100 const char *message, 98 const char *message, gint len);
101 gint len); 99void egg_tray_icon_cancel_message (EggTrayIcon * icon, guint id);
102void egg_tray_icon_cancel_message (EggTrayIcon *icon,
103 guint id);
104 100
105GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon); 101GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon * icon);
106 102
107 103
108static gboolean tray_clicked (GtkWidget *trayContextMenu, GdkEvent *event); 104static gboolean tray_clicked (GtkWidget * trayContextMenu, GdkEvent * event);
109static gboolean on_tray_quit_activate(GtkWidget *widget, GdkEvent *event, gpointer data); 105static gboolean on_tray_quit_activate (GtkWidget * widget, GdkEvent * event,
110 106 gpointer data);
111G_END_DECLS
112 107
108G_END_DECLS
113#define SYSTEM_TRAY_REQUEST_DOCK 0 109#define SYSTEM_TRAY_REQUEST_DOCK 0
114#define SYSTEM_TRAY_BEGIN_MESSAGE 1 110#define SYSTEM_TRAY_BEGIN_MESSAGE 1
115#define SYSTEM_TRAY_CANCEL_MESSAGE 2 111#define SYSTEM_TRAY_CANCEL_MESSAGE 2
116
117#define SYSTEM_TRAY_ORIENTATION_HORZ 0 112#define SYSTEM_TRAY_ORIENTATION_HORZ 0
118#define SYSTEM_TRAY_ORIENTATION_VERT 1 113#define SYSTEM_TRAY_ORIENTATION_VERT 1
119 114 enum
120enum { 115{
121 PROP_0, 116 PROP_0,
122 PROP_ORIENTATION 117 PROP_ORIENTATION
123}; 118};
124 119
125static GtkPlugClass *parent_class = NULL; 120static GtkPlugClass *parent_class = NULL;
126 121
127static void egg_tray_icon_init (EggTrayIcon *icon); 122static void egg_tray_icon_init (EggTrayIcon * icon);
128static void egg_tray_icon_class_init (EggTrayIconClass *klass); 123static void egg_tray_icon_class_init (EggTrayIconClass * klass);
129 124
130static void egg_tray_icon_get_property (GObject *object, 125static void egg_tray_icon_get_property (GObject * object,
131 guint prop_id, 126 guint prop_id,
132 GValue *value, 127 GValue * value, GParamSpec * pspec);
133 GParamSpec *pspec);
134 128
135static void egg_tray_icon_realize (GtkWidget *widget); 129static void egg_tray_icon_realize (GtkWidget * widget);
136static void egg_tray_icon_unrealize (GtkWidget *widget); 130static void egg_tray_icon_unrealize (GtkWidget * widget);
137 131
138static void egg_tray_icon_update_manager_window (EggTrayIcon *icon, 132static void egg_tray_icon_update_manager_window (EggTrayIcon * icon,
139 gboolean dock_if_realized); 133 gboolean dock_if_realized);
140static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon); 134static void egg_tray_icon_manager_window_destroyed (EggTrayIcon * icon);
141 135
142static Display * getDisplay(GtkWidget * w) { 136static Display *
137getDisplay (GtkWidget * w)
138{
143#if GTK_CHECK_VERSION(2,1,0) 139#if GTK_CHECK_VERSION(2,1,0)
144 return GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (w)); 140 return GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (w));
145#else 141#else
146 return gdk_display; 142 return gdk_display;
147#endif 143#endif
148} 144}
149 145
150static GdkWindow * getWindow(EggTrayIcon * icon) { 146static GdkWindow *
147getWindow (EggTrayIcon * icon)
148{
151#if GTK_CHECK_VERSION(2,1,0) 149#if GTK_CHECK_VERSION(2,1,0)
152 return gdk_window_lookup_for_display (gtk_widget_get_display(GTK_WIDGET(icon)), 150 return
153 icon->manager_window); 151 gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
152 icon->manager_window);
154#else 153#else
155 return gdk_window_lookup(icon->manager_window); 154 return gdk_window_lookup (icon->manager_window);
156#endif 155#endif
157} 156}
158 157
@@ -163,30 +162,32 @@ egg_tray_icon_get_type (void)
163 162
164 if (our_type == 0) 163 if (our_type == 0)
165 { 164 {
166 our_type = g_type_from_name("EggTrayIcon"); 165 our_type = g_type_from_name ("EggTrayIcon");
167 166
168 if (our_type == 0) 167 if (our_type == 0)
169 { 168 {
170 static const GTypeInfo our_info = 169 static const GTypeInfo our_info = {
171 { 170 sizeof (EggTrayIconClass),
172 sizeof (EggTrayIconClass), 171 (GBaseInitFunc) NULL,
173 (GBaseInitFunc) NULL, 172 (GBaseFinalizeFunc) NULL,
174 (GBaseFinalizeFunc) NULL, 173 (GClassInitFunc) egg_tray_icon_class_init,
175 (GClassInitFunc) egg_tray_icon_class_init, 174 NULL, /* class_finalize */
176 NULL, /* class_finalize */ 175 NULL, /* class_data */
177 NULL, /* class_data */ 176 sizeof (EggTrayIcon),
178 sizeof (EggTrayIcon), 177 0, /* n_preallocs */
179 0, /* n_preallocs */ 178 (GInstanceInitFunc) egg_tray_icon_init,
180 (GInstanceInitFunc) egg_tray_icon_init, 179 NULL /* value_table */
181 NULL /* value_table */ 180 };
182 }; 181
183 182 our_type =
184 our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0); 183 g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info,
184 0);
185 } 185 }
186 else if (parent_class == NULL) 186 else if (parent_class == NULL)
187 { 187 {
188 /* we're reheating the old class from a previous instance - engage ugly hack =( */ 188 /* we're reheating the old class from a previous instance - engage ugly hack =( */
189 egg_tray_icon_class_init((EggTrayIconClass *)g_type_class_peek(our_type)); 189 egg_tray_icon_class_init ((EggTrayIconClass *)
190 g_type_class_peek (our_type));
190 } 191 }
191 } 192 }
192 193
@@ -194,7 +195,7 @@ egg_tray_icon_get_type (void)
194} 195}
195 196
196static void 197static void
197egg_tray_icon_init (EggTrayIcon *icon) 198egg_tray_icon_init (EggTrayIcon * icon)
198{ 199{
199 icon->stamp = 1; 200 icon->stamp = 1;
200 icon->orientation = GTK_ORIENTATION_HORIZONTAL; 201 icon->orientation = GTK_ORIENTATION_HORIZONTAL;
@@ -203,33 +204,32 @@ egg_tray_icon_init (EggTrayIcon *icon)
203} 204}
204 205
205static void 206static void
206egg_tray_icon_class_init (EggTrayIconClass *klass) 207egg_tray_icon_class_init (EggTrayIconClass * klass)
207{ 208{
208 GObjectClass *gobject_class = (GObjectClass *)klass; 209 GObjectClass *gobject_class = (GObjectClass *) klass;
209 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; 210 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
210 211
211 parent_class = g_type_class_peek_parent (klass); 212 parent_class = g_type_class_peek_parent (klass);
212 213
213 gobject_class->get_property = egg_tray_icon_get_property; 214 gobject_class->get_property = egg_tray_icon_get_property;
214 215
215 widget_class->realize = egg_tray_icon_realize; 216 widget_class->realize = egg_tray_icon_realize;
216 widget_class->unrealize = egg_tray_icon_unrealize; 217 widget_class->unrealize = egg_tray_icon_unrealize;
217 218
218 g_object_class_install_property (gobject_class, 219 g_object_class_install_property (gobject_class,
219 PROP_ORIENTATION, 220 PROP_ORIENTATION,
220 g_param_spec_enum ("orientation", 221 g_param_spec_enum ("orientation",
221 _("Orientation"), 222 _("Orientation"),
222 _("The orientation of the tray."), 223 _
223 GTK_TYPE_ORIENTATION, 224 ("The orientation of the tray."),
224 GTK_ORIENTATION_HORIZONTAL, 225 GTK_TYPE_ORIENTATION,
225 G_PARAM_READABLE)); 226 GTK_ORIENTATION_HORIZONTAL,
227 G_PARAM_READABLE));
226} 228}
227 229
228static void 230static void
229egg_tray_icon_get_property (GObject *object, 231egg_tray_icon_get_property (GObject * object,
230 guint prop_id, 232 guint prop_id, GValue * value, GParamSpec * pspec)
231 GValue *value,
232 GParamSpec *pspec)
233{ 233{
234 EggTrayIcon *icon = EGG_TRAY_ICON (object); 234 EggTrayIcon *icon = EGG_TRAY_ICON (object);
235 235
@@ -245,32 +245,35 @@ egg_tray_icon_get_property (GObject *object,
245} 245}
246 246
247static void 247static void
248egg_tray_icon_get_orientation_property (EggTrayIcon *icon) 248egg_tray_icon_get_orientation_property (EggTrayIcon * icon)
249{ 249{
250 Display *xdisplay; 250 Display *xdisplay;
251 Atom type; 251 Atom type;
252 int format; 252 int format;
253 union { 253 union
254 gulong *prop; 254 {
255 guchar *prop_ch; 255 gulong *prop;
256 } prop = { NULL }; 256 guchar *prop_ch;
257 } prop =
258 {
259 NULL};
257 gulong nitems; 260 gulong nitems;
258 gulong bytes_after; 261 gulong bytes_after;
259 int error, result; 262 int error, result;
260 263
261 g_return_if_fail(icon->manager_window != None); 264 g_return_if_fail (icon->manager_window != None);
262 265
263 xdisplay = getDisplay(GTK_WIDGET (icon)); 266 xdisplay = getDisplay (GTK_WIDGET (icon));
264 267
265 gdk_error_trap_push (); 268 gdk_error_trap_push ();
266 type = None; 269 type = None;
267 result = XGetWindowProperty (xdisplay, 270 result = XGetWindowProperty (xdisplay,
268 icon->manager_window, 271 icon->manager_window,
269 icon->orientation_atom, 272 icon->orientation_atom,
270 0, G_MAXLONG, FALSE, 273 0, G_MAXLONG, FALSE,
271 XA_CARDINAL, 274 XA_CARDINAL,
272 &type, &format, &nitems, 275 &type, &format, &nitems,
273 &bytes_after, &(prop.prop_ch)); 276 &bytes_after, &(prop.prop_ch));
274 error = gdk_error_trap_pop (); 277 error = gdk_error_trap_pop ();
275 278
276 if (error || result != Success) 279 if (error || result != Success)
@@ -280,16 +283,15 @@ egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
280 { 283 {
281 GtkOrientation orientation; 284 GtkOrientation orientation;
282 285
283 orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ? 286 orientation = (prop.prop[0] == SYSTEM_TRAY_ORIENTATION_HORZ) ?
284 GTK_ORIENTATION_HORIZONTAL : 287 GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
285 GTK_ORIENTATION_VERTICAL;
286 288
287 if (icon->orientation != orientation) 289 if (icon->orientation != orientation)
288 { 290 {
289 icon->orientation = orientation; 291 icon->orientation = orientation;
290 292
291 g_object_notify (G_OBJECT (icon), "orientation"); 293 g_object_notify (G_OBJECT (icon), "orientation");
292 } 294 }
293 } 295 }
294 296
295 if (prop.prop) 297 if (prop.prop)
@@ -297,10 +299,11 @@ egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
297} 299}
298 300
299static GdkFilterReturn 301static GdkFilterReturn
300egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) 302egg_tray_icon_manager_filter (GdkXEvent * xevent, GdkEvent * event,
303 gpointer user_data)
301{ 304{
302 EggTrayIcon *icon = user_data; 305 EggTrayIcon *icon = user_data;
303 XEvent *xev = (XEvent *)xevent; 306 XEvent *xev = (XEvent *) xevent;
304 307
305 if (xev->xany.type == ClientMessage && 308 if (xev->xany.type == ClientMessage &&
306 xev->xclient.message_type == icon->manager_atom && 309 xev->xclient.message_type == icon->manager_atom &&
@@ -311,21 +314,21 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
311 else if (xev->xany.window == icon->manager_window) 314 else if (xev->xany.window == icon->manager_window)
312 { 315 {
313 if (xev->xany.type == PropertyNotify && 316 if (xev->xany.type == PropertyNotify &&
314 xev->xproperty.atom == icon->orientation_atom) 317 xev->xproperty.atom == icon->orientation_atom)
315 { 318 {
316 egg_tray_icon_get_orientation_property (icon); 319 egg_tray_icon_get_orientation_property (icon);
317 } 320 }
318 if (xev->xany.type == DestroyNotify) 321 if (xev->xany.type == DestroyNotify)
319 { 322 {
320 egg_tray_icon_manager_window_destroyed (icon); 323 egg_tray_icon_manager_window_destroyed (icon);
321 } 324 }
322 } 325 }
323 326
324 return GDK_FILTER_CONTINUE; 327 return GDK_FILTER_CONTINUE;
325} 328}
326 329
327static void 330static void
328egg_tray_icon_unrealize (GtkWidget *widget) 331egg_tray_icon_unrealize (GtkWidget * widget)
329{ 332{
330 EggTrayIcon *icon = EGG_TRAY_ICON (widget); 333 EggTrayIcon *icon = EGG_TRAY_ICON (widget);
331 GdkWindow *root_window; 334 GdkWindow *root_window;
@@ -334,7 +337,7 @@ egg_tray_icon_unrealize (GtkWidget *widget)
334 { 337 {
335 GdkWindow *gdkwin; 338 GdkWindow *gdkwin;
336 339
337 gdkwin = getWindow(icon); 340 gdkwin = getWindow (icon);
338 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); 341 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
339 } 342 }
340 343
@@ -347,16 +350,14 @@ egg_tray_icon_unrealize (GtkWidget *widget)
347 gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon); 350 gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon);
348 351
349 if (GTK_WIDGET_CLASS (parent_class)->unrealize) 352 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
350 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); 353 (*GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
351} 354}
352 355
353static void 356static void
354egg_tray_icon_send_manager_message (EggTrayIcon *icon, 357egg_tray_icon_send_manager_message (EggTrayIcon * icon,
355 long message, 358 long message,
356 Window window, 359 Window window,
357 long data1, 360 long data1, long data2, long data3)
358 long data2,
359 long data3)
360{ 361{
361 XClientMessageEvent ev; 362 XClientMessageEvent ev;
362 Display *display; 363 Display *display;
@@ -371,43 +372,43 @@ egg_tray_icon_send_manager_message (EggTrayIcon *icon,
371 ev.data.l[3] = data2; 372 ev.data.l[3] = data2;
372 ev.data.l[4] = data3; 373 ev.data.l[4] = data3;
373 374
374 display = getDisplay(GTK_WIDGET (icon)); 375 display = getDisplay (GTK_WIDGET (icon));
375 376
376 gdk_error_trap_push (); 377 gdk_error_trap_push ();
377 XSendEvent (display, 378 XSendEvent (display,
378 icon->manager_window, False, NoEventMask, (XEvent *)&ev); 379 icon->manager_window, False, NoEventMask, (XEvent *) & ev);
379 XSync (display, False); 380 XSync (display, False);
380 gdk_error_trap_pop (); 381 gdk_error_trap_pop ();
381} 382}
382 383
383static void 384static void
384egg_tray_icon_send_dock_request (EggTrayIcon *icon) 385egg_tray_icon_send_dock_request (EggTrayIcon * icon)
385{ 386{
386 egg_tray_icon_send_manager_message (icon, 387 egg_tray_icon_send_manager_message (icon,
387 SYSTEM_TRAY_REQUEST_DOCK, 388 SYSTEM_TRAY_REQUEST_DOCK,
388 icon->manager_window, 389 icon->manager_window,
389 gtk_plug_get_id (GTK_PLUG (icon)), 390 gtk_plug_get_id (GTK_PLUG (icon)),
390 0, 0); 391 0, 0);
391} 392}
392 393
393static void 394static void
394egg_tray_icon_update_manager_window (EggTrayIcon *icon, 395egg_tray_icon_update_manager_window (EggTrayIcon * icon,
395 gboolean dock_if_realized) 396 gboolean dock_if_realized)
396{ 397{
397 Display *xdisplay; 398 Display *xdisplay;
398 399
399 if (icon->manager_window != None) 400 if (icon->manager_window != None)
400 return; 401 return;
401 402
402 xdisplay = getDisplay(GTK_WIDGET (icon)); 403 xdisplay = getDisplay (GTK_WIDGET (icon));
403 XGrabServer (xdisplay); 404 XGrabServer (xdisplay);
404 405
405 icon->manager_window = XGetSelectionOwner (xdisplay, 406 icon->manager_window = XGetSelectionOwner (xdisplay, icon->selection_atom);
406 icon->selection_atom);
407 407
408 if (icon->manager_window != None) 408 if (icon->manager_window != None)
409 XSelectInput (xdisplay, 409 XSelectInput (xdisplay,
410 icon->manager_window, StructureNotifyMask|PropertyChangeMask); 410 icon->manager_window,
411 StructureNotifyMask | PropertyChangeMask);
411 412
412 XUngrabServer (xdisplay); 413 XUngrabServer (xdisplay);
413 XFlush (xdisplay); 414 XFlush (xdisplay);
@@ -416,24 +417,24 @@ egg_tray_icon_update_manager_window (EggTrayIcon *icon,
416 { 417 {
417 GdkWindow *gdkwin; 418 GdkWindow *gdkwin;
418 419
419 gdkwin = getWindow(icon); 420 gdkwin = getWindow (icon);
420 gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon); 421 gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
421 422
422 if (dock_if_realized && GTK_WIDGET_REALIZED (icon)) 423 if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
423 egg_tray_icon_send_dock_request (icon); 424 egg_tray_icon_send_dock_request (icon);
424 425
425 egg_tray_icon_get_orientation_property (icon); 426 egg_tray_icon_get_orientation_property (icon);
426 } 427 }
427} 428}
428 429
429static void 430static void
430egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon) 431egg_tray_icon_manager_window_destroyed (EggTrayIcon * icon)
431{ 432{
432 GdkWindow *gdkwin; 433 GdkWindow *gdkwin;
433 434
434 g_return_if_fail (icon->manager_window != None); 435 g_return_if_fail (icon->manager_window != None);
435 436
436 gdkwin = getWindow(icon); 437 gdkwin = getWindow (icon);
437 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); 438 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
438 439
439 icon->manager_window = None; 440 icon->manager_window = None;
@@ -442,7 +443,7 @@ egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon)
442} 443}
443 444
444static void 445static void
445egg_tray_icon_realize (GtkWidget *widget) 446egg_tray_icon_realize (GtkWidget * widget)
446{ 447{
447 EggTrayIcon *icon = EGG_TRAY_ICON (widget); 448 EggTrayIcon *icon = EGG_TRAY_ICON (widget);
448 gint screen; 449 gint screen;
@@ -462,21 +463,19 @@ egg_tray_icon_realize (GtkWidget *widget)
462#endif 463#endif
463 464
464 /* Now see if there's a manager window around */ 465 /* Now see if there's a manager window around */
465 g_snprintf (buffer, sizeof (buffer), 466 g_snprintf (buffer, sizeof (buffer), "_NET_SYSTEM_TRAY_S%d", screen);
466 "_NET_SYSTEM_TRAY_S%d",
467 screen);
468 467
469 icon->selection_atom = XInternAtom (xdisplay, buffer, False); 468 icon->selection_atom = XInternAtom (xdisplay, buffer, False);
470 469
471 icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False); 470 icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False);
472 471
473 icon->system_tray_opcode_atom = XInternAtom (xdisplay, 472 icon->system_tray_opcode_atom = XInternAtom (xdisplay,
474 "_NET_SYSTEM_TRAY_OPCODE", 473 "_NET_SYSTEM_TRAY_OPCODE",
475 False); 474 False);
476 475
477 icon->orientation_atom = XInternAtom (xdisplay, 476 icon->orientation_atom = XInternAtom (xdisplay,
478 "_NET_SYSTEM_TRAY_ORIENTATION", 477 "_NET_SYSTEM_TRAY_ORIENTATION",
479 False); 478 False);
480 479
481 egg_tray_icon_update_manager_window (icon, FALSE); 480 egg_tray_icon_update_manager_window (icon, FALSE);
482 egg_tray_icon_send_dock_request (icon); 481 egg_tray_icon_send_dock_request (icon);
@@ -488,38 +487,36 @@ egg_tray_icon_realize (GtkWidget *widget)
488#endif 487#endif
489 488
490 /* Add a root window filter so that we get changes on MANAGER */ 489 /* Add a root window filter so that we get changes on MANAGER */
491 gdk_window_add_filter (root_window, 490 gdk_window_add_filter (root_window, egg_tray_icon_manager_filter, icon);
492 egg_tray_icon_manager_filter, icon);
493} 491}
494 492
495#if GTK_CHECK_VERSION(2,1,0) 493#if GTK_CHECK_VERSION(2,1,0)
496EggTrayIcon * 494EggTrayIcon *
497egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name) 495egg_tray_icon_new_for_screen (GdkScreen * screen, const char *name)
498{ 496{
499 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); 497 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
500 498
501 return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL); 499 return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name,
500 NULL);
502} 501}
503#endif 502#endif
504 503
505EggTrayIcon* 504EggTrayIcon *
506egg_tray_icon_new (const gchar *name) 505egg_tray_icon_new (const gchar * name)
507{ 506{
508 return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL); 507 return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL);
509} 508}
510 509
511guint 510guint
512egg_tray_icon_send_message (EggTrayIcon *icon, 511egg_tray_icon_send_message (EggTrayIcon * icon,
513 gint timeout, 512 gint timeout, const gchar * message, gint len)
514 const gchar *message,
515 gint len)
516{ 513{
517 guint stamp; 514 guint stamp;
518 515
519 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); 516 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0);
520 g_return_val_if_fail (timeout >= 0, 0); 517 g_return_val_if_fail (timeout >= 0, 0);
521 g_return_val_if_fail (message != NULL, 0); 518 g_return_val_if_fail (message != NULL, 0);
522 519
523 if (icon->manager_window == None) 520 if (icon->manager_window == None)
524 return 0; 521 return 0;
525 522
@@ -530,8 +527,9 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
530 527
531 /* Get ready to send the message */ 528 /* Get ready to send the message */
532 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, 529 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
533 (Window)gtk_plug_get_id (GTK_PLUG (icon)), 530 (Window)
534 timeout, len, stamp); 531 gtk_plug_get_id (GTK_PLUG (icon)),
532 timeout, len, stamp);
535 533
536 /* Now to send the actual message */ 534 /* Now to send the actual message */
537 gdk_error_trap_push (); 535 gdk_error_trap_push ();
@@ -540,27 +538,28 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
540 XClientMessageEvent ev; 538 XClientMessageEvent ev;
541 Display *xdisplay; 539 Display *xdisplay;
542 540
543 xdisplay = getDisplay(GTK_WIDGET (icon)); 541 xdisplay = getDisplay (GTK_WIDGET (icon));
544 542
545 ev.type = ClientMessage; 543 ev.type = ClientMessage;
546 ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon)); 544 ev.window = (Window) gtk_plug_get_id (GTK_PLUG (icon));
547 ev.format = 8; 545 ev.format = 8;
548 ev.message_type = XInternAtom (xdisplay, 546 ev.message_type = XInternAtom (xdisplay,
549 "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); 547 "_NET_SYSTEM_TRAY_MESSAGE_DATA", False);
550 if (len > 20) 548 if (len > 20)
551 { 549 {
552 memcpy (&ev.data, message, 20); 550 memcpy (&ev.data, message, 20);
553 len -= 20; 551 len -= 20;
554 message += 20; 552 message += 20;
555 } 553 }
556 else 554 else
557 { 555 {
558 memcpy (&ev.data, message, len); 556 memcpy (&ev.data, message, len);
559 len = 0; 557 len = 0;
560 } 558 }
561 559
562 XSendEvent (xdisplay, 560 XSendEvent (xdisplay,
563 icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); 561 icon->manager_window, False, StructureNotifyMask,
562 (XEvent *) & ev);
564 XSync (xdisplay, False); 563 XSync (xdisplay, False);
565 } 564 }
566 gdk_error_trap_pop (); 565 gdk_error_trap_pop ();
@@ -569,19 +568,19 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
569} 568}
570 569
571void 570void
572egg_tray_icon_cancel_message (EggTrayIcon *icon, 571egg_tray_icon_cancel_message (EggTrayIcon * icon, guint id)
573 guint id)
574{ 572{
575 g_return_if_fail (EGG_IS_TRAY_ICON (icon)); 573 g_return_if_fail (EGG_IS_TRAY_ICON (icon));
576 g_return_if_fail (id > 0); 574 g_return_if_fail (id > 0);
577 575
578 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE, 576 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
579 (Window)gtk_plug_get_id (GTK_PLUG (icon)), 577 (Window)
580 id, 0, 0); 578 gtk_plug_get_id (GTK_PLUG (icon)), id,
579 0, 0);
581} 580}
582 581
583GtkOrientation 582GtkOrientation
584egg_tray_icon_get_orientation (EggTrayIcon *icon) 583egg_tray_icon_get_orientation (EggTrayIcon * icon)
585{ 584{
586 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL); 585 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL);
587 586
@@ -590,75 +589,86 @@ egg_tray_icon_get_orientation (EggTrayIcon *icon)
590 589
591 590
592/* Callback for the "Quit" element on the tray icon menu */ 591/* Callback for the "Quit" element on the tray icon menu */
593static gboolean on_tray_quit_activate(GtkWidget *widget, GdkEvent *event, gpointer data) { 592static gboolean
594 gnunet_gtk_main_quit(); 593on_tray_quit_activate (GtkWidget * widget, GdkEvent * event, gpointer data)
595 return TRUE; 594{
595 gnunet_gtk_main_quit ();
596 return TRUE;
596} 597}
597 598
598/* Function activated when the user clicks the tray icon */ 599/* Function activated when the user clicks the tray icon */
599static gboolean tray_clicked(GtkWidget *widget, GdkEvent *event) { 600static gboolean
600 if(event->type == GDK_BUTTON_PRESS) { 601tray_clicked (GtkWidget * widget, GdkEvent * event)
601 GdkEventButton *event_button; 602{
602 event_button = (GdkEventButton *) event; 603 if (event->type == GDK_BUTTON_PRESS)
603 if(event_button->button == 1) { 604 {
604 GtkWidget *root; 605 GdkEventButton *event_button;
605 root = glade_xml_get_widget(getMainXML(), 606 event_button = (GdkEventButton *) event;
606 "mainWindow"); 607 if (event_button->button == 1)
607 GdkWindowState main_window_state; 608 {
608 if (gtk_window_is_active (GTK_WINDOW(root))) 609 GtkWidget *root;
609 gtk_widget_hide (root); 610 root = glade_xml_get_widget (getMainXML (), "mainWindow");
610 else 611 GdkWindowState main_window_state;
611 gtk_window_present (GTK_WINDOW(root)); 612 if (gtk_window_is_active (GTK_WINDOW (root)))
612 main_window_state = getMainWindowState(); 613 gtk_widget_hide (root);
613 if(main_window_state & GDK_WINDOW_STATE_MAXIMIZED) 614 else
614 gtk_window_maximize (GTK_WINDOW(root)); 615 gtk_window_present (GTK_WINDOW (root));
615 return TRUE; 616 main_window_state = getMainWindowState ();
616 } 617 if (main_window_state & GDK_WINDOW_STATE_MAXIMIZED)
617 else if(event_button->button == 3) { 618 gtk_window_maximize (GTK_WINDOW (root));
618 GtkMenu *trayContextMenu; 619 return TRUE;
619 trayContextMenu = GTK_MENU (widget); 620 }
620 g_return_val_if_fail (GTK_IS_MENU (trayContextMenu), FALSE); 621 else if (event_button->button == 3)
621 gtk_menu_popup(trayContextMenu, NULL, NULL, NULL, NULL, 622 {
622 event_button->button, event_button->time); 623 GtkMenu *trayContextMenu;
623 return TRUE; 624 trayContextMenu = GTK_MENU (widget);
625 g_return_val_if_fail (GTK_IS_MENU (trayContextMenu), FALSE);
626 gtk_menu_popup (trayContextMenu, NULL, NULL, NULL, NULL,
627 event_button->button, event_button->time);
628 return TRUE;
629 }
624 } 630 }
625 }
626 return FALSE; 631 return FALSE;
627} 632}
628 633
629/* Initiate the system tray icon */ 634/* Initiate the system tray icon */
630void initTrayIcon() { 635void
631 static EggTrayIcon *tray_icon; 636initTrayIcon ()
632 static GtkWidget *tray_icon_image; 637{
633 static GtkTooltips *tray_icon_tooltip; 638 static EggTrayIcon *tray_icon;
634 GtkWidget *eventbox, *trayContextMenu, *tray_quit; 639 static GtkWidget *tray_icon_image;
635 GdkPixbuf *pixbuf; 640 static GtkTooltips *tray_icon_tooltip;
636 GladeXML *trayContextMenuXML; 641 GtkWidget *eventbox, *trayContextMenu, *tray_quit;
637 char * instDir; 642 GdkPixbuf *pixbuf;
638 char * iconPath; 643 GladeXML *trayContextMenuXML;
639 644 char *instDir;
640 trayContextMenuXML = glade_xml_new (getGladeFileName(), "trayContextMenu", PACKAGE_NAME); 645 char *iconPath;
641 trayContextMenu = glade_xml_get_widget (trayContextMenuXML, "trayContextMenu"); 646
642 tray_quit = glade_xml_get_widget (trayContextMenuXML, "tray_quit"); 647 trayContextMenuXML =
643 648 glade_xml_new (getGladeFileName (), "trayContextMenu", PACKAGE_NAME);
644 tray_icon = egg_tray_icon_new (_("GNU's p2p network")); 649 trayContextMenu =
645 instDir = os_get_installation_path(IPK_DATADIR); 650 glade_xml_get_widget (trayContextMenuXML, "trayContextMenu");
646 iconPath = MALLOC(strlen(instDir) + 40); 651 tray_quit = glade_xml_get_widget (trayContextMenuXML, "tray_quit");
647 strcpy(iconPath, instDir); 652
648 strcat(iconPath, "/../gnunet-gtk/gnunet-gtk-tray.png"); 653 tray_icon = egg_tray_icon_new (_("GNU's p2p network"));
649 FREE(instDir); 654 instDir = os_get_installation_path (IPK_DATADIR);
650 pixbuf = gdk_pixbuf_new_from_file (iconPath, NULL); 655 iconPath = MALLOC (strlen (instDir) + 40);
651 FREE(iconPath); 656 strcpy (iconPath, instDir);
652 tray_icon_image = gtk_image_new_from_pixbuf (pixbuf); 657 strcat (iconPath, "/../gnunet-gtk/gnunet-gtk-tray.png");
653 eventbox = gtk_event_box_new (); 658 FREE (instDir);
654 gtk_container_add (GTK_CONTAINER (eventbox), tray_icon_image); 659 pixbuf = gdk_pixbuf_new_from_file (iconPath, NULL);
655 gtk_container_add (GTK_CONTAINER (tray_icon), eventbox); 660 FREE (iconPath);
656 g_signal_connect(G_OBJECT(tray_quit), "activate", G_CALLBACK(on_tray_quit_activate), NULL); 661 tray_icon_image = gtk_image_new_from_pixbuf (pixbuf);
657 g_signal_connect_swapped (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (tray_clicked), trayContextMenu); 662 eventbox = gtk_event_box_new ();
658 tray_icon_tooltip = gtk_tooltips_new (); 663 gtk_container_add (GTK_CONTAINER (eventbox), tray_icon_image);
659 gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon), _("GNU's p2p network"), NULL); 664 gtk_container_add (GTK_CONTAINER (tray_icon), eventbox);
660 gtk_widget_show (eventbox); 665 g_signal_connect (G_OBJECT (tray_quit), "activate",
661 gtk_widget_show_all (GTK_WIDGET (tray_icon)); 666 G_CALLBACK (on_tray_quit_activate), NULL);
667 g_signal_connect_swapped (G_OBJECT (eventbox), "button_press_event",
668 G_CALLBACK (tray_clicked), trayContextMenu);
669 tray_icon_tooltip = gtk_tooltips_new ();
670 gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon),
671 _("GNU's p2p network"), NULL);
672 gtk_widget_show (eventbox);
673 gtk_widget_show_all (GTK_WIDGET (tray_icon));
662} 674}
663
664