1
diff -Nur gdesklets-0.35.3/utils/eggtrayicon.c gdesklets-0.35.3.new/utils/eggtrayicon.c
2
--- gdesklets-0.35.3/utils/eggtrayicon.c 2006-05-09 22:23:56.000000000 +0300
3
+++ gdesklets-0.35.3.new/utils/eggtrayicon.c 2006-05-09 22:29:55.000000000 +0300
5
* Boston, MA 02111-1307, USA.
12
#include "eggtrayicon.h"
14
+#include <gdk/gdkx.h>
15
#include <X11/Xatom.h>
17
+#ifndef EGG_COMPILATION
19
+#define _(x) dgettext (GETTEXT_PACKAGE, x)
27
#define SYSTEM_TRAY_REQUEST_DOCK 0
28
+#define SYSTEM_TRAY_BEGIN_MESSAGE 1
29
+#define SYSTEM_TRAY_CANCEL_MESSAGE 2
31
#define SYSTEM_TRAY_ORIENTATION_HORZ 0
32
#define SYSTEM_TRAY_ORIENTATION_VERT 1
38
+static GtkPlugClass *parent_class = NULL;
40
-G_DEFINE_TYPE (EggTrayIcon, egg_tray_icon, GTK_TYPE_PLUG);
41
+static void egg_tray_icon_init (EggTrayIcon *icon);
42
+static void egg_tray_icon_class_init (EggTrayIconClass *klass);
44
static void egg_tray_icon_get_property (GObject *object,
52
static void egg_tray_icon_realize (GtkWidget *widget);
53
static void egg_tray_icon_unrealize (GtkWidget *widget);
55
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon);
57
+static void egg_tray_icon_add (GtkContainer *container, GtkWidget *widget);
60
+egg_tray_icon_get_type (void)
62
+ static GType our_type = 0;
66
+ static const GTypeInfo our_info =
68
+ sizeof (EggTrayIconClass),
69
+ (GBaseInitFunc) NULL,
70
+ (GBaseFinalizeFunc) NULL,
71
+ (GClassInitFunc) egg_tray_icon_class_init,
72
+ NULL, /* class_finalize */
73
+ NULL, /* class_data */
74
+ sizeof (EggTrayIcon),
75
+ 0, /* n_preallocs */
76
+ (GInstanceInitFunc) egg_tray_icon_init
79
+ our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0);
86
egg_tray_icon_init (EggTrayIcon *icon)
89
icon->orientation = GTK_ORIENTATION_HORIZONTAL;
92
gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
97
GObjectClass *gobject_class = (GObjectClass *)klass;
98
GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
99
+ GtkContainerClass *container_class = (GtkContainerClass *)klass;
101
+ parent_class = g_type_class_peek_parent (klass);
103
gobject_class->get_property = egg_tray_icon_get_property;
105
widget_class->realize = egg_tray_icon_realize;
106
widget_class->unrealize = egg_tray_icon_unrealize;
108
- g_object_class_install_property (gobject_class,
110
- g_param_spec_enum ("orientation",
112
- "The orientation of the tray.",
113
- GTK_TYPE_ORIENTATION,
114
- GTK_ORIENTATION_HORIZONTAL,
115
- G_PARAM_READABLE));
116
+ container_class->add = egg_tray_icon_add;
118
+ g_object_class_install_property (gobject_class,
120
+ g_param_spec_enum ("orientation",
122
+ _("The orientation of the tray."),
123
+ GTK_TYPE_ORIENTATION,
124
+ GTK_ORIENTATION_HORIZONTAL,
125
+ G_PARAM_READABLE));
129
egg_tray_icon_get_property (GObject *object,
137
EggTrayIcon *icon = EGG_TRAY_ICON (object);
139
@@ -101,26 +153,26 @@
152
g_assert (icon->manager_window != None);
155
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
157
gdk_error_trap_push ();
159
result = XGetWindowProperty (xdisplay,
160
- icon->manager_window,
161
- icon->orientation_atom,
162
- 0, G_MAXLONG, FALSE,
164
- &type, &format, &nitems,
165
- &bytes_after, &(prop.prop_ch));
166
+ icon->manager_window,
167
+ icon->orientation_atom,
168
+ 0, G_MAXLONG, FALSE,
170
+ &type, &format, &nitems,
171
+ &bytes_after, &(prop.prop_ch));
172
error = gdk_error_trap_pop ();
174
if (error || result != Success)
175
@@ -131,15 +183,15 @@
176
GtkOrientation orientation;
178
orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ?
179
- GTK_ORIENTATION_HORIZONTAL :
180
- GTK_ORIENTATION_VERTICAL;
181
+ GTK_ORIENTATION_HORIZONTAL :
182
+ GTK_ORIENTATION_VERTICAL;
184
if (icon->orientation != orientation)
186
- icon->orientation = orientation;
188
+ icon->orientation = orientation;
190
- g_object_notify (G_OBJECT (icon), "orientation");
192
+ g_object_notify (G_OBJECT (icon), "orientation");
197
@@ -161,16 +213,16 @@
198
else if (xev->xany.window == icon->manager_window)
200
if (xev->xany.type == PropertyNotify &&
201
- xev->xproperty.atom == icon->orientation_atom)
203
- egg_tray_icon_get_orientation_property (icon);
205
+ xev->xproperty.atom == icon->orientation_atom)
207
+ egg_tray_icon_get_orientation_property (icon);
209
if (xev->xany.type == DestroyNotify)
211
- egg_tray_icon_update_manager_window (icon);
214
+ egg_tray_icon_update_manager_window (icon);
219
return GDK_FILTER_CONTINUE;
222
@@ -194,21 +246,21 @@
224
gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon);
226
- if (GTK_WIDGET_CLASS (egg_tray_icon_parent_class)->unrealize)
227
- (* GTK_WIDGET_CLASS (egg_tray_icon_parent_class)->unrealize) (widget);
228
+ if (GTK_WIDGET_CLASS (parent_class)->unrealize)
229
+ (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
233
egg_tray_icon_send_manager_message (EggTrayIcon *icon,
245
XClientMessageEvent ev;
249
ev.type = ClientMessage;
251
ev.message_type = icon->system_tray_opcode_atom;
252
@@ -220,10 +272,10 @@
253
ev.data.l[4] = data3;
255
display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
258
gdk_error_trap_push ();
260
- icon->manager_window, False, NoEventMask, (XEvent *)&ev);
261
+ icon->manager_window, False, NoEventMask, (XEvent *)&ev);
262
XSync (display, False);
263
gdk_error_trap_pop ();
265
@@ -232,48 +284,48 @@
266
egg_tray_icon_send_dock_request (EggTrayIcon *icon)
268
egg_tray_icon_send_manager_message (icon,
269
- SYSTEM_TRAY_REQUEST_DOCK,
270
- icon->manager_window,
271
- gtk_plug_get_id (GTK_PLUG (icon)),
273
+ SYSTEM_TRAY_REQUEST_DOCK,
274
+ icon->manager_window,
275
+ gtk_plug_get_id (GTK_PLUG (icon)),
280
egg_tray_icon_update_manager_window (EggTrayIcon *icon)
285
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
288
if (icon->manager_window != None)
292
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
293
- icon->manager_window);
295
+ icon->manager_window);
297
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
301
XGrabServer (xdisplay);
304
icon->manager_window = XGetSelectionOwner (xdisplay,
305
- icon->selection_atom);
306
+ icon->selection_atom);
308
if (icon->manager_window != None)
309
XSelectInput (xdisplay,
310
- icon->manager_window, StructureNotifyMask|PropertyChangeMask);
311
+ icon->manager_window, StructureNotifyMask|PropertyChangeMask);
313
XUngrabServer (xdisplay);
317
if (icon->manager_window != None)
321
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
322
- icon->manager_window);
324
+ icon->manager_window);
326
gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
328
/* Send a request that we'd like to dock */
334
+transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
336
+ gdk_window_clear_area (widget->window, event->area.x, event->area.y,
337
+ event->area.width, event->area.height);
342
+make_transparent_again (GtkWidget *widget, GtkStyle *previous_style,
343
+ gpointer user_data)
345
+ gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
349
+make_transparent (GtkWidget *widget, gpointer user_data)
351
+ if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
354
+ gtk_widget_set_app_paintable (widget, TRUE);
355
+ gtk_widget_set_double_buffered (widget, FALSE);
356
+ gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
357
+ g_signal_connect (widget, "expose_event",
358
+ G_CALLBACK (transparent_expose_event), NULL);
359
+ g_signal_connect_after (widget, "style_set",
360
+ G_CALLBACK (make_transparent_again), NULL);
364
egg_tray_icon_realize (GtkWidget *widget)
368
GdkWindow *root_window;
370
- if (GTK_WIDGET_CLASS (egg_tray_icon_parent_class)->realize)
371
- GTK_WIDGET_CLASS (egg_tray_icon_parent_class)->realize (widget);
372
+ if (GTK_WIDGET_CLASS (parent_class)->realize)
373
+ GTK_WIDGET_CLASS (parent_class)->realize (widget);
375
+ make_transparent (widget, NULL);
377
screen = gtk_widget_get_screen (widget);
378
display = gdk_screen_get_display (screen);
379
@@ -302,28 +386,56 @@
381
/* Now see if there's a manager window around */
382
g_snprintf (buffer, sizeof (buffer),
383
- "_NET_SYSTEM_TRAY_S%d",
384
- gdk_screen_get_number (screen));
385
+ "_NET_SYSTEM_TRAY_S%d",
386
+ gdk_screen_get_number (screen));
388
icon->selection_atom = XInternAtom (xdisplay, buffer, False);
391
icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False);
394
icon->system_tray_opcode_atom = XInternAtom (xdisplay,
395
- "_NET_SYSTEM_TRAY_OPCODE",
397
+ "_NET_SYSTEM_TRAY_OPCODE",
400
icon->orientation_atom = XInternAtom (xdisplay,
401
- "_NET_SYSTEM_TRAY_ORIENTATION",
403
+ "_NET_SYSTEM_TRAY_ORIENTATION",
406
egg_tray_icon_update_manager_window (icon);
408
root_window = gdk_screen_get_root_window (screen);
411
/* Add a root window filter so that we get changes on MANAGER */
412
gdk_window_add_filter (root_window,
413
- egg_tray_icon_manager_filter, icon);
414
+ egg_tray_icon_manager_filter, icon);
418
+egg_tray_icon_add (GtkContainer *container, GtkWidget *widget)
420
+ g_signal_connect (widget, "realize",
421
+ G_CALLBACK (make_transparent), NULL);
422
+ GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
426
+egg_tray_icon_new_for_xscreen (Screen *xscreen, const char *name)
428
+ GdkDisplay *display;
431
+ display = gdk_x11_lookup_xdisplay (DisplayOfScreen (xscreen));
432
+ screen = gdk_display_get_screen (display, XScreenNumberOfScreen (xscreen));
434
+ return egg_tray_icon_new_for_screen (screen, name);
438
+egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name)
440
+ g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
442
+ return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL);
447
return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL);
451
+egg_tray_icon_send_message (EggTrayIcon *icon,
453
+ const gchar *message,
458
+ g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0);
459
+ g_return_val_if_fail (timeout >= 0, 0);
460
+ g_return_val_if_fail (message != NULL, 0);
462
+ if (icon->manager_window == None)
466
+ len = strlen (message);
468
+ stamp = icon->stamp++;
470
+ /* Get ready to send the message */
471
+ egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
472
+ (Window)gtk_plug_get_id (GTK_PLUG (icon)),
473
+ timeout, len, stamp);
475
+ /* Now to send the actual message */
476
+ gdk_error_trap_push ();
479
+ XClientMessageEvent ev;
482
+ xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
484
+ ev.type = ClientMessage;
485
+ ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon));
487
+ ev.message_type = XInternAtom (xdisplay,
488
+ "_NET_SYSTEM_TRAY_MESSAGE_DATA", False);
491
+ memcpy (&ev.data, message, 20);
497
+ memcpy (&ev.data, message, len);
501
+ XSendEvent (xdisplay,
502
+ icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev);
503
+ XSync (xdisplay, False);
505
+ gdk_error_trap_pop ();
511
+egg_tray_icon_cancel_message (EggTrayIcon *icon,
514
+ g_return_if_fail (EGG_IS_TRAY_ICON (icon));
515
+ g_return_if_fail (id > 0);
517
+ egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
518
+ (Window)gtk_plug_get_id (GTK_PLUG (icon)),
523
egg_tray_icon_get_orientation (EggTrayIcon *icon)
527
return icon->orientation;
530
diff -Nur gdesklets-0.35.3/utils/eggtrayicon.h gdesklets-0.35.3.new/utils/eggtrayicon.h
531
--- gdesklets-0.35.3/utils/eggtrayicon.h 2006-05-09 22:23:56.000000000 +0300
532
+++ gdesklets-0.35.3.new/utils/eggtrayicon.h 2006-05-09 22:29:35.000000000 +0300
537
-#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ())
538
-#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon))
539
-#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
540
-#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON))
541
-#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON))
542
-#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
544
-typedef struct _EggTrayIcon EggTrayIcon;
545
+#define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ())
546
+#define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon))
547
+#define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
548
+#define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON))
549
+#define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON))
550
+#define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass))
552
+typedef struct _EggTrayIcon EggTrayIcon;
553
typedef struct _EggTrayIconClass EggTrayIconClass;
557
GtkPlug parent_instance;
564
Atom system_tray_opcode_atom;
567
GType egg_tray_icon_get_type (void);
569
+EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen *screen,
570
+ const gchar *name);
572
EggTrayIcon *egg_tray_icon_new (const gchar *name);
574
-GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon);
575
+guint egg_tray_icon_send_message (EggTrayIcon *icon,
577
+ const char *message,
579
+void egg_tray_icon_cancel_message (EggTrayIcon *icon,
582
+GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon);
586
#endif /* __EGG_TRAY_ICON_H__ */