Sat, 19 May 2007 21:38:47 +0000
merge of '1442df274a24edc9a31194327bd00dfbcf478720'
and 'ce02548a6b6a545d97fb3f371506bcf1b5cc5131'
| 3510 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
| 2 | /* eggtrayicon.c | |
| 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 | ||
| 10779 | 21 | #include <config.h> |
| 3510 | 22 | #include <string.h> |
| 10779 | 23 | |
| 24 | #include "eggtrayicon.h" | |
| 25 | ||
| 3510 | 26 | #include <gdk/gdkx.h> |
| 10779 | 27 | #include <X11/Xatom.h> |
| 28 | ||
| 29 | #define _(x) x | |
| 30 | #define N_(x) x | |
| 3510 | 31 | |
| 32 | #define SYSTEM_TRAY_REQUEST_DOCK 0 | |
| 33 | #define SYSTEM_TRAY_BEGIN_MESSAGE 1 | |
| 34 | #define SYSTEM_TRAY_CANCEL_MESSAGE 2 | |
| 10779 | 35 | |
| 36 | #define SYSTEM_TRAY_ORIENTATION_HORZ 0 | |
| 37 | #define SYSTEM_TRAY_ORIENTATION_VERT 1 | |
| 38 | ||
| 39 | enum { | |
| 40 | PROP_0, | |
| 41 | PROP_ORIENTATION | |
| 42 | }; | |
| 3510 | 43 | |
| 44 | static GtkPlugClass *parent_class = NULL; | |
| 45 | ||
| 46 | static void egg_tray_icon_init (EggTrayIcon *icon); | |
| 47 | static void egg_tray_icon_class_init (EggTrayIconClass *klass); | |
| 48 | ||
| 10779 | 49 | static void egg_tray_icon_get_property (GObject *object, |
| 50 | guint prop_id, | |
| 51 | GValue *value, | |
| 52 | GParamSpec *pspec); | |
| 53 | ||
| 54 | static void egg_tray_icon_realize (GtkWidget *widget); | |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
55 | static void egg_tray_icon_unrealize (GtkWidget *widget); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
56 | |
| 14231 | 57 | static void egg_tray_icon_add (GtkContainer *container, |
| 58 | GtkWidget *widget); | |
| 59 | ||
| 10779 | 60 | static void egg_tray_icon_update_manager_window (EggTrayIcon *icon, |
| 61 | gboolean dock_if_realized); | |
| 62 | static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon); | |
| 3510 | 63 | |
| 64 | GType | |
| 65 | egg_tray_icon_get_type (void) | |
| 66 | { | |
| 67 | static GType our_type = 0; | |
| 68 | ||
| 69 | if (our_type == 0) | |
| 70 | { | |
| 10779 | 71 | our_type = g_type_from_name("EggTrayIcon"); |
| 72 | ||
| 73 | if (our_type == 0) | |
| 74 | { | |
| 3510 | 75 | static const GTypeInfo our_info = |
| 76 | { | |
| 77 | sizeof (EggTrayIconClass), | |
| 78 | (GBaseInitFunc) NULL, | |
| 79 | (GBaseFinalizeFunc) NULL, | |
| 80 | (GClassInitFunc) egg_tray_icon_class_init, | |
| 81 | NULL, /* class_finalize */ | |
| 82 | NULL, /* class_data */ | |
| 83 | sizeof (EggTrayIcon), | |
| 84 | 0, /* n_preallocs */ | |
|
12600
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11291
diff
changeset
|
85 | (GInstanceInitFunc) egg_tray_icon_init, |
|
7ecd4441fdc7
[gaim-migrate @ 14934]
Richard Laager <rlaager@pidgin.im>
parents:
11291
diff
changeset
|
86 | NULL /* value_table */ |
| 3510 | 87 | }; |
| 88 | ||
| 89 | our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0); | |
| 10779 | 90 | } |
| 91 | else if (parent_class == NULL) | |
| 92 | { | |
| 93 | /* we're reheating the old class from a previous instance - engage ugly hack =( */ | |
| 94 | egg_tray_icon_class_init((EggTrayIconClass *)g_type_class_peek(our_type)); | |
| 95 | } | |
| 3510 | 96 | } |
| 97 | ||
| 98 | return our_type; | |
| 99 | } | |
| 100 | ||
| 101 | static void | |
| 102 | egg_tray_icon_init (EggTrayIcon *icon) | |
| 103 | { | |
| 104 | icon->stamp = 1; | |
| 10779 | 105 | icon->orientation = GTK_ORIENTATION_HORIZONTAL; |
| 3510 | 106 | |
| 107 | gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK); | |
| 108 | } | |
| 109 | ||
| 110 | static void | |
| 111 | egg_tray_icon_class_init (EggTrayIconClass *klass) | |
| 112 | { | |
| 10779 | 113 | GObjectClass *gobject_class = (GObjectClass *)klass; |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
114 | GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; |
| 14231 | 115 | GtkContainerClass *container_class = (GtkContainerClass *)klass; |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
116 | |
| 3510 | 117 | parent_class = g_type_class_peek_parent (klass); |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
118 | |
| 10779 | 119 | gobject_class->get_property = egg_tray_icon_get_property; |
| 120 | ||
| 121 | widget_class->realize = egg_tray_icon_realize; | |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
122 | widget_class->unrealize = egg_tray_icon_unrealize; |
| 10779 | 123 | |
| 14231 | 124 | container_class->add = egg_tray_icon_add; |
| 125 | ||
| 10779 | 126 | g_object_class_install_property (gobject_class, |
| 127 | PROP_ORIENTATION, | |
| 128 | g_param_spec_enum ("orientation", | |
| 129 | _("Orientation"), | |
| 130 | _("The orientation of the tray."), | |
| 131 | GTK_TYPE_ORIENTATION, | |
| 132 | GTK_ORIENTATION_HORIZONTAL, | |
| 133 | G_PARAM_READABLE)); | |
| 134 | } | |
| 135 | ||
| 136 | static void | |
| 137 | egg_tray_icon_get_property (GObject *object, | |
| 138 | guint prop_id, | |
| 139 | GValue *value, | |
| 140 | GParamSpec *pspec) | |
| 141 | { | |
| 142 | EggTrayIcon *icon = EGG_TRAY_ICON (object); | |
| 143 | ||
| 144 | switch (prop_id) | |
| 145 | { | |
| 146 | case PROP_ORIENTATION: | |
| 147 | g_value_set_enum (value, icon->orientation); | |
| 148 | break; | |
| 149 | default: | |
| 150 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
| 151 | break; | |
| 152 | } | |
| 153 | } | |
| 154 | ||
| 155 | static void | |
| 156 | egg_tray_icon_get_orientation_property (EggTrayIcon *icon) | |
| 157 | { | |
| 158 | Display *xdisplay; | |
| 159 | Atom type; | |
| 160 | int format; | |
| 161 | union { | |
| 162 | gulong *prop; | |
| 163 | guchar *prop_ch; | |
| 164 | } prop = { NULL }; | |
| 165 | gulong nitems; | |
| 166 | gulong bytes_after; | |
| 167 | int error, result; | |
| 168 | ||
|
11291
5441d2419942
[gaim-migrate @ 13491]
Mark Doliner <markdoliner@pidgin.im>
parents:
10779
diff
changeset
|
169 | g_return_if_fail(icon->manager_window != None); |
| 10779 | 170 | |
| 171 | #if GTK_CHECK_VERSION(2,1,0) | |
| 172 | xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); | |
| 173 | #else | |
| 174 | xdisplay = gdk_display; | |
| 175 | #endif | |
| 176 | ||
| 177 | gdk_error_trap_push (); | |
| 178 | type = None; | |
| 179 | result = XGetWindowProperty (xdisplay, | |
| 180 | icon->manager_window, | |
| 181 | icon->orientation_atom, | |
| 182 | 0, G_MAXLONG, FALSE, | |
| 183 | XA_CARDINAL, | |
| 184 | &type, &format, &nitems, | |
| 185 | &bytes_after, &(prop.prop_ch)); | |
| 186 | error = gdk_error_trap_pop (); | |
| 187 | ||
| 188 | if (error || result != Success) | |
| 189 | return; | |
| 190 | ||
| 191 | if (type == XA_CARDINAL) | |
| 192 | { | |
| 193 | GtkOrientation orientation; | |
| 194 | ||
| 195 | orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ? | |
| 196 | GTK_ORIENTATION_HORIZONTAL : | |
| 197 | GTK_ORIENTATION_VERTICAL; | |
| 198 | ||
| 199 | if (icon->orientation != orientation) | |
| 200 | { | |
| 201 | icon->orientation = orientation; | |
| 202 | ||
| 203 | g_object_notify (G_OBJECT (icon), "orientation"); | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | if (prop.prop) | |
| 208 | XFree (prop.prop); | |
| 3510 | 209 | } |
| 210 | ||
| 211 | static GdkFilterReturn | |
| 212 | egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) | |
| 213 | { | |
| 214 | EggTrayIcon *icon = user_data; | |
| 215 | XEvent *xev = (XEvent *)xevent; | |
| 216 | ||
| 217 | if (xev->xany.type == ClientMessage && | |
| 218 | xev->xclient.message_type == icon->manager_atom && | |
| 219 | xev->xclient.data.l[1] == icon->selection_atom) | |
| 220 | { | |
| 10779 | 221 | egg_tray_icon_update_manager_window (icon, TRUE); |
| 3510 | 222 | } |
| 223 | else if (xev->xany.window == icon->manager_window) | |
| 224 | { | |
| 10779 | 225 | if (xev->xany.type == PropertyNotify && |
| 226 | xev->xproperty.atom == icon->orientation_atom) | |
| 227 | { | |
| 228 | egg_tray_icon_get_orientation_property (icon); | |
| 229 | } | |
| 3510 | 230 | if (xev->xany.type == DestroyNotify) |
| 231 | { | |
| 10779 | 232 | egg_tray_icon_manager_window_destroyed (icon); |
| 3510 | 233 | } |
| 234 | } | |
| 235 | ||
| 236 | return GDK_FILTER_CONTINUE; | |
| 237 | } | |
| 238 | ||
| 239 | static void | |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
240 | egg_tray_icon_unrealize (GtkWidget *widget) |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
241 | { |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
242 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
243 | GdkWindow *root_window; |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
244 | |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
245 | if (icon->manager_window != None) |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
246 | { |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
247 | GdkWindow *gdkwin; |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
248 | |
| 10779 | 249 | #if GTK_CHECK_VERSION(2,1,0) |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
250 | gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (widget), |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
251 | icon->manager_window); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
252 | #else |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
253 | gdkwin = gdk_window_lookup (icon->manager_window); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
254 | #endif |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
255 | |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
256 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
257 | } |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
258 | |
| 10779 | 259 | #if GTK_CHECK_VERSION(2,1,0) |
|
4261
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
260 | root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget)); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
261 | #else |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
262 | root_window = gdk_window_lookup (gdk_x11_get_default_root_xwindow ()); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
263 | #endif |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
264 | |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
265 | gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
266 | |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
267 | if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
268 | (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
269 | } |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
270 | |
|
cc35d7c0582f
<Robot101> commit message:
Robert McQueen <robot101@debian.org>
parents:
3510
diff
changeset
|
271 | static void |
| 3510 | 272 | egg_tray_icon_send_manager_message (EggTrayIcon *icon, |
| 273 | long message, | |
| 274 | Window window, | |
| 275 | long data1, | |
| 276 | long data2, | |
| 277 | long data3) | |
| 278 | { | |
| 279 | XClientMessageEvent ev; | |
| 280 | Display *display; | |
| 281 | ||
| 282 | ev.type = ClientMessage; | |
| 283 | ev.window = window; | |
| 284 | ev.message_type = icon->system_tray_opcode_atom; | |
| 285 | ev.format = 32; | |
| 286 | ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window); | |
| 287 | ev.data.l[1] = message; | |
| 288 | ev.data.l[2] = data1; | |
| 289 | ev.data.l[3] = data2; | |
| 290 | ev.data.l[4] = data3; | |
| 291 | ||
| 10779 | 292 | #if GTK_CHECK_VERSION(2,1,0) |
| 3510 | 293 | display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); |
| 294 | #else | |
| 295 | display = gdk_display; | |
| 296 | #endif | |
| 10779 | 297 | |
| 3510 | 298 | gdk_error_trap_push (); |
| 299 | XSendEvent (display, | |
| 300 | icon->manager_window, False, NoEventMask, (XEvent *)&ev); | |
| 301 | XSync (display, False); | |
| 302 | gdk_error_trap_pop (); | |
| 303 | } | |
| 304 | ||
| 305 | static void | |
| 306 | egg_tray_icon_send_dock_request (EggTrayIcon *icon) | |
| 307 | { | |
| 308 | egg_tray_icon_send_manager_message (icon, | |
| 309 | SYSTEM_TRAY_REQUEST_DOCK, | |
| 310 | icon->manager_window, | |
| 311 | gtk_plug_get_id (GTK_PLUG (icon)), | |
| 312 | 0, 0); | |
| 313 | } | |
| 314 | ||
| 315 | static void | |
| 10779 | 316 | egg_tray_icon_update_manager_window (EggTrayIcon *icon, |
| 317 | gboolean dock_if_realized) | |
| 3510 | 318 | { |
| 319 | Display *xdisplay; | |
| 320 | ||
| 10779 | 321 | if (icon->manager_window != None) |
| 322 | return; | |
| 323 | ||
| 324 | #if GTK_CHECK_VERSION(2,1,0) | |
| 3510 | 325 | xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); |
| 326 | #else | |
| 327 | xdisplay = gdk_display; | |
| 328 | #endif | |
| 329 | ||
| 330 | XGrabServer (xdisplay); | |
| 331 | ||
| 332 | icon->manager_window = XGetSelectionOwner (xdisplay, | |
| 333 | icon->selection_atom); | |
| 334 | ||
| 335 | if (icon->manager_window != None) | |
| 336 | XSelectInput (xdisplay, | |
| 10779 | 337 | icon->manager_window, StructureNotifyMask|PropertyChangeMask); |
| 3510 | 338 | |
| 339 | XUngrabServer (xdisplay); | |
| 340 | XFlush (xdisplay); | |
| 341 | ||
| 342 | if (icon->manager_window != None) | |
| 343 | { | |
| 344 | GdkWindow *gdkwin; | |
| 345 | ||
| 10779 | 346 | #if GTK_CHECK_VERSION(2,1,0) |
| 3510 | 347 | gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)), |
| 348 | icon->manager_window); | |
| 349 | #else | |
| 350 | gdkwin = gdk_window_lookup (icon->manager_window); | |
| 351 | #endif | |
| 10779 | 352 | |
| 3510 | 353 | gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon); |
| 354 | ||
| 10779 | 355 | if (dock_if_realized && GTK_WIDGET_REALIZED (icon)) |
| 356 | egg_tray_icon_send_dock_request (icon); | |
| 357 | ||
| 358 | egg_tray_icon_get_orientation_property (icon); | |
| 3510 | 359 | } |
| 360 | } | |
| 361 | ||
| 10779 | 362 | static void |
| 363 | egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon) | |
| 3510 | 364 | { |
| 10779 | 365 | GdkWindow *gdkwin; |
| 366 | ||
| 367 | g_return_if_fail (icon->manager_window != None); | |
| 368 | ||
| 369 | #if GTK_CHECK_VERSION(2,1,0) | |
| 370 | gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)), | |
| 371 | icon->manager_window); | |
| 372 | #else | |
| 373 | gdkwin = gdk_window_lookup (icon->manager_window); | |
| 374 | #endif | |
| 375 | ||
| 376 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); | |
| 377 | ||
| 378 | icon->manager_window = None; | |
| 379 | ||
| 380 | egg_tray_icon_update_manager_window (icon, TRUE); | |
| 381 | } | |
| 382 | ||
| 14231 | 383 | static gboolean |
| 384 | transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) | |
| 385 | { | |
| 386 | gdk_window_clear_area (widget->window, event->area.x, event->area.y, | |
| 387 | event->area.width, event->area.height); | |
| 388 | return FALSE; | |
| 389 | } | |
| 390 | ||
| 391 | static void | |
| 392 | make_transparent_again (GtkWidget *widget, GtkStyle *previous_style, | |
| 393 | gpointer user_data) | |
| 394 | { | |
| 395 | gdk_window_set_back_pixmap(widget->window, NULL, TRUE); | |
| 396 | } | |
| 397 | ||
| 398 | static void | |
| 399 | make_transparent (GtkWidget *widget, gpointer user_data) | |
| 400 | { | |
| 401 | if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget)) | |
| 402 | return; | |
| 403 | ||
| 404 | gtk_widget_set_app_paintable (widget, TRUE); | |
| 405 | gtk_widget_set_double_buffered (widget, FALSE); | |
| 406 | gdk_window_set_back_pixmap (widget->window, NULL, TRUE); | |
| 407 | g_signal_connect (widget, "expose_event", | |
| 408 | G_CALLBACK (transparent_expose_event), NULL); | |
| 409 | g_signal_connect_after (widget, "style_set", | |
| 410 | G_CALLBACK (make_transparent_again), NULL); | |
| 411 | } | |
| 412 | ||
| 10779 | 413 | static void |
| 414 | egg_tray_icon_realize (GtkWidget *widget) | |
| 415 | { | |
| 416 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); | |
| 417 | gint screen; | |
| 418 | Display *xdisplay; | |
| 3510 | 419 | char buffer[256]; |
| 420 | GdkWindow *root_window; | |
| 421 | ||
| 10779 | 422 | if (GTK_WIDGET_CLASS (parent_class)->realize) |
| 423 | GTK_WIDGET_CLASS (parent_class)->realize (widget); | |
| 3510 | 424 | |
| 14231 | 425 | make_transparent (widget, NULL); |
| 426 | ||
| 10779 | 427 | #if GTK_CHECK_VERSION(2,1,0) |
| 428 | screen = gdk_screen_get_number (gtk_widget_get_screen (widget)); | |
| 429 | xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)); | |
| 3510 | 430 | #else |
| 10779 | 431 | screen = XScreenNumberOfScreen (DefaultScreenOfDisplay (gdk_display)); |
| 432 | xdisplay = gdk_display; | |
| 3510 | 433 | #endif |
| 434 | ||
| 435 | /* Now see if there's a manager window around */ | |
| 436 | g_snprintf (buffer, sizeof (buffer), | |
| 437 | "_NET_SYSTEM_TRAY_S%d", | |
| 10779 | 438 | screen); |
| 439 | ||
| 440 | icon->selection_atom = XInternAtom (xdisplay, buffer, False); | |
| 3510 | 441 | |
| 10779 | 442 | icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False); |
| 3510 | 443 | |
| 10779 | 444 | icon->system_tray_opcode_atom = XInternAtom (xdisplay, |
| 445 | "_NET_SYSTEM_TRAY_OPCODE", | |
| 446 | False); | |
| 3510 | 447 | |
| 10779 | 448 | icon->orientation_atom = XInternAtom (xdisplay, |
| 449 | "_NET_SYSTEM_TRAY_ORIENTATION", | |
| 450 | False); | |
| 3510 | 451 | |
| 10779 | 452 | egg_tray_icon_update_manager_window (icon, FALSE); |
| 453 | egg_tray_icon_send_dock_request (icon); | |
| 454 | ||
| 455 | #if GTK_CHECK_VERSION(2,1,0) | |
| 456 | root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget)); | |
| 3510 | 457 | #else |
| 458 | root_window = gdk_window_lookup (gdk_x11_get_default_root_xwindow ()); | |
| 459 | #endif | |
| 10779 | 460 | |
| 3510 | 461 | /* Add a root window filter so that we get changes on MANAGER */ |
| 462 | gdk_window_add_filter (root_window, | |
| 463 | egg_tray_icon_manager_filter, icon); | |
| 464 | } | |
| 465 | ||
| 14231 | 466 | static void |
| 467 | egg_tray_icon_add (GtkContainer *container, GtkWidget *widget) | |
| 468 | { | |
| 469 | g_signal_connect (widget, "realize", | |
| 470 | G_CALLBACK (make_transparent), NULL); | |
| 471 | GTK_CONTAINER_CLASS (parent_class)->add (container, widget); | |
| 472 | } | |
| 473 | ||
| 10779 | 474 | #if GTK_CHECK_VERSION(2,1,0) |
| 3510 | 475 | EggTrayIcon * |
| 476 | egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name) | |
| 477 | { | |
| 478 | g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); | |
| 479 | ||
| 10779 | 480 | return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL); |
| 3510 | 481 | } |
| 482 | #endif | |
| 483 | ||
| 484 | EggTrayIcon* | |
| 485 | egg_tray_icon_new (const gchar *name) | |
| 486 | { | |
| 10779 | 487 | return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL); |
| 3510 | 488 | } |
| 489 | ||
| 490 | guint | |
| 491 | egg_tray_icon_send_message (EggTrayIcon *icon, | |
| 492 | gint timeout, | |
| 493 | const gchar *message, | |
| 494 | gint len) | |
| 495 | { | |
| 496 | guint stamp; | |
| 497 | ||
| 498 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); | |
| 499 | g_return_val_if_fail (timeout >= 0, 0); | |
| 500 | g_return_val_if_fail (message != NULL, 0); | |
| 501 | ||
| 502 | if (icon->manager_window == None) | |
| 503 | return 0; | |
| 504 | ||
| 505 | if (len < 0) | |
| 506 | len = strlen (message); | |
| 507 | ||
| 508 | stamp = icon->stamp++; | |
| 509 | ||
| 510 | /* Get ready to send the message */ | |
| 511 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, | |
| 512 | (Window)gtk_plug_get_id (GTK_PLUG (icon)), | |
| 513 | timeout, len, stamp); | |
| 514 | ||
| 515 | /* Now to send the actual message */ | |
| 516 | gdk_error_trap_push (); | |
| 517 | while (len > 0) | |
| 518 | { | |
| 519 | XClientMessageEvent ev; | |
| 520 | Display *xdisplay; | |
| 521 | ||
| 10779 | 522 | #if GTK_CHECK_VERSION(2,1,0) |
| 3510 | 523 | xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); |
| 524 | #else | |
| 525 | xdisplay = gdk_display; | |
| 526 | #endif | |
| 10779 | 527 | |
| 3510 | 528 | ev.type = ClientMessage; |
| 529 | ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon)); | |
| 530 | ev.format = 8; | |
| 531 | ev.message_type = XInternAtom (xdisplay, | |
| 532 | "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); | |
| 533 | if (len > 20) | |
| 534 | { | |
| 535 | memcpy (&ev.data, message, 20); | |
| 536 | len -= 20; | |
| 537 | message += 20; | |
| 538 | } | |
| 539 | else | |
| 540 | { | |
| 541 | memcpy (&ev.data, message, len); | |
| 542 | len = 0; | |
| 543 | } | |
| 544 | ||
| 545 | XSendEvent (xdisplay, | |
| 546 | icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); | |
| 547 | XSync (xdisplay, False); | |
| 548 | } | |
| 549 | gdk_error_trap_pop (); | |
| 550 | ||
| 551 | return stamp; | |
| 552 | } | |
| 553 | ||
| 554 | void | |
| 555 | egg_tray_icon_cancel_message (EggTrayIcon *icon, | |
| 556 | guint id) | |
| 557 | { | |
| 558 | g_return_if_fail (EGG_IS_TRAY_ICON (icon)); | |
| 559 | g_return_if_fail (id > 0); | |
| 560 | ||
| 561 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE, | |
| 562 | (Window)gtk_plug_get_id (GTK_PLUG (icon)), | |
| 563 | id, 0, 0); | |
| 564 | } | |
| 10779 | 565 | |
| 566 | GtkOrientation | |
| 567 | egg_tray_icon_get_orientation (EggTrayIcon *icon) | |
| 568 | { | |
| 569 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL); | |
| 570 | ||
| 571 | return icon->orientation; | |
| 572 | } |