]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/eggtrayicon.c
Add wxTranslations::GetTranslatedString().
[wxWidgets.git] / src / gtk / eggtrayicon.c
CommitLineData
33d4eef0
VS
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/* eggtrayicon.c
0a949d78
FM
3 * Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21/*
22
526954c5 23Permission to use this file under wxWindows licence given by
0a949d78
FM
24copyright holder:
25--------
26From andersca@gnu.org Tue Dec 9 13:01:56 2003
0fef6b7a
VS
27Return-path: <andersca@gnu.org>
28Envelope-to: vasek@localhost
29Delivery-date: Tue, 09 Dec 2003 13:04:35 +0100
30Received: from localhost
31 ([127.0.0.1] helo=amavis ident=amavis)
32 by armitage with esmtp (Exim 3.35 #1)
33 id 1ATgbS-0001Gs-00
34 for vasek@localhost; Tue, 09 Dec 2003 13:04:35 +0100
35Received: from armitage ([127.0.0.1])
36 by amavis (armitage [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
37 id 04227-09 for <vasek@localhost>;
38 Tue, 9 Dec 2003 13:04:11 +0100 (CET)
39Received: from localhost ([127.0.0.1] ident=fetchmail)
40 by armitage with esmtp (Exim 3.35 #1)
41 id 1ATgb5-0001GY-00
42 for vasek@localhost; Tue, 09 Dec 2003 13:04:11 +0100
43Delivered-To: alias-email-slavikvaclav@seznam.cz
44Received: from pop3.seznam.cz [212.80.76.45]
45 by localhost with POP3 (fetchmail-5.9.11)
46 for vasek@localhost (single-drop); Tue, 09 Dec 2003 13:04:11 +0100 (CET)
47Received: (qmail 9861 invoked from network); 9 Dec 2003 12:02:17 -0000
48Received: from unknown (HELO maxipes.logix.cz) (81.0.234.97)
49 by buster.go.seznam.cz with SMTP; 9 Dec 2003 12:02:17 -0000
50Received: by maxipes.logix.cz (Postfix, from userid 604)
51 id 37E6D29A51; Tue, 9 Dec 2003 13:02:16 +0100 (CET)
52X-Original-To: vaclav.slavik@matfyz.cz
53Received: from mail.csbnet.se (glutus.csbnet.se [193.11.248.2])
54 by maxipes.logix.cz (Postfix) with ESMTP id 90D6A29A51
55 for <vaclav.slavik@matfyz.cz>; Tue, 9 Dec 2003 13:02:15 +0100 (CET)
56Received: by mail.csbnet.se (Postfix, from userid 8)
57 id 7AA7F10A6D7; Tue, 9 Dec 2003 13:02:14 +0100 (CET)
58Received: from carbon.csbnet.se (carbon.csbnet.se [193.11.248.180])
59 by mail.csbnet.se (Postfix) with ESMTP id A190F10A71D
60 for <vaclav.slavik@matfyz.cz>; Tue, 9 Dec 2003 13:01:56 +0100 (CET)
0a949d78
FM
61Subject: Re: eggtrayicon.{c,h} licensing
62From: Anders Carlsson <andersca@gnu.org>
63To: Vaclav Slavik <vaclav.slavik@matfyz.cz>
0fef6b7a
VS
64In-Reply-To: <200312091142.54542.vaclav.slavik@matfyz.cz>
65References: <200312091142.54542.vaclav.slavik@matfyz.cz>
66Content-Type: text/plain
67Message-Id: <1070971316.30989.0.camel@carbon.csbnet.se>
68Mime-Version: 1.0
69X-Mailer: Ximian Evolution 1.5
70Date: Tue, 09 Dec 2003 13:01:56 +0100
71Content-Transfer-Encoding: 7bit
72X-Scanned-By: CLAM (openantivirus DB) antivirus scanner at mail.csbnet.se
73X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at armitage
74X-Spam-Status: No, hits=-4.9 tagged_above=-999.0 required=6.3 tests=BAYES_00
75X-Spam-Level:
76Status: R
77X-Status: N
78X-KMail-EncryptionState:
79X-KMail-SignatureState:
0a949d78
FM
80
81On tis, 2003-12-09 at 11:42 +0100, Vaclav Slavik wrote:
82> Hi,
0fef6b7a 83>
0a949d78
FM
84> I'm working on the wxWindows cross-platform GUI toolkit
85> (http://www.wxwindows.org) which uses GTK+ and it would save me a lot
86> of time if I could use your eggtrayicon code to implement tray icons
87> on X11. Unfortunately I can't use it right now because it is not part
88> of any library we could depend on (as we do depend on GTK+) and would
89> have to be included in our sources and it is under the LGPL license.
90> The problem is that wxWindows' license is more permissive (see
91> http://www.opensource.org/licenses/wxwindows.php for details) and so
92> I can't take your code and put it under wxWindows License. And I
93> can't put code that can't be used under the terms of wxWindows
94> License into wxWindows either. Do you think it would be possible to
95> get permission to include eggtrayicon under wxWindows license?
96>
97> Thanks,
98> Vaclav
99>
100
101Sure, that's fine by me.
102
103Anders
104--------
f9fb5408
VS
105*/
106
0a949d78 107
f9fb5408
VS
108#include "wx/platform.h"
109
a9047d85
PC
110#if wxUSE_TASKBARICON
111
adc62081 112#include <gtk/gtk.h>
0a949d78
FM
113#if GTK_CHECK_VERSION(2, 1, 0)
114
33d4eef0 115#include <string.h>
33d4eef0
VS
116#include "eggtrayicon.h"
117
b055d991
RR
118#include <gdkconfig.h>
119#if defined (GDK_WINDOWING_X11)
120#include <gdk/gdkx.h>
121#include <X11/Xatom.h>
122#elif defined (GDK_WINDOWING_WIN32)
123#include <gdk/gdkwin32.h>
124#endif
125
126
0a949d78
FM
127#define SYSTEM_TRAY_REQUEST_DOCK 0
128#define SYSTEM_TRAY_BEGIN_MESSAGE 1
129#define SYSTEM_TRAY_CANCEL_MESSAGE 2
130
131#define SYSTEM_TRAY_ORIENTATION_HORZ 0
132#define SYSTEM_TRAY_ORIENTATION_VERT 1
b055d991
RR
133
134enum {
0a949d78
FM
135 PROP_0,
136 PROP_ORIENTATION
b055d991 137};
0955be65 138
33d4eef0
VS
139static GtkPlugClass *parent_class = NULL;
140
141static void egg_tray_icon_init (EggTrayIcon *icon);
142static void egg_tray_icon_class_init (EggTrayIconClass *klass);
143
b055d991 144static void egg_tray_icon_get_property (GObject *object,
0a949d78
FM
145 guint prop_id,
146 GValue *value,
147 GParamSpec *pspec);
b055d991
RR
148
149static void egg_tray_icon_realize (GtkWidget *widget);
33d4eef0
VS
150static void egg_tray_icon_unrealize (GtkWidget *widget);
151
b055d991 152static void egg_tray_icon_add (GtkContainer *container,
0a949d78 153 GtkWidget *widget);
b055d991
RR
154
155#ifdef GDK_WINDOWING_X11
156static void egg_tray_icon_update_manager_window (EggTrayIcon *icon,
0a949d78 157 gboolean dock_if_realized);
b055d991
RR
158static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon);
159#endif
33d4eef0
VS
160
161GType
162egg_tray_icon_get_type (void)
163{
0a949d78 164 static GType our_type = 0;
33d4eef0 165
0a949d78 166 if (our_type == 0)
33d4eef0 167 {
0a949d78
FM
168 static const GTypeInfo our_info =
169 {
170 sizeof (EggTrayIconClass),
171 (GBaseInitFunc) NULL,
172 (GBaseFinalizeFunc) NULL,
173 (GClassInitFunc) egg_tray_icon_class_init,
174 NULL, /* class_finalize */
175 NULL, /* class_data */
176 sizeof (EggTrayIcon),
177 0, /* n_preallocs */
178 (GInstanceInitFunc) egg_tray_icon_init
179 };
180
181 our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0);
33d4eef0
VS
182 }
183
0a949d78 184 return our_type;
33d4eef0
VS
185}
186
187static void
188egg_tray_icon_init (EggTrayIcon *icon)
189{
0a949d78
FM
190 icon->stamp = 1;
191 icon->orientation = GTK_ORIENTATION_HORIZONTAL;
0955be65 192
0a949d78 193 gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
33d4eef0
VS
194}
195
196static void
197egg_tray_icon_class_init (EggTrayIconClass *klass)
198{
0a949d78
FM
199 GObjectClass *gobject_class = (GObjectClass *)klass;
200 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
201 GtkContainerClass *container_class = (GtkContainerClass *)klass;
33d4eef0 202
0a949d78 203 parent_class = g_type_class_peek_parent (klass);
33d4eef0 204
0a949d78 205 gobject_class->get_property = egg_tray_icon_get_property;
b055d991 206
0a949d78
FM
207 widget_class->realize = egg_tray_icon_realize;
208 widget_class->unrealize = egg_tray_icon_unrealize;
b055d991 209
0a949d78 210 container_class->add = egg_tray_icon_add;
b055d991 211
0a949d78
FM
212 g_object_class_install_property (gobject_class,
213 PROP_ORIENTATION,
214 g_param_spec_enum ("orientation",
215 "Orientation",
216 "The orientation of the tray.",
217 GTK_TYPE_ORIENTATION,
218 GTK_ORIENTATION_HORIZONTAL,
219 G_PARAM_READABLE));
b055d991
RR
220}
221
222static void
223egg_tray_icon_get_property (GObject *object,
0a949d78
FM
224 guint prop_id,
225 GValue *value,
226 GParamSpec *pspec)
b055d991 227{
0a949d78 228 EggTrayIcon *icon = EGG_TRAY_ICON (object);
b055d991 229
0a949d78 230 switch (prop_id)
b055d991
RR
231 {
232 case PROP_ORIENTATION:
0a949d78
FM
233 g_value_set_enum (value, icon->orientation);
234 break;
b055d991 235 default:
0a949d78
FM
236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237 break;
b055d991
RR
238 }
239}
240
241#ifdef GDK_WINDOWING_X11
242
243static void
244egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
245{
0a949d78
FM
246 Display *xdisplay;
247 Atom type;
248 int format;
249 union {
250 gulong *prop;
251 guchar *prop_ch;
252 } prop = { NULL };
253 gulong nitems;
254 gulong bytes_after;
255 int error, result;
256
257 g_assert (icon->manager_window != None);
258
259 xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
260
261 gdk_error_trap_push ();
262 type = None;
263 result = XGetWindowProperty (xdisplay,
264 icon->manager_window,
265 icon->orientation_atom,
266 0, G_MAXLONG, FALSE,
267 XA_CARDINAL,
268 &type, &format, &nitems,
269 &bytes_after, &(prop.prop_ch));
270 error = gdk_error_trap_pop ();
271
272 if (error || result != Success)
273 return;
274
275 if (type == XA_CARDINAL)
b055d991 276 {
0a949d78 277 GtkOrientation orientation;
b055d991 278
0a949d78
FM
279 orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ?
280 GTK_ORIENTATION_HORIZONTAL :
281 GTK_ORIENTATION_VERTICAL;
b055d991 282
0a949d78
FM
283 if (icon->orientation != orientation)
284 {
285 icon->orientation = orientation;
b055d991 286
0a949d78
FM
287 g_object_notify (G_OBJECT (icon), "orientation");
288 }
b055d991
RR
289 }
290
0a949d78
FM
291 if (prop.prop)
292 XFree (prop.prop);
33d4eef0
VS
293}
294
295static GdkFilterReturn
296egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data)
297{
0a949d78
FM
298 EggTrayIcon *icon = user_data;
299 XEvent *xev = (XEvent *)xevent;
33d4eef0 300
0a949d78
FM
301 if (xev->xany.type == ClientMessage &&
302 xev->xclient.message_type == icon->manager_atom &&
303 xev->xclient.data.l[1] == icon->selection_atom)
33d4eef0 304 {
0a949d78 305 egg_tray_icon_update_manager_window (icon, TRUE);
33d4eef0 306 }
0a949d78 307 else if (xev->xany.window == icon->manager_window)
33d4eef0 308 {
0a949d78
FM
309 if (xev->xany.type == PropertyNotify &&
310 xev->xproperty.atom == icon->orientation_atom)
311 {
312 egg_tray_icon_get_orientation_property (icon);
313 }
314 if (xev->xany.type == DestroyNotify)
315 {
316 egg_tray_icon_manager_window_destroyed (icon);
317 }
33d4eef0 318 }
0a949d78 319 return GDK_FILTER_CONTINUE;
33d4eef0
VS
320}
321
0955be65 322#endif
b055d991 323
33d4eef0
VS
324static void
325egg_tray_icon_unrealize (GtkWidget *widget)
326{
b055d991 327#ifdef GDK_WINDOWING_X11
0a949d78
FM
328 EggTrayIcon *icon = EGG_TRAY_ICON (widget);
329 GdkWindow *root_window;
33d4eef0 330
0a949d78 331 if (icon->manager_window != None)
33d4eef0 332 {
0a949d78 333 GdkWindow *gdkwin;
33d4eef0 334
0a949d78
FM
335 gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (widget),
336 icon->manager_window);
33d4eef0 337
0a949d78 338 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
33d4eef0
VS
339 }
340
0a949d78 341 root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
33d4eef0 342
0a949d78 343 gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon);
33d4eef0 344
0a949d78
FM
345 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
346 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
b055d991 347#endif
33d4eef0
VS
348}
349
b055d991
RR
350#ifdef GDK_WINDOWING_X11
351
33d4eef0
VS
352static void
353egg_tray_icon_send_manager_message (EggTrayIcon *icon,
0a949d78
FM
354 long message,
355 Window window,
356 long data1,
357 long data2,
358 long data3)
33d4eef0 359{
0a949d78
FM
360 XClientMessageEvent ev;
361 Display *display;
362
363 ev.type = ClientMessage;
364 ev.window = window;
365 ev.message_type = icon->system_tray_opcode_atom;
366 ev.format = 32;
367 ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window);
368 ev.data.l[1] = message;
369 ev.data.l[2] = data1;
370 ev.data.l[3] = data2;
371 ev.data.l[4] = data3;
372
373 display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
374
375 gdk_error_trap_push ();
376 XSendEvent (display,
377 icon->manager_window, False, NoEventMask, (XEvent *)&ev);
378 XSync (display, False);
379 gdk_error_trap_pop ();
33d4eef0
VS
380}
381
382static void
383egg_tray_icon_send_dock_request (EggTrayIcon *icon)
384{
0a949d78
FM
385 egg_tray_icon_send_manager_message (icon,
386 SYSTEM_TRAY_REQUEST_DOCK,
387 icon->manager_window,
388 gtk_plug_get_id (GTK_PLUG (icon)),
389 0, 0);
33d4eef0
VS
390}
391
392static void
b055d991 393egg_tray_icon_update_manager_window (EggTrayIcon *icon,
0a949d78 394 gboolean dock_if_realized)
33d4eef0 395{
0a949d78 396 Display *xdisplay;
0955be65 397
0a949d78
FM
398 if (icon->manager_window != None)
399 return;
0955be65 400
0a949d78 401 xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
0955be65 402
0a949d78 403 XGrabServer (xdisplay);
0955be65 404
0a949d78
FM
405 icon->manager_window = XGetSelectionOwner (xdisplay,
406 icon->selection_atom);
0955be65 407
0a949d78
FM
408 if (icon->manager_window != None)
409 XSelectInput (xdisplay,
410 icon->manager_window, StructureNotifyMask|PropertyChangeMask);
0955be65 411
0a949d78
FM
412 XUngrabServer (xdisplay);
413 XFlush (xdisplay);
0955be65 414
0a949d78 415 if (icon->manager_window != None)
33d4eef0 416 {
0a949d78 417 GdkWindow *gdkwin;
0955be65 418
0a949d78
FM
419 gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
420 icon->manager_window);
33d4eef0 421
0a949d78 422 gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
33d4eef0 423
0a949d78
FM
424 if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
425 egg_tray_icon_send_dock_request (icon);
b055d991 426
0a949d78 427 egg_tray_icon_get_orientation_property (icon);
33d4eef0
VS
428 }
429}
430
b055d991
RR
431static void
432egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon)
433{
0a949d78 434 GdkWindow *gdkwin;
b055d991 435
0a949d78 436 g_return_if_fail (icon->manager_window != None);
b055d991 437
0a949d78
FM
438 gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
439 icon->manager_window);
b055d991 440
0a949d78 441 gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
0955be65 442
0a949d78 443 icon->manager_window = None;
0955be65 444
0a949d78 445 egg_tray_icon_update_manager_window (icon, TRUE);
b055d991
RR
446}
447
448#endif
449
450static gboolean
451transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
452{
0a949d78
FM
453 gdk_window_clear_area (widget->window, event->area.x, event->area.y,
454 event->area.width, event->area.height);
455 return FALSE;
b055d991
RR
456}
457
458static void
459make_transparent_again (GtkWidget *widget, GtkStyle *previous_style,
0a949d78 460 gpointer user_data)
b055d991 461{
0a949d78 462 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
b055d991
RR
463}
464
465static void
466make_transparent (GtkWidget *widget, gpointer user_data)
33d4eef0 467{
0a949d78
FM
468 if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
469 return;
470
471 gtk_widget_set_app_paintable (widget, TRUE);
472 gtk_widget_set_double_buffered (widget, FALSE);
473 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
474 g_signal_connect (widget, "expose_event",
475 G_CALLBACK (transparent_expose_event), NULL);
476 g_signal_connect_after (widget, "style_set",
477 G_CALLBACK (make_transparent_again), NULL);
0955be65 478}
b055d991
RR
479
480static void
481egg_tray_icon_realize (GtkWidget *widget)
482{
483#ifdef GDK_WINDOWING_X11
0a949d78
FM
484 EggTrayIcon *icon = EGG_TRAY_ICON (widget);
485 GdkScreen *screen;
486 GdkDisplay *display;
487 Display *xdisplay;
488 char buffer[256];
489 GdkWindow *root_window;
0955be65 490
0a949d78
FM
491 if (GTK_WIDGET_CLASS (parent_class)->realize)
492 GTK_WIDGET_CLASS (parent_class)->realize (widget);
0955be65 493
0a949d78 494 make_transparent (widget, NULL);
0955be65 495
0a949d78
FM
496 screen = gtk_widget_get_screen (widget);
497 display = gdk_screen_get_display (screen);
498 xdisplay = gdk_x11_display_get_xdisplay (display);
0955be65 499
0a949d78
FM
500 /* Now see if there's a manager window around */
501 g_snprintf (buffer, sizeof (buffer),
502 "_NET_SYSTEM_TRAY_S%d",
503 gdk_screen_get_number (screen));
0955be65 504
0a949d78 505 icon->selection_atom = XInternAtom (xdisplay, buffer, False);
0955be65 506
0a949d78 507 icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False);
0955be65 508
0a949d78
FM
509 icon->system_tray_opcode_atom = XInternAtom (xdisplay,
510 "_NET_SYSTEM_TRAY_OPCODE",
511 False);
0955be65 512
0a949d78
FM
513 icon->orientation_atom = XInternAtom (xdisplay,
514 "_NET_SYSTEM_TRAY_ORIENTATION",
515 False);
0955be65 516
0a949d78
FM
517 egg_tray_icon_update_manager_window (icon, FALSE);
518 egg_tray_icon_send_dock_request (icon);
0955be65 519
0a949d78 520 root_window = gdk_screen_get_root_window (screen);
0955be65 521
0a949d78
FM
522 /* Add a root window filter so that we get changes on MANAGER */
523 gdk_window_add_filter (root_window,
524 egg_tray_icon_manager_filter, icon);
b055d991
RR
525#endif
526}
527
528static void
529egg_tray_icon_add (GtkContainer *container, GtkWidget *widget)
530{
0a949d78
FM
531 g_signal_connect (widget, "realize",
532 G_CALLBACK (make_transparent), NULL);
533 GTK_CONTAINER_CLASS (parent_class)->add (container, widget);
33d4eef0
VS
534}
535
536EggTrayIcon *
537egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name)
538{
0a949d78 539 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
33d4eef0 540
0a949d78 541 return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL);
33d4eef0
VS
542}
543
544EggTrayIcon*
545egg_tray_icon_new (const gchar *name)
546{
0a949d78 547 return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL);
33d4eef0
VS
548}
549
550guint
551egg_tray_icon_send_message (EggTrayIcon *icon,
0a949d78
FM
552 gint timeout,
553 const gchar *message,
554 gint len)
33d4eef0 555{
0a949d78 556 guint stamp;
0955be65 557
0a949d78
FM
558 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0);
559 g_return_val_if_fail (timeout >= 0, 0);
560 g_return_val_if_fail (message != NULL, 0);
0955be65 561
b055d991 562#ifdef GDK_WINDOWING_X11
0a949d78
FM
563 if (icon->manager_window == None)
564 return 0;
b055d991 565#endif
33d4eef0 566
0a949d78
FM
567 if (len < 0)
568 len = strlen (message);
0955be65 569
0a949d78 570 stamp = icon->stamp++;
33d4eef0 571
b055d991 572#ifdef GDK_WINDOWING_X11
0a949d78
FM
573 /* Get ready to send the message */
574 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
575 icon->manager_window,
576 timeout, len, stamp);
577
578 /* Now to send the actual message */
579 gdk_error_trap_push ();
580 while (len > 0)
33d4eef0 581 {
0a949d78
FM
582 XClientMessageEvent ev;
583 Display *xdisplay;
584
585 xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
586
587 ev.type = ClientMessage;
588 ev.window = icon->manager_window;
589 ev.format = 8;
590 ev.message_type = XInternAtom (xdisplay,
591 "_NET_SYSTEM_TRAY_MESSAGE_DATA", False);
592 if (len > 20)
593 {
594 memcpy (&ev.data, message, 20);
595 len -= 20;
596 message += 20;
597 }
598 else
599 {
600 memcpy (&ev.data, message, len);
601 len = 0;
602 }
603
604 XSendEvent (xdisplay,
605 icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev);
606 XSync (xdisplay, False);
33d4eef0 607 }
0a949d78 608 gdk_error_trap_pop ();
b055d991 609#endif
33d4eef0 610
0a949d78 611 return stamp;
33d4eef0
VS
612}
613
614void
615egg_tray_icon_cancel_message (EggTrayIcon *icon,
0a949d78 616 guint id)
33d4eef0 617{
0a949d78
FM
618 g_return_if_fail (EGG_IS_TRAY_ICON (icon));
619 g_return_if_fail (id > 0);
0955be65 620#ifdef GDK_WINDOWING_X11
0a949d78
FM
621 egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
622 (Window)gtk_plug_get_id (GTK_PLUG (icon)),
623 id, 0, 0);
b055d991 624#endif
33d4eef0 625}
f9fb5408 626
b055d991
RR
627GtkOrientation
628egg_tray_icon_get_orientation (EggTrayIcon *icon)
629{
0a949d78 630 g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL);
b055d991 631
0a949d78 632 return icon->orientation;
b055d991
RR
633}
634
0a949d78
FM
635
636
637
638
639#endif /* GTK_CHECK_VERSION(2, 1, 0) */
a9047d85 640#endif /* wxUSE_TASKBARICON */