3 * Copyright (C) 2003 Sun Microsystems, Inc.
4 * Copyright (C) 2005 Hans Breuer <hans@breuer.org>
5 * Copyright (C) 2005 Novell, Inc.
6 * Copyright (C) 2006 Imendio AB
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Mark McLoughlin <mark@skynet.ie>
25 * Hans Breuer <hans@breuer.org>
26 * Tor Lillqvist <tml@novell.com>
27 * Mikael Hallendal <micke@imendio.com>
33 #include "gtkstatusicon.h"
36 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
39 #include "gtktrayicon.h"
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
43 #include "gtktooltip.h"
45 #ifdef GDK_WINDOWING_X11
46 #include "gdk/x11/gdkx.h"
49 #ifdef GDK_WINDOWING_WIN32
50 #include "gtkicontheme.h"
53 #include "win32/gdkwin32.h"
54 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
57 #ifdef GDK_WINDOWING_QUARTZ
58 #include "gtkicontheme.h"
62 #include "gdkkeysyms.h"
66 #define BLINK_TIMEOUT 500
94 BUTTON_PRESS_EVENT_SIGNAL,
95 BUTTON_RELEASE_EVENT_SIGNAL,
101 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
103 #ifdef GDK_WINDOWING_QUARTZ
104 #include "gtkstatusicon-quartz.c"
107 struct _GtkStatusIconPrivate
109 #ifdef GDK_WINDOWING_X11
110 GtkWidget *tray_icon;
114 #ifdef GDK_WINDOWING_WIN32
115 GtkWidget *dummy_widget;
117 gint last_click_x, last_click_y;
118 GtkOrientation orientation;
123 #ifdef GDK_WINDOWING_QUARTZ
124 GtkWidget *dummy_widget;
125 GtkQuartzStatusIcon *status_item;
135 GtkImageType storage_type;
145 GdkPixbuf *blank_icon;
146 guint blinking_timeout;
153 static GObject* gtk_status_icon_constructor (GType type,
154 guint n_construct_properties,
155 GObjectConstructParam *construct_params);
156 static void gtk_status_icon_finalize (GObject *object);
157 static void gtk_status_icon_set_property (GObject *object,
161 static void gtk_status_icon_get_property (GObject *object,
166 #ifdef GDK_WINDOWING_X11
167 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
168 GtkAllocation *allocation);
169 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
170 GdkScreen *old_screen);
171 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
172 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
173 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
174 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
176 GtkStatusIcon *status_icon);
177 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
178 GdkEventScroll *event);
179 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
182 gboolean keyboard_tip,
183 GtkTooltip *tooltip);
185 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
187 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
189 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
190 GdkEventButton *event);
191 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
192 GdkEventButton *event);
193 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
194 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
195 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
197 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
200 gtk_status_icon_class_init (GtkStatusIconClass *class)
202 GObjectClass *gobject_class = (GObjectClass *) class;
204 gobject_class->constructor = gtk_status_icon_constructor;
205 gobject_class->finalize = gtk_status_icon_finalize;
206 gobject_class->set_property = gtk_status_icon_set_property;
207 gobject_class->get_property = gtk_status_icon_get_property;
209 class->button_press_event = NULL;
210 class->button_release_event = NULL;
211 class->scroll_event = NULL;
212 class->query_tooltip = NULL;
214 g_object_class_install_property (gobject_class,
216 g_param_spec_object ("pixbuf",
218 P_("A GdkPixbuf to display"),
220 GTK_PARAM_READWRITE));
222 g_object_class_install_property (gobject_class,
224 g_param_spec_string ("file",
226 P_("Filename to load and display"),
228 GTK_PARAM_WRITABLE));
230 g_object_class_install_property (gobject_class,
232 g_param_spec_string ("stock",
234 P_("Stock ID for a stock image to display"),
236 GTK_PARAM_READWRITE));
238 g_object_class_install_property (gobject_class,
240 g_param_spec_string ("icon-name",
242 P_("The name of the icon from the icon theme"),
244 GTK_PARAM_READWRITE));
247 * GtkStatusIcon:gicon:
249 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
250 * the image will be updated automatically if the theme changes.
254 g_object_class_install_property (gobject_class,
256 g_param_spec_object ("gicon",
258 P_("The GIcon being displayed"),
260 GTK_PARAM_READWRITE));
262 g_object_class_install_property (gobject_class,
264 g_param_spec_enum ("storage-type",
266 P_("The representation being used for image data"),
269 GTK_PARAM_READABLE));
271 g_object_class_install_property (gobject_class,
273 g_param_spec_int ("size",
275 P_("The size of the icon"),
279 GTK_PARAM_READABLE));
281 g_object_class_install_property (gobject_class,
283 g_param_spec_object ("screen",
285 P_("The screen where this status icon will be displayed"),
287 GTK_PARAM_READWRITE));
289 g_object_class_install_property (gobject_class,
291 g_param_spec_boolean ("blinking",
293 P_("Whether or not the status icon is blinking"),
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (gobject_class,
299 g_param_spec_boolean ("visible",
301 P_("Whether or not the status icon is visible"),
303 GTK_PARAM_READWRITE));
307 * GtkStatusIcon:embedded:
309 * %TRUE if the statusicon is embedded in a notification area.
313 g_object_class_install_property (gobject_class,
315 g_param_spec_boolean ("embedded",
317 P_("Whether or not the status icon is embedded"),
319 GTK_PARAM_READABLE));
322 * GtkStatusIcon:orientation:
324 * The orientation of the tray in which the statusicon
329 g_object_class_install_property (gobject_class,
331 g_param_spec_enum ("orientation",
333 P_("The orientation of the tray"),
334 GTK_TYPE_ORIENTATION,
335 GTK_ORIENTATION_HORIZONTAL,
336 GTK_PARAM_READABLE));
339 * GtkStatusIcon:has-tooltip:
341 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
342 * @status_icon. A value of %TRUE indicates that @status_icon can have a
343 * tooltip, in this case the status icon will be queried using
344 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
347 * Note that setting this property to %TRUE for the first time will change
348 * the event masks of the windows of this status icon to include leave-notify
349 * and motion-notify events. This will not be undone when the property is set
352 * Whether this property is respected is platform dependent.
353 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
357 g_object_class_install_property (gobject_class,
359 g_param_spec_boolean ("has-tooltip",
361 P_("Whether this tray icon has a tooltip"),
363 GTK_PARAM_READWRITE));
365 * GtkStatusIcon:tooltip-text:
367 * Sets the text of tooltip to be the given string.
369 * Also see gtk_tooltip_set_text().
371 * This is a convenience property which will take care of getting the
372 * tooltip shown if the given string is not %NULL.
373 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
374 * the default handler for the #GtkStatusIcon::query-tooltip signal
375 * will take care of displaying the tooltip.
377 * Note that some platforms have limitations on the length of tooltips
378 * that they allow on status icons, e.g. Windows only shows the first
383 g_object_class_install_property (gobject_class,
385 g_param_spec_string ("tooltip-text",
387 P_("The contents of the tooltip for this widget"),
389 GTK_PARAM_READWRITE));
391 * GtkStatusIcon:tooltip-markup:
393 * Sets the text of tooltip to be the given string, which is marked up
394 * with the <link linkend="PangoMarkupFormat">Pango text markup
395 * language</link>. Also see gtk_tooltip_set_markup().
397 * This is a convenience property which will take care of getting the
398 * tooltip shown if the given string is not %NULL.
399 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
400 * the default handler for the #GtkStatusIcon::query-tooltip signal
401 * will take care of displaying the tooltip.
403 * On some platforms, embedded markup will be ignored.
407 g_object_class_install_property (gobject_class,
409 g_param_spec_string ("tooltip-markup",
410 P_("Tooltip markup"),
411 P_("The contents of the tooltip for this tray icon"),
413 GTK_PARAM_READWRITE));
417 * GtkStatusIcon:title:
419 * The title of this tray icon. This should be a short, human-readable,
420 * localized string describing the tray icon. It may be used by tools
421 * like screen readers to render the tray icon.
425 g_object_class_install_property (gobject_class,
427 g_param_spec_string ("title",
429 P_("The title of this tray icon"),
431 GTK_PARAM_READWRITE));
434 * GtkStatusIcon::activate:
435 * @status_icon: the object which received the signal
437 * Gets emitted when the user activates the status icon.
438 * If and how status icons can activated is platform-dependent.
440 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
441 * be used by applications and should be wrapped by language bindings.
445 status_icon_signals [ACTIVATE_SIGNAL] =
446 g_signal_new (I_("activate"),
447 G_TYPE_FROM_CLASS (gobject_class),
448 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
449 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
452 g_cclosure_marshal_VOID__VOID,
457 * GtkStatusIcon::popup-menu:
458 * @status_icon: the object which received the signal
459 * @button: the button that was pressed, or 0 if the
460 * signal is not emitted in response to a button press event
461 * @activate_time: the timestamp of the event that
462 * triggered the signal emission
464 * Gets emitted when the user brings up the context menu
465 * of the status icon. Whether status icons can have context
466 * menus and how these are activated is platform-dependent.
468 * The @button and @activate_time parameters should be
469 * passed as the last to arguments to gtk_menu_popup().
471 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
472 * be used by applications and should be wrapped by language bindings.
476 status_icon_signals [POPUP_MENU_SIGNAL] =
477 g_signal_new (I_("popup-menu"),
478 G_TYPE_FROM_CLASS (gobject_class),
479 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
480 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
483 _gtk_marshal_VOID__UINT_UINT,
490 * GtkStatusIcon::size-changed:
491 * @status_icon: the object which received the signal
492 * @size: the new size
494 * Gets emitted when the size available for the image
495 * changes, e.g. because the notification area got resized.
497 * Return value: %TRUE if the icon was updated for the new
498 * size. Otherwise, GTK+ will scale the icon as necessary.
502 status_icon_signals [SIZE_CHANGED_SIGNAL] =
503 g_signal_new (I_("size-changed"),
504 G_TYPE_FROM_CLASS (gobject_class),
506 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
507 g_signal_accumulator_true_handled,
509 _gtk_marshal_BOOLEAN__INT,
515 * GtkStatusIcon::button-press-event:
516 * @status_icon: the object which received the signal
517 * @event: the #GdkEventButton which triggered this signal
519 * The ::button-press-event signal will be emitted when a button
520 * (typically from a mouse) is pressed.
522 * Whether this event is emitted is platform-dependent. Use the ::activate
523 * and ::popup-menu signals in preference.
525 * Return value: %TRUE to stop other handlers from being invoked
526 * for the event. %FALSE to propagate the event further.
530 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
531 g_signal_new (I_("button_press_event"),
532 G_TYPE_FROM_CLASS (gobject_class),
534 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
535 g_signal_accumulator_true_handled, NULL,
536 _gtk_marshal_BOOLEAN__BOXED,
538 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
541 * GtkStatusIcon::button-release-event:
542 * @status_icon: the object which received the signal
543 * @event: the #GdkEventButton which triggered this signal
545 * The ::button-release-event signal will be emitted when a button
546 * (typically from a mouse) is released.
548 * Whether this event is emitted is platform-dependent. Use the ::activate
549 * and ::popup-menu signals in preference.
551 * Return value: %TRUE to stop other handlers from being invoked
552 * for the event. %FALSE to propagate the event further.
556 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
557 g_signal_new (I_("button_release_event"),
558 G_TYPE_FROM_CLASS (gobject_class),
560 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
561 g_signal_accumulator_true_handled, NULL,
562 _gtk_marshal_BOOLEAN__BOXED,
564 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
567 * GtkStatusIcon::scroll-event:
568 * @status_icon: the object which received the signal.
569 * @event: the #GdkEventScroll which triggered this signal
571 * The ::scroll-event signal is emitted when a button in the 4 to 7
572 * range is pressed. Wheel mice are usually configured to generate
573 * button press events for buttons 4 and 5 when the wheel is turned.
575 * Whether this event is emitted is platform-dependent.
577 * Returns: %TRUE to stop other handlers from being invoked for the event.
578 * %FALSE to propagate the event further.
580 status_icon_signals[SCROLL_EVENT_SIGNAL] =
581 g_signal_new (I_("scroll_event"),
582 G_TYPE_FROM_CLASS (gobject_class),
584 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
585 g_signal_accumulator_true_handled, NULL,
586 _gtk_marshal_BOOLEAN__BOXED,
588 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
591 * GtkStatusIcon::query-tooltip:
592 * @status_icon: the object which received the signal
593 * @x: the x coordinate of the cursor position where the request has been
594 * emitted, relative to @status_icon
595 * @y: the y coordinate of the cursor position where the request has been
596 * emitted, relative to @status_icon
597 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
598 * @tooltip: a #GtkTooltip
600 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
601 * cursor hovering above @status_icon; or emitted when @status_icon got
602 * focus in keyboard mode.
604 * Using the given coordinates, the signal handler should determine
605 * whether a tooltip should be shown for @status_icon. If this is
606 * the case %TRUE should be returned, %FALSE otherwise. Note that if
607 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
608 * should not be used.
610 * The signal handler is free to manipulate @tooltip with the therefore
611 * destined function calls.
613 * Whether this signal is emitted is platform-dependent.
614 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
616 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
620 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
621 g_signal_new (I_("query_tooltip"),
622 G_TYPE_FROM_CLASS (gobject_class),
624 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
625 g_signal_accumulator_true_handled, NULL,
626 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
633 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
636 #ifdef GDK_WINDOWING_WIN32
639 build_button_event (GtkStatusIconPrivate *priv,
644 GdkRectangle monitor0;
646 /* We know that gdk/win32 puts the primary monitor at index 0 */
647 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
648 e->window = g_object_ref (gdk_get_default_root_window ());
649 e->send_event = TRUE;
650 e->time = GetTickCount ();
652 priv->last_click_x = e->x = pos.x + monitor0.x;
653 priv->last_click_y = e->y = pos.y + monitor0.y;
657 e->device = gdk_display_get_default ()->core_pointer;
664 GtkStatusIcon *status_icon;
665 GdkEventButton *event;
666 } ButtonCallbackData;
669 button_callback (gpointer data)
671 ButtonCallbackData *bc = (ButtonCallbackData *) data;
673 if (bc->event->type == GDK_BUTTON_PRESS)
674 gtk_status_icon_button_press (bc->status_icon, bc->event);
676 gtk_status_icon_button_release (bc->status_icon, bc->event);
678 gdk_event_free ((GdkEvent *) bc->event);
684 static UINT taskbar_created_msg = 0;
685 static GSList *status_icons = NULL;
687 static LRESULT CALLBACK
693 if (message == taskbar_created_msg)
697 for (rover = status_icons; rover != NULL; rover = rover->next)
699 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
700 GtkStatusIconPrivate *priv = status_icon->priv;
702 priv->nid.hWnd = hwnd;
703 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
704 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
705 priv->nid.uFlags = NIF_MESSAGE;
707 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
709 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
710 priv->nid.hWnd = NULL;
714 gtk_status_icon_update_image (status_icon);
719 if (message == WM_GTK_TRAY_NOTIFICATION)
721 ButtonCallbackData *bc;
739 if (HIWORD (wparam) == XBUTTON1)
745 bc = g_new (ButtonCallbackData, 1);
746 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
747 bc->status_icon = GTK_STATUS_ICON (wparam);
748 build_button_event (bc->status_icon->priv, bc->event, button);
749 g_idle_add (button_callback, bc);
765 if (HIWORD (wparam) == XBUTTON1)
771 bc = g_new (ButtonCallbackData, 1);
772 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
773 bc->status_icon = GTK_STATUS_ICON (wparam);
774 build_button_event (bc->status_icon->priv, bc->event, button);
775 g_idle_add (button_callback, bc);
785 return DefWindowProc (hwnd, message, wparam, lparam);
790 create_tray_observer (void)
793 static HWND hwnd = NULL;
795 HINSTANCE hmodule = GetModuleHandle (NULL);
800 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
802 memset (&wclass, 0, sizeof(WNDCLASS));
803 wclass.lpszClassName = "gtkstatusicon-observer";
804 wclass.lpfnWndProc = wndproc;
805 wclass.hInstance = hmodule;
807 klass = RegisterClass (&wclass);
811 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
813 0, 0, 1, 1, NULL, NULL,
817 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
827 gtk_status_icon_init (GtkStatusIcon *status_icon)
829 GtkStatusIconPrivate *priv;
831 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
832 GtkStatusIconPrivate);
833 status_icon->priv = priv;
835 priv->storage_type = GTK_IMAGE_EMPTY;
836 priv->visible = TRUE;
838 #ifdef GDK_WINDOWING_X11
840 priv->image_width = 0;
841 priv->image_height = 0;
843 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
845 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
846 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
849 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
850 G_CALLBACK (gtk_status_icon_key_press), status_icon);
851 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
852 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
853 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
854 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
855 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
856 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
857 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
858 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
859 g_signal_connect (priv->tray_icon, "notify::error-color",
860 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
861 g_signal_connect (priv->tray_icon, "notify::warning-color",
862 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
863 g_signal_connect (priv->tray_icon, "notify::success-color",
864 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
865 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
866 G_CALLBACK (gtk_status_icon_button_press), status_icon);
867 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
868 G_CALLBACK (gtk_status_icon_button_release), status_icon);
869 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
870 G_CALLBACK (gtk_status_icon_scroll), status_icon);
871 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
872 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
873 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
874 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
875 priv->image = gtk_image_new ();
876 gtk_widget_set_can_focus (priv->image, TRUE);
877 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
878 gtk_widget_show (priv->image);
880 g_signal_connect_swapped (priv->image, "size-allocate",
881 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
885 #ifdef GDK_WINDOWING_WIN32
887 /* Get position and orientation of Windows taskbar. */
891 abd.cbSize = sizeof (abd);
892 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
893 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
894 priv->orientation = GTK_ORIENTATION_VERTICAL;
896 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
899 priv->last_click_x = priv->last_click_y = 0;
901 /* Are the system tray icons always 16 pixels square? */
903 priv->image_width = 16;
904 priv->image_height = 16;
906 priv->dummy_widget = gtk_label_new ("");
908 memset (&priv->nid, 0, sizeof (priv->nid));
910 priv->nid.hWnd = create_tray_observer ();
911 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
912 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
913 priv->nid.uFlags = NIF_MESSAGE;
915 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
917 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
918 priv->nid.hWnd = NULL;
921 status_icons = g_slist_append (status_icons, status_icon);
925 #ifdef GDK_WINDOWING_QUARTZ
926 priv->dummy_widget = gtk_label_new ("");
930 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
932 priv->image_width = priv->image_height = [priv->status_item getHeight];
933 priv->size = priv->image_height;
941 gtk_status_icon_constructor (GType type,
942 guint n_construct_properties,
943 GObjectConstructParam *construct_params)
946 #ifdef GDK_WINDOWING_X11
947 GtkStatusIcon *status_icon;
948 GtkStatusIconPrivate *priv;
951 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
952 n_construct_properties,
955 #ifdef GDK_WINDOWING_X11
956 status_icon = GTK_STATUS_ICON (object);
957 priv = status_icon->priv;
960 gtk_widget_show (priv->tray_icon);
967 gtk_status_icon_finalize (GObject *object)
969 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
970 GtkStatusIconPrivate *priv = status_icon->priv;
972 gtk_status_icon_disable_blinking (status_icon);
974 gtk_status_icon_reset_image_data (status_icon);
976 if (priv->blank_icon)
977 g_object_unref (priv->blank_icon);
978 priv->blank_icon = NULL;
980 #ifdef GDK_WINDOWING_X11
981 g_signal_handlers_disconnect_by_func (priv->tray_icon,
982 gtk_status_icon_key_press, status_icon);
983 g_signal_handlers_disconnect_by_func (priv->tray_icon,
984 gtk_status_icon_popup_menu, status_icon);
985 g_signal_handlers_disconnect_by_func (priv->tray_icon,
986 gtk_status_icon_embedded_changed, status_icon);
987 g_signal_handlers_disconnect_by_func (priv->tray_icon,
988 gtk_status_icon_orientation_changed, status_icon);
989 g_signal_handlers_disconnect_by_func (priv->tray_icon,
990 gtk_status_icon_fg_changed, status_icon);
991 g_signal_handlers_disconnect_by_func (priv->tray_icon,
992 gtk_status_icon_color_changed, status_icon);
993 g_signal_handlers_disconnect_by_func (priv->tray_icon,
994 gtk_status_icon_button_press, status_icon);
995 g_signal_handlers_disconnect_by_func (priv->tray_icon,
996 gtk_status_icon_button_release, status_icon);
997 g_signal_handlers_disconnect_by_func (priv->tray_icon,
998 gtk_status_icon_scroll, status_icon);
999 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1000 gtk_status_icon_query_tooltip, status_icon);
1001 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1002 gtk_status_icon_screen_changed, status_icon);
1003 gtk_widget_destroy (priv->image);
1004 gtk_widget_destroy (priv->tray_icon);
1007 #ifdef GDK_WINDOWING_WIN32
1008 if (priv->nid.hWnd != NULL && priv->visible)
1009 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1010 if (priv->nid.hIcon)
1011 DestroyIcon (priv->nid.hIcon);
1012 g_free (priv->tooltip_text);
1014 gtk_widget_destroy (priv->dummy_widget);
1016 status_icons = g_slist_remove (status_icons, status_icon);
1019 #ifdef GDK_WINDOWING_QUARTZ
1021 [priv->status_item release];
1022 QUARTZ_POOL_RELEASE;
1023 g_free (priv->tooltip_text);
1026 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1030 gtk_status_icon_set_property (GObject *object,
1032 const GValue *value,
1035 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1040 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1043 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1046 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1048 case PROP_ICON_NAME:
1049 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1052 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1055 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1058 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
1061 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1063 case PROP_HAS_TOOLTIP:
1064 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1066 case PROP_TOOLTIP_TEXT:
1067 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1069 case PROP_TOOLTIP_MARKUP:
1070 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1073 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1076 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1082 gtk_status_icon_get_property (GObject *object,
1087 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1088 GtkStatusIconPrivate *priv = status_icon->priv;
1090 /* The "getter" functions whine if you try to get the wrong
1091 * storage type. This function is instead robust against that,
1092 * so that GUI builders don't have to jump through hoops
1093 * to avoid g_warning
1099 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1100 g_value_set_object (value, NULL);
1102 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1105 if (priv->storage_type != GTK_IMAGE_STOCK)
1106 g_value_set_string (value, NULL);
1108 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1110 case PROP_ICON_NAME:
1111 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1112 g_value_set_string (value, NULL);
1114 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1117 if (priv->storage_type != GTK_IMAGE_GICON)
1118 g_value_set_object (value, NULL);
1120 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1122 case PROP_STORAGE_TYPE:
1123 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1126 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1129 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1132 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
1135 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1138 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1140 case PROP_ORIENTATION:
1141 #ifdef GDK_WINDOWING_X11
1142 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1144 #ifdef GDK_WINDOWING_WIN32
1145 g_value_set_enum (value, status_icon->priv->orientation);
1148 case PROP_HAS_TOOLTIP:
1149 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1151 case PROP_TOOLTIP_TEXT:
1152 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1154 case PROP_TOOLTIP_MARKUP:
1155 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1158 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1167 * gtk_status_icon_new:
1169 * Creates an empty status icon object.
1171 * Return value: a new #GtkStatusIcon
1176 gtk_status_icon_new (void)
1178 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1182 * gtk_status_icon_new_from_pixbuf:
1183 * @pixbuf: a #GdkPixbuf
1185 * Creates a status icon displaying @pixbuf.
1187 * The image will be scaled down to fit in the available
1188 * space in the notification area, if necessary.
1190 * Return value: a new #GtkStatusIcon
1195 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1197 return g_object_new (GTK_TYPE_STATUS_ICON,
1203 * gtk_status_icon_new_from_file:
1204 * @filename: a filename
1206 * Creates a status icon displaying the file @filename.
1208 * The image will be scaled down to fit in the available
1209 * space in the notification area, if necessary.
1211 * Return value: a new #GtkStatusIcon
1216 gtk_status_icon_new_from_file (const gchar *filename)
1218 return g_object_new (GTK_TYPE_STATUS_ICON,
1224 * gtk_status_icon_new_from_stock:
1225 * @stock_id: a stock icon id
1227 * Creates a status icon displaying a stock icon. Sample stock icon
1228 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1229 * own stock icon names, see gtk_icon_factory_add_default() and
1230 * gtk_icon_factory_add().
1232 * Return value: a new #GtkStatusIcon
1237 gtk_status_icon_new_from_stock (const gchar *stock_id)
1239 return g_object_new (GTK_TYPE_STATUS_ICON,
1245 * gtk_status_icon_new_from_icon_name:
1246 * @icon_name: an icon name
1248 * Creates a status icon displaying an icon from the current icon theme.
1249 * If the current icon theme is changed, the icon will be updated
1252 * Return value: a new #GtkStatusIcon
1257 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1259 return g_object_new (GTK_TYPE_STATUS_ICON,
1260 "icon-name", icon_name,
1265 * gtk_status_icon_new_from_gicon:
1268 * Creates a status icon displaying a #GIcon. If the icon is a
1269 * themed icon, it will be updated when the theme changes.
1271 * Return value: a new #GtkStatusIcon
1276 gtk_status_icon_new_from_gicon (GIcon *icon)
1278 return g_object_new (GTK_TYPE_STATUS_ICON,
1284 emit_activate_signal (GtkStatusIcon *status_icon)
1286 g_signal_emit (status_icon,
1287 status_icon_signals [ACTIVATE_SIGNAL], 0);
1291 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1293 guint32 activate_time)
1295 g_signal_emit (status_icon,
1296 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1301 #ifdef GDK_WINDOWING_X11
1304 emit_size_changed_signal (GtkStatusIcon *status_icon,
1307 gboolean handled = FALSE;
1309 g_signal_emit (status_icon,
1310 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1320 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
1322 GtkStatusIconPrivate *priv = status_icon->priv;
1324 if (priv->blank_icon)
1328 width = gdk_pixbuf_get_width (priv->blank_icon);
1329 height = gdk_pixbuf_get_height (priv->blank_icon);
1332 if (width == priv->image_width && height == priv->image_height)
1333 return priv->blank_icon;
1336 g_object_unref (priv->blank_icon);
1337 priv->blank_icon = NULL;
1341 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
1343 priv->image_height);
1344 if (priv->blank_icon)
1345 gdk_pixbuf_fill (priv->blank_icon, 0);
1347 return priv->blank_icon;
1350 #ifdef GDK_WINDOWING_X11
1353 find_icon_size (GtkWidget *widget,
1357 GtkSettings *settings;
1358 GtkIconSize s, size;
1361 screen = gtk_widget_get_screen (widget);
1364 return GTK_ICON_SIZE_MENU;
1366 settings = gtk_settings_get_for_screen (screen);
1369 size = GTK_ICON_SIZE_MENU;
1371 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1373 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1374 w <= pixel_size && h <= pixel_size)
1376 d = MAX (pixel_size - w, pixel_size - h);
1391 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1393 GtkStatusIconPrivate *priv = status_icon->priv;
1394 #ifdef GDK_WINDOWING_WIN32
1398 if (priv->blink_off)
1400 #ifdef GDK_WINDOWING_X11
1401 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
1402 gtk_status_icon_blank_icon (status_icon));
1404 #ifdef GDK_WINDOWING_WIN32
1405 prev_hicon = priv->nid.hIcon;
1406 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
1407 priv->nid.uFlags |= NIF_ICON;
1408 if (priv->nid.hWnd != NULL && priv->visible)
1409 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1410 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1412 DestroyIcon (prev_hicon);
1414 #ifdef GDK_WINDOWING_QUARTZ
1416 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
1417 QUARTZ_POOL_RELEASE;
1422 switch (priv->storage_type)
1424 case GTK_IMAGE_PIXBUF:
1428 pixbuf = priv->image_data.pixbuf;
1439 width = gdk_pixbuf_get_width (pixbuf);
1440 height = gdk_pixbuf_get_height (pixbuf);
1442 if (width > size || height > size)
1443 scaled = gdk_pixbuf_scale_simple (pixbuf,
1446 GDK_INTERP_BILINEAR);
1448 scaled = g_object_ref (pixbuf);
1450 #ifdef GDK_WINDOWING_X11
1451 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1453 #ifdef GDK_WINDOWING_WIN32
1454 prev_hicon = priv->nid.hIcon;
1455 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1456 priv->nid.uFlags |= NIF_ICON;
1457 if (priv->nid.hWnd != NULL && priv->visible)
1458 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1459 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1461 DestroyIcon (prev_hicon);
1463 #ifdef GDK_WINDOWING_QUARTZ
1465 [priv->status_item setImage:scaled];
1466 QUARTZ_POOL_RELEASE;
1469 g_object_unref (scaled);
1473 #ifdef GDK_WINDOWING_X11
1474 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1476 #ifdef GDK_WINDOWING_WIN32
1477 priv->nid.uFlags &= ~NIF_ICON;
1478 if (priv->nid.hWnd != NULL && priv->visible)
1479 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1480 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1482 #ifdef GDK_WINDOWING_QUARTZ
1483 [priv->status_item setImage:NULL];
1489 case GTK_IMAGE_STOCK:
1491 #ifdef GDK_WINDOWING_X11
1492 GtkIconSize size = find_icon_size (priv->image, priv->size);
1493 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1494 priv->image_data.stock_id,
1497 #ifdef GDK_WINDOWING_WIN32
1500 gtk_widget_render_icon (priv->dummy_widget,
1501 priv->image_data.stock_id,
1502 GTK_ICON_SIZE_SMALL_TOOLBAR,
1505 prev_hicon = priv->nid.hIcon;
1506 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1507 priv->nid.uFlags |= NIF_ICON;
1508 if (priv->nid.hWnd != NULL && priv->visible)
1509 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1510 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1512 DestroyIcon (prev_hicon);
1513 g_object_unref (pixbuf);
1516 #ifdef GDK_WINDOWING_QUARTZ
1520 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1521 priv->image_data.stock_id,
1522 GTK_ICON_SIZE_SMALL_TOOLBAR,
1525 [priv->status_item setImage:pixbuf];
1526 QUARTZ_POOL_RELEASE;
1527 g_object_unref (pixbuf);
1533 case GTK_IMAGE_ICON_NAME:
1535 #ifdef GDK_WINDOWING_X11
1536 GtkIconSize size = find_icon_size (priv->image, priv->size);
1537 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1538 priv->image_data.icon_name,
1541 #ifdef GDK_WINDOWING_WIN32
1544 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1545 priv->image_data.icon_name,
1549 prev_hicon = priv->nid.hIcon;
1550 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1551 priv->nid.uFlags |= NIF_ICON;
1552 if (priv->nid.hWnd != NULL && priv->visible)
1553 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1554 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1556 DestroyIcon (prev_hicon);
1557 g_object_unref (pixbuf);
1560 #ifdef GDK_WINDOWING_QUARTZ
1564 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1565 priv->image_data.icon_name,
1570 [priv->status_item setImage:pixbuf];
1571 QUARTZ_POOL_RELEASE;
1572 g_object_unref (pixbuf);
1579 case GTK_IMAGE_GICON:
1581 #ifdef GDK_WINDOWING_X11
1582 GtkIconSize size = find_icon_size (priv->image, priv->size);
1583 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1584 priv->image_data.gicon,
1587 #ifdef GDK_WINDOWING_WIN32
1590 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1591 priv->image_data.gicon,
1594 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1596 prev_hicon = priv->nid.hIcon;
1597 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1598 priv->nid.uFlags |= NIF_ICON;
1599 if (priv->nid.hWnd != NULL && priv->visible)
1600 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1601 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1603 DestroyIcon (prev_hicon);
1604 g_object_unref (pixbuf);
1607 #ifdef GDK_WINDOWING_QUARTZ
1610 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1611 priv->image_data.gicon,
1614 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1617 [priv->status_item setImage:pixbuf];
1618 QUARTZ_POOL_RELEASE;
1619 g_object_unref (pixbuf);
1626 case GTK_IMAGE_EMPTY:
1627 #ifdef GDK_WINDOWING_X11
1628 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1630 #ifdef GDK_WINDOWING_WIN32
1631 priv->nid.uFlags &= ~NIF_ICON;
1632 if (priv->nid.hWnd != NULL && priv->visible)
1633 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1634 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1636 #ifdef GDK_WINDOWING_QUARTZ
1639 [priv->status_item setImage:NULL];
1640 QUARTZ_POOL_RELEASE;
1645 g_assert_not_reached ();
1650 #ifdef GDK_WINDOWING_X11
1653 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1654 GtkAllocation *allocation)
1656 GtkStatusIconPrivate *priv = status_icon->priv;
1657 GtkOrientation orientation;
1660 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1662 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1663 size = allocation->height;
1665 size = allocation->width;
1667 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1668 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1670 if (priv->size != size)
1674 g_object_notify (G_OBJECT (status_icon), "size");
1676 if (!emit_size_changed_signal (status_icon, size))
1677 gtk_status_icon_update_image (status_icon);
1682 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1683 GdkScreen *old_screen)
1685 GtkStatusIconPrivate *priv = status_icon->priv;
1687 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1689 g_object_notify (G_OBJECT (status_icon), "screen");
1695 #ifdef GDK_WINDOWING_X11
1698 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1700 g_object_notify (G_OBJECT (status_icon), "embedded");
1704 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1706 g_object_notify (G_OBJECT (status_icon), "orientation");
1710 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1712 GtkStatusIconPrivate *priv = status_icon->priv;
1715 g_object_get (priv->tray_icon, "fg-color", &color, NULL);
1716 gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
1720 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1722 GtkStatusIcon *status_icon)
1724 GtkStatusIconPrivate *priv = status_icon->priv;
1728 switch (pspec->name[0])
1746 g_object_get (priv->tray_icon, pspec->name, &color, NULL);
1747 gtk_widget_modify_symbolic_color (priv->image, name, &color);
1752 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1755 guint state, keyval;
1757 state = event->state & gtk_accelerator_get_default_mod_mask ();
1758 keyval = event->keyval;
1760 (keyval == GDK_Return ||
1761 keyval == GDK_KP_Enter ||
1762 keyval == GDK_ISO_Enter ||
1763 keyval == GDK_space ||
1764 keyval == GDK_KP_Space))
1766 emit_activate_signal (status_icon);
1774 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1776 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1782 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1783 GdkEventButton *event)
1785 gboolean handled = FALSE;
1787 g_signal_emit (status_icon,
1788 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1793 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1795 emit_activate_signal (status_icon);
1798 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1800 emit_popup_menu_signal (status_icon, event->button, event->time);
1808 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1809 GdkEventButton *event)
1811 gboolean handled = FALSE;
1812 g_signal_emit (status_icon,
1813 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1818 #ifdef GDK_WINDOWING_X11
1820 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1821 GdkEventScroll *event)
1823 gboolean handled = FALSE;
1824 g_signal_emit (status_icon,
1825 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1831 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1834 gboolean keyboard_tip,
1835 GtkTooltip *tooltip)
1837 gboolean handled = FALSE;
1838 g_signal_emit (status_icon,
1839 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1840 x, y, keyboard_tip, tooltip, &handled);
1843 #endif /* GDK_WINDOWING_X11 */
1846 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1848 GtkStatusIconPrivate *priv = status_icon->priv;
1850 switch (priv->storage_type)
1852 case GTK_IMAGE_PIXBUF:
1853 if (priv->image_data.pixbuf)
1854 g_object_unref (priv->image_data.pixbuf);
1855 priv->image_data.pixbuf = NULL;
1856 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1859 case GTK_IMAGE_STOCK:
1860 g_free (priv->image_data.stock_id);
1861 priv->image_data.stock_id = NULL;
1863 g_object_notify (G_OBJECT (status_icon), "stock");
1866 case GTK_IMAGE_ICON_NAME:
1867 g_free (priv->image_data.icon_name);
1868 priv->image_data.icon_name = NULL;
1870 g_object_notify (G_OBJECT (status_icon), "icon-name");
1873 case GTK_IMAGE_GICON:
1874 if (priv->image_data.gicon)
1875 g_object_unref (priv->image_data.gicon);
1876 priv->image_data.gicon = NULL;
1878 g_object_notify (G_OBJECT (status_icon), "gicon");
1881 case GTK_IMAGE_EMPTY:
1884 g_assert_not_reached ();
1888 priv->storage_type = GTK_IMAGE_EMPTY;
1889 g_object_notify (G_OBJECT (status_icon), "storage-type");
1893 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1894 GtkImageType storage_type,
1897 GtkStatusIconPrivate *priv = status_icon->priv;
1899 g_object_freeze_notify (G_OBJECT (status_icon));
1901 gtk_status_icon_reset_image_data (status_icon);
1903 priv->storage_type = storage_type;
1904 g_object_notify (G_OBJECT (status_icon), "storage-type");
1906 switch (storage_type)
1908 case GTK_IMAGE_PIXBUF:
1909 priv->image_data.pixbuf = (GdkPixbuf *)data;
1910 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1912 case GTK_IMAGE_STOCK:
1913 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1914 g_object_notify (G_OBJECT (status_icon), "stock");
1916 case GTK_IMAGE_ICON_NAME:
1917 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1918 g_object_notify (G_OBJECT (status_icon), "icon-name");
1920 case GTK_IMAGE_GICON:
1921 priv->image_data.gicon = (GIcon *)data;
1922 g_object_notify (G_OBJECT (status_icon), "gicon");
1925 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1928 g_object_thaw_notify (G_OBJECT (status_icon));
1930 gtk_status_icon_update_image (status_icon);
1934 * gtk_status_icon_set_from_pixbuf:
1935 * @status_icon: a #GtkStatusIcon
1936 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1938 * Makes @status_icon display @pixbuf.
1939 * See gtk_status_icon_new_from_pixbuf() for details.
1944 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1947 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1948 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1951 g_object_ref (pixbuf);
1953 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1958 * gtk_status_icon_set_from_file:
1959 * @status_icon: a #GtkStatusIcon
1960 * @filename: a filename
1962 * Makes @status_icon display the file @filename.
1963 * See gtk_status_icon_new_from_file() for details.
1968 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1969 const gchar *filename)
1973 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1974 g_return_if_fail (filename != NULL);
1976 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1978 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1981 g_object_unref (pixbuf);
1985 * gtk_status_icon_set_from_stock:
1986 * @status_icon: a #GtkStatusIcon
1987 * @stock_id: a stock icon id
1989 * Makes @status_icon display the stock icon with the id @stock_id.
1990 * See gtk_status_icon_new_from_stock() for details.
1995 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1996 const gchar *stock_id)
1998 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1999 g_return_if_fail (stock_id != NULL);
2001 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
2002 (gpointer) stock_id);
2006 * gtk_status_icon_set_from_icon_name:
2007 * @status_icon: a #GtkStatusIcon
2008 * @icon_name: an icon name
2010 * Makes @status_icon display the icon named @icon_name from the
2011 * current icon theme.
2012 * See gtk_status_icon_new_from_icon_name() for details.
2017 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
2018 const gchar *icon_name)
2020 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2021 g_return_if_fail (icon_name != NULL);
2023 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
2024 (gpointer) icon_name);
2028 * gtk_status_icon_set_from_gicon:
2029 * @status_icon: a #GtkStatusIcon
2032 * Makes @status_icon display the #GIcon.
2033 * See gtk_status_icon_new_from_gicon() for details.
2038 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
2041 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2042 g_return_if_fail (icon != NULL);
2045 g_object_ref (icon);
2047 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
2052 * gtk_status_icon_get_storage_type:
2053 * @status_icon: a #GtkStatusIcon
2055 * Gets the type of representation being used by the #GtkStatusIcon
2056 * to store image data. If the #GtkStatusIcon has no image data,
2057 * the return value will be %GTK_IMAGE_EMPTY.
2059 * Return value: the image representation being used
2064 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2066 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2068 return status_icon->priv->storage_type;
2071 * gtk_status_icon_get_pixbuf:
2072 * @status_icon: a #GtkStatusIcon
2074 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2075 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2076 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2077 * The caller of this function does not own a reference to the
2080 * Return value: the displayed pixbuf, or %NULL if the image is empty.
2085 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2087 GtkStatusIconPrivate *priv;
2089 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2091 priv = status_icon->priv;
2093 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2094 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2096 if (priv->storage_type == GTK_IMAGE_EMPTY)
2097 priv->image_data.pixbuf = NULL;
2099 return priv->image_data.pixbuf;
2103 * gtk_status_icon_get_stock:
2104 * @status_icon: a #GtkStatusIcon
2106 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2107 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2108 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2109 * The returned string is owned by the #GtkStatusIcon and should not
2110 * be freed or modified.
2112 * Return value: stock id of the displayed stock icon,
2113 * or %NULL if the image is empty.
2117 G_CONST_RETURN gchar *
2118 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2120 GtkStatusIconPrivate *priv;
2122 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2124 priv = status_icon->priv;
2126 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2127 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2129 if (priv->storage_type == GTK_IMAGE_EMPTY)
2130 priv->image_data.stock_id = NULL;
2132 return priv->image_data.stock_id;
2136 * gtk_status_icon_get_icon_name:
2137 * @status_icon: a #GtkStatusIcon
2139 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2140 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2141 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2142 * The returned string is owned by the #GtkStatusIcon and should not
2143 * be freed or modified.
2145 * Return value: name of the displayed icon, or %NULL if the image is empty.
2149 G_CONST_RETURN gchar *
2150 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2152 GtkStatusIconPrivate *priv;
2154 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2156 priv = status_icon->priv;
2158 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2159 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2161 if (priv->storage_type == GTK_IMAGE_EMPTY)
2162 priv->image_data.icon_name = NULL;
2164 return priv->image_data.icon_name;
2168 * gtk_status_icon_get_gicon:
2169 * @status_icon: a #GtkStatusIcon
2171 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2172 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2173 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2174 * The caller of this function does not own a reference to the
2177 * If this function fails, @icon is left unchanged;
2179 * Returns: the displayed icon, or %NULL if the image is empty
2184 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2186 GtkStatusIconPrivate *priv;
2188 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2190 priv = status_icon->priv;
2192 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2193 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2195 if (priv->storage_type == GTK_IMAGE_EMPTY)
2196 priv->image_data.gicon = NULL;
2198 return priv->image_data.gicon;
2202 * gtk_status_icon_get_size:
2203 * @status_icon: a #GtkStatusIcon
2205 * Gets the size in pixels that is available for the image.
2206 * Stock icons and named icons adapt their size automatically
2207 * if the size of the notification area changes. For other
2208 * storage types, the size-changed signal can be used to
2209 * react to size changes.
2211 * Note that the returned size is only meaningful while the
2212 * status icon is embedded (see gtk_status_icon_is_embedded()).
2214 * Return value: the size that is available for the image
2219 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2221 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2223 return status_icon->priv->size;
2227 * gtk_status_icon_set_screen:
2228 * @status_icon: a #GtkStatusIcon
2229 * @screen: a #GdkScreen
2231 * Sets the #GdkScreen where @status_icon is displayed; if
2232 * the icon is already mapped, it will be unmapped, and
2233 * then remapped on the new screen.
2238 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2241 g_return_if_fail (GDK_IS_SCREEN (screen));
2243 #ifdef GDK_WINDOWING_X11
2244 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2249 * gtk_status_icon_get_screen:
2250 * @status_icon: a #GtkStatusIcon
2252 * Returns the #GdkScreen associated with @status_icon.
2254 * Return value: a #GdkScreen.
2259 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2261 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2263 #ifdef GDK_WINDOWING_X11
2264 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2266 return gdk_screen_get_default ();
2271 * gtk_status_icon_set_tooltip:
2272 * @status_icon: a #GtkStatusIcon
2273 * @tooltip_text: (allow-none): the tooltip text, or %NULL
2275 * Sets the tooltip of the status icon.
2279 * Deprecated: 2.16: Use gtk_status_icon_set_tooltip_text() instead.
2282 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
2283 const gchar *tooltip_text)
2285 gtk_status_icon_set_tooltip_text (status_icon, tooltip_text);
2289 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
2291 GtkStatusIconPrivate *priv = status_icon->priv;
2293 priv->blink_off = !priv->blink_off;
2295 gtk_status_icon_update_image (status_icon);
2301 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
2303 GtkStatusIconPrivate *priv = status_icon->priv;
2305 if (!priv->blinking_timeout)
2307 gtk_status_icon_blinker (status_icon);
2309 priv->blinking_timeout =
2310 gdk_threads_add_timeout (BLINK_TIMEOUT,
2311 (GSourceFunc) gtk_status_icon_blinker,
2317 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
2319 GtkStatusIconPrivate *priv = status_icon->priv;
2321 if (priv->blinking_timeout)
2323 g_source_remove (priv->blinking_timeout);
2324 priv->blinking_timeout = 0;
2325 priv->blink_off = FALSE;
2327 gtk_status_icon_update_image (status_icon);
2332 * gtk_status_icon_set_visible:
2333 * @status_icon: a #GtkStatusIcon
2334 * @visible: %TRUE to show the status icon, %FALSE to hide it
2336 * Shows or hides a status icon.
2341 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2344 GtkStatusIconPrivate *priv;
2346 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2348 priv = status_icon->priv;
2350 visible = visible != FALSE;
2352 if (priv->visible != visible)
2354 priv->visible = visible;
2356 #ifdef GDK_WINDOWING_X11
2358 gtk_widget_show (priv->tray_icon);
2359 else if (gtk_widget_get_realized (priv->tray_icon))
2361 gtk_widget_hide (priv->tray_icon);
2362 gtk_widget_unrealize (priv->tray_icon);
2365 #ifdef GDK_WINDOWING_WIN32
2366 if (priv->nid.hWnd != NULL)
2369 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2371 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2374 #ifdef GDK_WINDOWING_QUARTZ
2376 [priv->status_item setVisible:visible];
2377 QUARTZ_POOL_RELEASE;
2379 g_object_notify (G_OBJECT (status_icon), "visible");
2384 * gtk_status_icon_get_visible:
2385 * @status_icon: a #GtkStatusIcon
2387 * Returns whether the status icon is visible or not.
2388 * Note that being visible does not guarantee that
2389 * the user can actually see the icon, see also
2390 * gtk_status_icon_is_embedded().
2392 * Return value: %TRUE if the status icon is visible
2397 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2399 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2401 return status_icon->priv->visible;
2405 * gtk_status_icon_set_blinking:
2406 * @status_icon: a #GtkStatusIcon
2407 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
2409 * Makes the status icon start or stop blinking.
2410 * Note that blinking user interface elements may be problematic
2411 * for some users, and thus may be turned off, in which case
2412 * this setting has no effect.
2417 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
2420 GtkStatusIconPrivate *priv;
2422 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2424 priv = status_icon->priv;
2426 blinking = blinking != FALSE;
2428 if (priv->blinking != blinking)
2430 priv->blinking = blinking;
2433 gtk_status_icon_enable_blinking (status_icon);
2435 gtk_status_icon_disable_blinking (status_icon);
2437 g_object_notify (G_OBJECT (status_icon), "blinking");
2442 * gtk_status_icon_get_blinking:
2443 * @status_icon: a #GtkStatusIcon
2445 * Returns whether the icon is blinking, see
2446 * gtk_status_icon_set_blinking().
2448 * Return value: %TRUE if the icon is blinking
2453 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
2455 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2457 return status_icon->priv->blinking;
2461 * gtk_status_icon_is_embedded:
2462 * @status_icon: a #GtkStatusIcon
2464 * Returns whether the status icon is embedded in a notification
2467 * Return value: %TRUE if the status icon is embedded in
2468 * a notification area.
2473 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2475 #ifdef GDK_WINDOWING_X11
2479 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2481 #ifdef GDK_WINDOWING_X11
2482 plug = GTK_PLUG (status_icon->priv->tray_icon);
2484 if (plug->socket_window)
2489 #ifdef GDK_WINDOWING_WIN32
2492 #ifdef GDK_WINDOWING_QUARTZ
2498 * gtk_status_icon_position_menu:
2499 * @menu: the #GtkMenu
2500 * @x: return location for the x position
2501 * @y: return location for the y position
2502 * @push_in: whether the first menu item should be offset (pushed in) to be
2503 * aligned with the menu popup position (only useful for GtkOptionMenu).
2504 * @user_data: the status icon to position the menu on
2506 * Menu positioning function to use with gtk_menu_popup()
2507 * to position @menu aligned to the status icon @user_data.
2512 gtk_status_icon_position_menu (GtkMenu *menu,
2518 #ifdef GDK_WINDOWING_X11
2519 GtkStatusIcon *status_icon;
2520 GtkStatusIconPrivate *priv;
2521 GtkTrayIcon *tray_icon;
2524 GtkTextDirection direction;
2525 GtkRequisition menu_req;
2526 GdkRectangle monitor;
2527 gint monitor_num, height, width, xoffset, yoffset;
2529 g_return_if_fail (GTK_IS_MENU (menu));
2530 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2532 status_icon = GTK_STATUS_ICON (user_data);
2533 priv = status_icon->priv;
2534 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2535 widget = priv->tray_icon;
2537 direction = gtk_widget_get_direction (widget);
2539 screen = gtk_widget_get_screen (widget);
2540 gtk_menu_set_screen (menu, screen);
2542 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
2543 if (monitor_num < 0)
2545 gtk_menu_set_monitor (menu, monitor_num);
2547 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2549 gdk_window_get_origin (widget->window, x, y);
2551 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2553 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2556 height = widget->allocation.height;
2557 xoffset = widget->allocation.width;
2562 width = widget->allocation.width;
2565 yoffset = widget->allocation.height;
2568 if (direction == GTK_TEXT_DIR_RTL)
2570 if ((*x - (menu_req.width - width)) >= monitor.x)
2571 *x -= menu_req.width - width;
2572 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2574 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2575 *x -= menu_req.width - width;
2581 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2583 else if ((*x - (menu_req.width - width)) >= monitor.x)
2584 *x -= menu_req.width - width;
2585 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2588 *x -= menu_req.width - width;
2591 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2593 else if ((*y - (menu_req.height - height)) >= monitor.y)
2594 *y -= menu_req.height - height;
2595 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2598 *y -= menu_req.height - height;
2601 #endif /* GDK_WINDOWING_X11 */
2603 #ifdef GDK_WINDOWING_WIN32
2604 GtkStatusIcon *status_icon;
2605 GtkStatusIconPrivate *priv;
2607 g_return_if_fail (GTK_IS_MENU (menu));
2608 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2610 status_icon = GTK_STATUS_ICON (user_data);
2611 priv = status_icon->priv;
2613 *x = priv->last_click_x;
2614 *y = priv->last_click_y;
2620 * gtk_status_icon_get_geometry:
2621 * @status_icon: a #GtkStatusIcon
2622 * @screen: (out) (transfer none) (allow-none): return location for the screen, or %NULL if the
2623 * information is not needed
2624 * @area: (out) (allow-none): return location for the area occupied by the status
2626 * @orientation: (out) (allow-none): return location for the orientation of the panel
2627 * in which the status icon is embedded, or %NULL. A panel
2628 * at the top or bottom of the screen is horizontal, a panel
2629 * at the left or right is vertical.
2631 * Obtains information about the location of the status icon
2632 * on screen. This information can be used to e.g. position
2633 * popups like notification bubbles.
2635 * See gtk_status_icon_position_menu() for a more convenient
2636 * alternative for positioning menus.
2638 * Note that some platforms do not allow GTK+ to provide
2639 * this information, and even on platforms that do allow it,
2640 * the information is not reliable unless the status icon
2641 * is embedded in a notification area, see
2642 * gtk_status_icon_is_embedded().
2644 * Return value: %TRUE if the location information has
2650 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2653 GtkOrientation *orientation)
2655 #ifdef GDK_WINDOWING_X11
2657 GtkStatusIconPrivate *priv;
2660 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2662 priv = status_icon->priv;
2663 widget = priv->tray_icon;
2666 *screen = gtk_widget_get_screen (widget);
2670 gdk_window_get_origin (widget->window, &x, &y);
2673 area->width = widget->allocation.width;
2674 area->height = widget->allocation.height;
2678 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2683 #endif /* GDK_WINDOWING_X11 */
2687 * gtk_status_icon_set_has_tooltip:
2688 * @status_icon: a #GtkStatusIcon
2689 * @has_tooltip: whether or not @status_icon has a tooltip
2691 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2692 * See #GtkStatusIcon:has-tooltip for more information.
2697 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2698 gboolean has_tooltip)
2700 GtkStatusIconPrivate *priv;
2702 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2704 priv = status_icon->priv;
2706 #ifdef GDK_WINDOWING_X11
2707 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2709 #ifdef GDK_WINDOWING_WIN32
2710 if (!has_tooltip && priv->tooltip_text)
2711 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2713 #ifdef GDK_WINDOWING_QUARTZ
2714 if (!has_tooltip && priv->tooltip_text)
2715 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2720 * gtk_status_icon_get_has_tooltip:
2721 * @status_icon: a #GtkStatusIcon
2723 * Returns the current value of the has-tooltip property.
2724 * See #GtkStatusIcon:has-tooltip for more information.
2726 * Return value: current value of has-tooltip on @status_icon.
2731 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2733 GtkStatusIconPrivate *priv;
2734 gboolean has_tooltip = FALSE;
2736 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2738 priv = status_icon->priv;
2740 #ifdef GDK_WINDOWING_X11
2741 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2743 #ifdef GDK_WINDOWING_WIN32
2744 has_tooltip = (priv->tooltip_text != NULL);
2746 #ifdef GDK_WINDOWING_QUARTZ
2747 has_tooltip = (priv->tooltip_text != NULL);
2754 * gtk_status_icon_set_tooltip_text:
2755 * @status_icon: a #GtkStatusIcon
2756 * @text: the contents of the tooltip for @status_icon
2758 * Sets @text as the contents of the tooltip.
2760 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2761 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2764 * See also the #GtkStatusIcon:tooltip-text property and
2765 * gtk_tooltip_set_text().
2770 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2773 GtkStatusIconPrivate *priv;
2775 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2777 priv = status_icon->priv;
2779 #ifdef GDK_WINDOWING_X11
2781 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2784 #ifdef GDK_WINDOWING_WIN32
2786 priv->nid.uFlags &= ~NIF_TIP;
2789 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2791 priv->nid.uFlags |= NIF_TIP;
2792 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2793 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2796 if (priv->nid.hWnd != NULL && priv->visible)
2797 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2798 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2800 g_free (priv->tooltip_text);
2801 priv->tooltip_text = g_strdup (text);
2803 #ifdef GDK_WINDOWING_QUARTZ
2805 [priv->status_item setToolTip:text];
2806 QUARTZ_POOL_RELEASE;
2808 g_free (priv->tooltip_text);
2809 priv->tooltip_text = g_strdup (text);
2814 * gtk_status_icon_get_tooltip_text:
2815 * @status_icon: a #GtkStatusIcon
2817 * Gets the contents of the tooltip for @status_icon.
2819 * Return value: the tooltip text, or %NULL. You should free the
2820 * returned string with g_free() when done.
2825 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2827 GtkStatusIconPrivate *priv;
2828 gchar *tooltip_text = NULL;
2830 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2832 priv = status_icon->priv;
2834 #ifdef GDK_WINDOWING_X11
2835 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2837 #ifdef GDK_WINDOWING_WIN32
2838 if (priv->tooltip_text)
2839 tooltip_text = g_strdup (priv->tooltip_text);
2841 #ifdef GDK_WINDOWING_QUARTZ
2842 if (priv->tooltip_text)
2843 tooltip_text = g_strdup (priv->tooltip_text);
2846 return tooltip_text;
2850 * gtk_status_icon_set_tooltip_markup:
2851 * @status_icon: a #GtkStatusIcon
2852 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2854 * Sets @markup as the contents of the tooltip, which is marked up with
2855 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2857 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2858 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2860 * See also the #GtkStatusIcon:tooltip-markup property and
2861 * gtk_tooltip_set_markup().
2866 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2867 const gchar *markup)
2869 GtkStatusIconPrivate *priv;
2870 #ifndef GDK_WINDOWING_X11
2874 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2876 priv = status_icon->priv;
2878 #ifdef GDK_WINDOWING_X11
2879 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2881 #ifdef GDK_WINDOWING_WIN32
2883 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2884 gtk_status_icon_set_tooltip_text (status_icon, text);
2887 #ifdef GDK_WINDOWING_QUARTZ
2889 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2890 gtk_status_icon_set_tooltip_text (status_icon, text);
2896 * gtk_status_icon_get_tooltip_markup:
2897 * @status_icon: a #GtkStatusIcon
2899 * Gets the contents of the tooltip for @status_icon.
2901 * Return value: the tooltip text, or %NULL. You should free the
2902 * returned string with g_free() when done.
2907 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2909 GtkStatusIconPrivate *priv;
2910 gchar *markup = NULL;
2912 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2914 priv = status_icon->priv;
2916 #ifdef GDK_WINDOWING_X11
2917 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2919 #ifdef GDK_WINDOWING_WIN32
2920 if (priv->tooltip_text)
2921 markup = g_markup_escape_text (priv->tooltip_text, -1);
2923 #ifdef GDK_WINDOWING_QUARTZ
2924 if (priv->tooltip_text)
2925 markup = g_markup_escape_text (priv->tooltip_text, -1);
2932 * gtk_status_icon_get_x11_window_id:
2933 * @status_icon: a #GtkStatusIcon
2935 * This function is only useful on the X11/freedesktop.org platform.
2936 * It returns a window ID for the widget in the underlying
2937 * status icon implementation. This is useful for the Galago
2938 * notification service, which can send a window ID in the protocol
2939 * in order for the server to position notification windows
2940 * pointing to a status icon reliably.
2942 * This function is not intended for other use cases which are
2943 * more likely to be met by one of the non-X11 specific methods, such
2944 * as gtk_status_icon_position_menu().
2946 * Return value: An 32 bit unsigned integer identifier for the
2947 * underlying X11 Window
2952 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2954 #ifdef GDK_WINDOWING_X11
2955 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2956 return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
2963 * gtk_status_icon_set_title:
2964 * @status_icon: a #GtkStatusIcon
2967 * Sets the title of this tray icon.
2968 * This should be a short, human-readable, localized string
2969 * describing the tray icon. It may be used by tools like screen
2970 * readers to render the tray icon.
2975 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2978 GtkStatusIconPrivate *priv;
2980 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2982 priv = status_icon->priv;
2984 #ifdef GDK_WINDOWING_X11
2985 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2987 #ifdef GDK_WINDOWING_QUARTZ
2988 g_free (priv->title);
2989 priv->title = g_strdup (title);
2991 #ifdef GDK_WINDOWING_WIN32
2992 g_free (priv->title);
2993 priv->title = g_strdup (title);
2996 g_object_notify (G_OBJECT (status_icon), "title");
3000 * gtk_status_icon_get_title:
3001 * @status_icon: a #GtkStatusIcon
3003 * Gets the title of this tray icon. See gtk_status_icon_set_title().
3005 * Returns: the title of the status icon
3009 G_CONST_RETURN gchar *
3010 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
3012 GtkStatusIconPrivate *priv;
3014 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
3016 priv = status_icon->priv;
3018 #ifdef GDK_WINDOWING_X11
3019 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
3021 #ifdef GDK_WINDOWING_QUARTZ
3024 #ifdef GDK_WINDOWING_WIN32
3031 * gtk_status_icon_set_name:
3032 * @status_icon: a #GtkStatusIcon
3035 * Sets the name of this tray icon.
3036 * This should be a string identifying this icon. It is may be
3037 * used for sorting the icons in the tray and will not be shown to
3043 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
3046 GtkStatusIconPrivate *priv;
3048 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
3050 priv = status_icon->priv;
3052 #ifdef GDK_WINDOWING_X11
3053 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
3056 g_object_notify (G_OBJECT (status_icon), "name");
3060 #define __GTK_STATUS_ICON_C__
3061 #include "gtkaliasdef.c"