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, see <http://www.gnu.org/licenses/>.
22 * Mark McLoughlin <mark@skynet.ie>
23 * Hans Breuer <hans@breuer.org>
24 * Tor Lillqvist <tml@novell.com>
25 * Mikael Hallendal <micke@imendio.com>
32 #include "gtkstatusicon.h"
35 #include "gtkiconfactory.h"
36 #include "gtkiconhelperprivate.h"
38 #include "gtkmarshalers.h"
39 #include "gtksizerequest.h"
40 #include "gtkprivate.h"
41 #include "gtkwidget.h"
42 #include "gtktooltip.h"
43 #include "gtkicontheme.h"
45 #include "gtktypebuiltins.h"
47 #ifdef GDK_WINDOWING_X11
48 #include "gdk/x11/gdkx.h"
49 #include "gtktrayicon.h"
52 #ifdef GDK_WINDOWING_WIN32
53 #include "gdk/win32/gdkwin32.h"
54 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
59 * SECTION:gtkstatusicon
60 * @Short_description: Display an icon in the system tray
61 * @Title: GtkStatusIcon
63 * The "system tray" or notification area is normally used for transient icons
64 * that indicate some special state. For example, a system tray icon might
65 * appear to tell the user that they have new mail, or have an incoming instant
66 * message, or something along those lines. The basic idea is that creating an
67 * icon in the notification area is less annoying than popping up a dialog.
69 * A #GtkStatusIcon object can be used to display an icon in a "system tray".
70 * The icon can have a tooltip, and the user can interact with it by
71 * activating it or popping up a context menu. Critical information should
72 * not solely be displayed in a #GtkStatusIcon, since it may not be
73 * visible (e.g. when the user doesn't have a notification area on his panel).
74 * This can be checked with gtk_status_icon_is_embedded().
76 * On X11, the implementation follows the freedesktop.org "System Tray"
77 * <ulink url="http://www.freedesktop.org/wiki/Specifications/systemtray-spec">specification</ulink>.
78 * Implementations of the "tray" side of this specification can
79 * be found e.g. in the GNOME 2 and KDE panel applications.
81 * Note that a GtkStatusIcon is <emphasis>not</emphasis> a widget, but just
82 * a #GObject. Making it a widget would be impractical, since the system tray
83 * on Win32 doesn't allow to embed arbitrary widgets.
87 #define BLINK_TIMEOUT 500
115 BUTTON_PRESS_EVENT_SIGNAL,
116 BUTTON_RELEASE_EVENT_SIGNAL,
118 QUERY_TOOLTIP_SIGNAL,
122 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
124 #ifdef GDK_WINDOWING_QUARTZ
125 #include "gtkstatusicon-quartz.c"
128 struct _GtkStatusIconPrivate
130 #ifdef GDK_WINDOWING_X11
131 GtkWidget *tray_icon;
134 GtkWidget *dummy_widget;
137 #ifdef GDK_WINDOWING_WIN32
140 gint last_click_x, last_click_y;
141 GtkOrientation orientation;
146 #ifdef GDK_WINDOWING_QUARTZ
147 GtkQuartzStatusIcon *status_item;
153 GtkIconHelper *icon_helper;
157 static GObject* gtk_status_icon_constructor (GType type,
158 guint n_construct_properties,
159 GObjectConstructParam *construct_params);
160 static void gtk_status_icon_finalize (GObject *object);
161 static void gtk_status_icon_set_property (GObject *object,
165 static void gtk_status_icon_get_property (GObject *object,
170 #ifdef GDK_WINDOWING_X11
171 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
172 GtkAllocation *allocation);
173 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
174 GdkScreen *old_screen);
175 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
176 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
177 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
178 static void gtk_status_icon_icon_size_changed(GtkStatusIcon *status_icon);
179 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
180 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
182 GtkStatusIcon *status_icon);
183 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
184 GdkEventScroll *event);
185 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
188 gboolean keyboard_tip,
189 GtkTooltip *tooltip);
191 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
193 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
195 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
196 GdkEventButton *event);
197 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
198 GdkEventButton *event);
199 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
200 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
202 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
205 gtk_status_icon_class_init (GtkStatusIconClass *class)
207 GObjectClass *gobject_class = (GObjectClass *) class;
209 gobject_class->constructor = gtk_status_icon_constructor;
210 gobject_class->finalize = gtk_status_icon_finalize;
211 gobject_class->set_property = gtk_status_icon_set_property;
212 gobject_class->get_property = gtk_status_icon_get_property;
214 class->button_press_event = NULL;
215 class->button_release_event = NULL;
216 class->scroll_event = NULL;
217 class->query_tooltip = NULL;
219 g_object_class_install_property (gobject_class,
221 g_param_spec_object ("pixbuf",
223 P_("A GdkPixbuf to display"),
225 GTK_PARAM_READWRITE));
227 g_object_class_install_property (gobject_class,
229 g_param_spec_string ("file",
231 P_("Filename to load and display"),
233 GTK_PARAM_WRITABLE));
235 g_object_class_install_property (gobject_class,
237 g_param_spec_string ("stock",
239 P_("Stock ID for a stock image to display"),
241 GTK_PARAM_READWRITE));
243 g_object_class_install_property (gobject_class,
245 g_param_spec_string ("icon-name",
247 P_("The name of the icon from the icon theme"),
249 GTK_PARAM_READWRITE));
252 * GtkStatusIcon:gicon:
254 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
255 * the image will be updated automatically if the theme changes.
259 g_object_class_install_property (gobject_class,
261 g_param_spec_object ("gicon",
263 P_("The GIcon being displayed"),
265 GTK_PARAM_READWRITE));
267 g_object_class_install_property (gobject_class,
269 g_param_spec_enum ("storage-type",
271 P_("The representation being used for image data"),
274 GTK_PARAM_READABLE));
276 g_object_class_install_property (gobject_class,
278 g_param_spec_int ("size",
280 P_("The size of the icon"),
284 GTK_PARAM_READABLE));
286 g_object_class_install_property (gobject_class,
288 g_param_spec_object ("screen",
290 P_("The screen where this status icon will be displayed"),
292 GTK_PARAM_READWRITE));
294 g_object_class_install_property (gobject_class,
296 g_param_spec_boolean ("visible",
298 P_("Whether the status icon is visible"),
300 GTK_PARAM_READWRITE));
304 * GtkStatusIcon:embedded:
306 * %TRUE if the statusicon is embedded in a notification area.
310 g_object_class_install_property (gobject_class,
312 g_param_spec_boolean ("embedded",
314 P_("Whether the status icon is embedded"),
316 GTK_PARAM_READABLE));
319 * GtkStatusIcon:orientation:
321 * The orientation of the tray in which the statusicon
326 g_object_class_install_property (gobject_class,
328 g_param_spec_enum ("orientation",
330 P_("The orientation of the tray"),
331 GTK_TYPE_ORIENTATION,
332 GTK_ORIENTATION_HORIZONTAL,
333 GTK_PARAM_READABLE));
336 * GtkStatusIcon:has-tooltip:
338 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
339 * @status_icon. A value of %TRUE indicates that @status_icon can have a
340 * tooltip, in this case the status icon will be queried using
341 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
344 * Note that setting this property to %TRUE for the first time will change
345 * the event masks of the windows of this status icon to include leave-notify
346 * and motion-notify events. This will not be undone when the property is set
349 * Whether this property is respected is platform dependent.
350 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
354 g_object_class_install_property (gobject_class,
356 g_param_spec_boolean ("has-tooltip",
358 P_("Whether this tray icon has a tooltip"),
360 GTK_PARAM_READWRITE));
362 * GtkStatusIcon:tooltip-text:
364 * Sets the text of tooltip to be the given string.
366 * Also see gtk_tooltip_set_text().
368 * This is a convenience property which will take care of getting the
369 * tooltip shown if the given string is not %NULL.
370 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
371 * the default handler for the #GtkStatusIcon::query-tooltip signal
372 * will take care of displaying the tooltip.
374 * Note that some platforms have limitations on the length of tooltips
375 * that they allow on status icons, e.g. Windows only shows the first
380 g_object_class_install_property (gobject_class,
382 g_param_spec_string ("tooltip-text",
384 P_("The contents of the tooltip for this widget"),
386 GTK_PARAM_READWRITE));
388 * GtkStatusIcon:tooltip-markup:
390 * Sets the text of tooltip to be the given string, which is marked up
391 * with the <link linkend="PangoMarkupFormat">Pango text markup
392 * language</link>. Also see gtk_tooltip_set_markup().
394 * This is a convenience property which will take care of getting the
395 * tooltip shown if the given string is not %NULL.
396 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
397 * the default handler for the #GtkStatusIcon::query-tooltip signal
398 * will take care of displaying the tooltip.
400 * On some platforms, embedded markup will be ignored.
404 g_object_class_install_property (gobject_class,
406 g_param_spec_string ("tooltip-markup",
407 P_("Tooltip markup"),
408 P_("The contents of the tooltip for this tray icon"),
410 GTK_PARAM_READWRITE));
414 * GtkStatusIcon:title:
416 * The title of this tray icon. This should be a short, human-readable,
417 * localized string describing the tray icon. It may be used by tools
418 * like screen readers to render the tray icon.
422 g_object_class_install_property (gobject_class,
424 g_param_spec_string ("title",
426 P_("The title of this tray icon"),
428 GTK_PARAM_READWRITE));
431 * GtkStatusIcon::activate:
432 * @status_icon: the object which received the signal
434 * Gets emitted when the user activates the status icon.
435 * If and how status icons can activated is platform-dependent.
437 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
438 * be used by applications and should be wrapped by language bindings.
442 status_icon_signals [ACTIVATE_SIGNAL] =
443 g_signal_new (I_("activate"),
444 G_TYPE_FROM_CLASS (gobject_class),
445 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
446 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
449 g_cclosure_marshal_VOID__VOID,
454 * GtkStatusIcon::popup-menu:
455 * @status_icon: the object which received the signal
456 * @button: the button that was pressed, or 0 if the
457 * signal is not emitted in response to a button press event
458 * @activate_time: the timestamp of the event that
459 * triggered the signal emission
461 * Gets emitted when the user brings up the context menu
462 * of the status icon. Whether status icons can have context
463 * menus and how these are activated is platform-dependent.
465 * The @button and @activate_time parameters should be
466 * passed as the last to arguments to gtk_menu_popup().
468 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
469 * be used by applications and should be wrapped by language bindings.
473 status_icon_signals [POPUP_MENU_SIGNAL] =
474 g_signal_new (I_("popup-menu"),
475 G_TYPE_FROM_CLASS (gobject_class),
476 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
477 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
480 _gtk_marshal_VOID__UINT_UINT,
487 * GtkStatusIcon::size-changed:
488 * @status_icon: the object which received the signal
489 * @size: the new size
491 * Gets emitted when the size available for the image
492 * changes, e.g. because the notification area got resized.
494 * Return value: %TRUE if the icon was updated for the new
495 * size. Otherwise, GTK+ will scale the icon as necessary.
499 status_icon_signals [SIZE_CHANGED_SIGNAL] =
500 g_signal_new (I_("size-changed"),
501 G_TYPE_FROM_CLASS (gobject_class),
503 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
504 g_signal_accumulator_true_handled,
506 _gtk_marshal_BOOLEAN__INT,
512 * GtkStatusIcon::button-press-event:
513 * @status_icon: the object which received the signal
514 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
517 * The ::button-press-event signal will be emitted when a button
518 * (typically from a mouse) is pressed.
520 * Whether this event is emitted is platform-dependent. Use the ::activate
521 * and ::popup-menu signals in preference.
523 * Return value: %TRUE to stop other handlers from being invoked
524 * for the event. %FALSE to propagate the event further.
528 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
529 g_signal_new (I_("button_press_event"),
530 G_TYPE_FROM_CLASS (gobject_class),
532 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
533 g_signal_accumulator_true_handled, NULL,
534 _gtk_marshal_BOOLEAN__BOXED,
536 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
539 * GtkStatusIcon::button-release-event:
540 * @status_icon: the object which received the signal
541 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
544 * The ::button-release-event signal will be emitted when a button
545 * (typically from a mouse) is released.
547 * Whether this event is emitted is platform-dependent. Use the ::activate
548 * and ::popup-menu signals in preference.
550 * Return value: %TRUE to stop other handlers from being invoked
551 * for the event. %FALSE to propagate the event further.
555 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
556 g_signal_new (I_("button_release_event"),
557 G_TYPE_FROM_CLASS (gobject_class),
559 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
560 g_signal_accumulator_true_handled, NULL,
561 _gtk_marshal_BOOLEAN__BOXED,
563 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
566 * GtkStatusIcon::scroll-event:
567 * @status_icon: the object which received the signal.
568 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
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.
582 status_icon_signals[SCROLL_EVENT_SIGNAL] =
583 g_signal_new (I_("scroll_event"),
584 G_TYPE_FROM_CLASS (gobject_class),
586 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
587 g_signal_accumulator_true_handled, NULL,
588 _gtk_marshal_BOOLEAN__BOXED,
590 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
593 * GtkStatusIcon::query-tooltip:
594 * @status_icon: the object which received the signal
595 * @x: the x coordinate of the cursor position where the request has been
596 * emitted, relative to @status_icon
597 * @y: the y coordinate of the cursor position where the request has been
598 * emitted, relative to @status_icon
599 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
600 * @tooltip: a #GtkTooltip
602 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
603 * cursor hovering above @status_icon; or emitted when @status_icon got
604 * focus in keyboard mode.
606 * Using the given coordinates, the signal handler should determine
607 * whether a tooltip should be shown for @status_icon. If this is
608 * the case %TRUE should be returned, %FALSE otherwise. Note that if
609 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
610 * should not be used.
612 * The signal handler is free to manipulate @tooltip with the therefore
613 * destined function calls.
615 * Whether this signal is emitted is platform-dependent.
616 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
618 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
622 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
623 g_signal_new (I_("query_tooltip"),
624 G_TYPE_FROM_CLASS (gobject_class),
626 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
627 g_signal_accumulator_true_handled, NULL,
628 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
635 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
638 #ifdef GDK_WINDOWING_WIN32
641 build_button_event (GtkStatusIconPrivate *priv,
646 GdkRectangle monitor0;
648 /* We know that gdk/win32 puts the primary monitor at index 0 */
649 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
650 e->window = g_object_ref (gdk_get_default_root_window ());
651 e->send_event = TRUE;
652 e->time = GetTickCount ();
654 priv->last_click_x = e->x = pos.x + monitor0.x;
655 priv->last_click_y = e->y = pos.y + monitor0.y;
659 //FIXME: e->device = gdk_display_get_default ()->core_pointer;
666 GtkStatusIcon *status_icon;
667 GdkEventButton *event;
668 } ButtonCallbackData;
671 button_callback (gpointer data)
673 ButtonCallbackData *bc = (ButtonCallbackData *) data;
675 if (bc->event->type == GDK_BUTTON_PRESS)
676 gtk_status_icon_button_press (bc->status_icon, bc->event);
678 gtk_status_icon_button_release (bc->status_icon, bc->event);
680 gdk_event_free ((GdkEvent *) bc->event);
683 return G_SOURCE_REMOVE;
686 static UINT taskbar_created_msg = 0;
687 static GSList *status_icons = NULL;
689 static LRESULT CALLBACK
695 if (message == taskbar_created_msg)
699 for (rover = status_icons; rover != NULL; rover = rover->next)
701 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
702 GtkStatusIconPrivate *priv = status_icon->priv;
704 priv->nid.hWnd = hwnd;
705 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
706 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
707 priv->nid.uFlags = NIF_MESSAGE;
709 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
711 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
712 priv->nid.hWnd = NULL;
716 gtk_status_icon_update_image (status_icon);
721 if (message == WM_GTK_TRAY_NOTIFICATION)
723 ButtonCallbackData *bc;
741 if (HIWORD (wparam) == XBUTTON1)
747 bc = g_new (ButtonCallbackData, 1);
748 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
749 bc->status_icon = GTK_STATUS_ICON (wparam);
750 build_button_event (bc->status_icon->priv, bc->event, button);
751 g_idle_add (button_callback, bc);
767 if (HIWORD (wparam) == XBUTTON1)
773 bc = g_new (ButtonCallbackData, 1);
774 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
775 bc->status_icon = GTK_STATUS_ICON (wparam);
776 build_button_event (bc->status_icon->priv, bc->event, button);
777 g_idle_add (button_callback, bc);
787 return DefWindowProc (hwnd, message, wparam, lparam);
792 create_tray_observer (void)
795 static HWND hwnd = NULL;
797 HINSTANCE hmodule = GetModuleHandle (NULL);
802 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
804 memset (&wclass, 0, sizeof(WNDCLASS));
805 wclass.lpszClassName = "gtkstatusicon-observer";
806 wclass.lpfnWndProc = wndproc;
807 wclass.hInstance = hmodule;
809 klass = RegisterClass (&wclass);
813 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
815 0, 0, 1, 1, NULL, NULL,
819 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
829 gtk_status_icon_init (GtkStatusIcon *status_icon)
831 GtkStatusIconPrivate *priv;
833 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
834 GtkStatusIconPrivate);
835 status_icon->priv = priv;
837 priv->icon_helper = _gtk_icon_helper_new ();
838 priv->visible = TRUE;
840 #ifdef GDK_WINDOWING_X11
842 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
844 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
845 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
848 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
849 G_CALLBACK (gtk_status_icon_key_press), status_icon);
850 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
851 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
852 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
853 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
854 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
855 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
856 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
857 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
858 g_signal_connect_swapped (priv->tray_icon, "notify::icon-size",
859 G_CALLBACK (gtk_status_icon_icon_size_changed), status_icon);
860 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
861 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
862 g_signal_connect (priv->tray_icon, "notify::error-color",
863 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
864 g_signal_connect (priv->tray_icon, "notify::warning-color",
865 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
866 g_signal_connect (priv->tray_icon, "notify::success-color",
867 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
868 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
869 G_CALLBACK (gtk_status_icon_button_press), status_icon);
870 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
871 G_CALLBACK (gtk_status_icon_button_release), status_icon);
872 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
873 G_CALLBACK (gtk_status_icon_scroll), status_icon);
874 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
875 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
876 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
877 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
878 priv->image = gtk_image_new ();
879 gtk_widget_set_can_focus (priv->image, TRUE);
880 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
881 gtk_widget_show (priv->image);
883 /* Force-initialize the symbolic colors */
884 g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
885 g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
886 g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
887 g_object_notify (G_OBJECT (priv->tray_icon), "success-color");
889 g_signal_connect_swapped (priv->image, "size-allocate",
890 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
892 #else /* !GDK_WINDOWING_X11 */
893 priv->dummy_widget = gtk_label_new ("");
896 #ifdef GDK_WINDOWING_WIN32
898 /* Get position and orientation of Windows taskbar. */
902 abd.cbSize = sizeof (abd);
903 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
904 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
905 priv->orientation = GTK_ORIENTATION_VERTICAL;
907 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
909 priv->taskbar_top = abd.rc.top;
912 priv->last_click_x = priv->last_click_y = 0;
914 /* Are the system tray icons always 16 pixels square? */
917 memset (&priv->nid, 0, sizeof (priv->nid));
919 priv->nid.hWnd = create_tray_observer ();
920 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
921 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
922 priv->nid.uFlags = NIF_MESSAGE;
924 /* To help win7 identify the icon create it with an application "unique" tip */
925 if (g_get_prgname ())
927 WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
929 priv->nid.uFlags |= NIF_TIP;
930 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
931 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
935 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
937 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
938 priv->nid.hWnd = NULL;
941 status_icons = g_slist_append (status_icons, status_icon);
945 #ifdef GDK_WINDOWING_QUARTZ
948 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
949 priv->size = [priv->status_item getHeight];
957 gtk_status_icon_constructor (GType type,
958 guint n_construct_properties,
959 GObjectConstructParam *construct_params)
962 #ifdef GDK_WINDOWING_X11
963 GtkStatusIcon *status_icon;
964 GtkStatusIconPrivate *priv;
967 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
968 n_construct_properties,
971 #ifdef GDK_WINDOWING_X11
972 status_icon = GTK_STATUS_ICON (object);
973 priv = status_icon->priv;
976 gtk_widget_show (priv->tray_icon);
983 gtk_status_icon_finalize (GObject *object)
985 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
986 GtkStatusIconPrivate *priv = status_icon->priv;
988 gtk_status_icon_reset_image_data (status_icon);
989 g_clear_object (&priv->icon_helper);
991 #ifdef GDK_WINDOWING_X11
992 g_signal_handlers_disconnect_by_func (priv->tray_icon,
993 gtk_status_icon_key_press, status_icon);
994 g_signal_handlers_disconnect_by_func (priv->tray_icon,
995 gtk_status_icon_popup_menu, status_icon);
996 g_signal_handlers_disconnect_by_func (priv->tray_icon,
997 gtk_status_icon_embedded_changed, status_icon);
998 g_signal_handlers_disconnect_by_func (priv->tray_icon,
999 gtk_status_icon_orientation_changed, status_icon);
1000 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1001 gtk_status_icon_padding_changed, status_icon);
1002 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1003 gtk_status_icon_icon_size_changed, status_icon);
1004 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1005 gtk_status_icon_fg_changed, status_icon);
1006 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1007 gtk_status_icon_color_changed, status_icon);
1008 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1009 gtk_status_icon_button_press, status_icon);
1010 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1011 gtk_status_icon_button_release, status_icon);
1012 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1013 gtk_status_icon_scroll, status_icon);
1014 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1015 gtk_status_icon_query_tooltip, status_icon);
1016 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1017 gtk_status_icon_screen_changed, status_icon);
1018 gtk_widget_destroy (priv->image);
1019 gtk_widget_destroy (priv->tray_icon);
1020 #else /* !GDK_WINDOWING_X11 */
1021 gtk_widget_destroy (priv->dummy_widget);
1024 #ifdef GDK_WINDOWING_WIN32
1025 if (priv->nid.hWnd != NULL && priv->visible)
1026 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1027 if (priv->nid.hIcon)
1028 DestroyIcon (priv->nid.hIcon);
1029 g_free (priv->tooltip_text);
1031 status_icons = g_slist_remove (status_icons, status_icon);
1034 #ifdef GDK_WINDOWING_QUARTZ
1036 [priv->status_item release];
1037 QUARTZ_POOL_RELEASE;
1038 g_free (priv->tooltip_text);
1041 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1045 gtk_status_icon_set_property (GObject *object,
1047 const GValue *value,
1050 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1055 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1058 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1061 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1063 case PROP_ICON_NAME:
1064 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1067 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1070 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1073 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1075 case PROP_HAS_TOOLTIP:
1076 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1078 case PROP_TOOLTIP_TEXT:
1079 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1081 case PROP_TOOLTIP_MARKUP:
1082 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1085 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1088 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1094 gtk_status_icon_get_property (GObject *object,
1099 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1104 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1107 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1109 case PROP_ICON_NAME:
1110 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1113 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1115 case PROP_STORAGE_TYPE:
1116 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1119 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1122 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1125 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1128 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1130 case PROP_ORIENTATION:
1131 #ifdef GDK_WINDOWING_X11
1132 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1134 #ifdef GDK_WINDOWING_WIN32
1135 g_value_set_enum (value, status_icon->priv->orientation);
1138 case PROP_HAS_TOOLTIP:
1139 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1141 case PROP_TOOLTIP_TEXT:
1142 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1144 case PROP_TOOLTIP_MARKUP:
1145 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1148 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1151 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1157 * gtk_status_icon_new:
1159 * Creates an empty status icon object.
1161 * Return value: a new #GtkStatusIcon
1166 gtk_status_icon_new (void)
1168 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1172 * gtk_status_icon_new_from_pixbuf:
1173 * @pixbuf: a #GdkPixbuf
1175 * Creates a status icon displaying @pixbuf.
1177 * The image will be scaled down to fit in the available
1178 * space in the notification area, if necessary.
1180 * Return value: a new #GtkStatusIcon
1185 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1187 return g_object_new (GTK_TYPE_STATUS_ICON,
1193 * gtk_status_icon_new_from_file:
1194 * @filename: (type filename): a filename
1196 * Creates a status icon displaying the file @filename.
1198 * The image will be scaled down to fit in the available
1199 * space in the notification area, if necessary.
1201 * Return value: a new #GtkStatusIcon
1206 gtk_status_icon_new_from_file (const gchar *filename)
1208 return g_object_new (GTK_TYPE_STATUS_ICON,
1214 * gtk_status_icon_new_from_stock:
1215 * @stock_id: a stock icon id
1217 * Creates a status icon displaying a stock icon. Sample stock icon
1218 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1219 * own stock icon names, see gtk_icon_factory_add_default() and
1220 * gtk_icon_factory_add().
1222 * Return value: a new #GtkStatusIcon
1227 gtk_status_icon_new_from_stock (const gchar *stock_id)
1229 return g_object_new (GTK_TYPE_STATUS_ICON,
1235 * gtk_status_icon_new_from_icon_name:
1236 * @icon_name: an icon name
1238 * Creates a status icon displaying an icon from the current icon theme.
1239 * If the current icon theme is changed, the icon will be updated
1242 * Return value: a new #GtkStatusIcon
1247 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1249 return g_object_new (GTK_TYPE_STATUS_ICON,
1250 "icon-name", icon_name,
1255 * gtk_status_icon_new_from_gicon:
1258 * Creates a status icon displaying a #GIcon. If the icon is a
1259 * themed icon, it will be updated when the theme changes.
1261 * Return value: a new #GtkStatusIcon
1266 gtk_status_icon_new_from_gicon (GIcon *icon)
1268 return g_object_new (GTK_TYPE_STATUS_ICON,
1274 emit_activate_signal (GtkStatusIcon *status_icon)
1276 g_signal_emit (status_icon,
1277 status_icon_signals [ACTIVATE_SIGNAL], 0);
1281 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1283 guint32 activate_time)
1285 g_signal_emit (status_icon,
1286 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1291 #ifdef GDK_WINDOWING_X11
1294 emit_size_changed_signal (GtkStatusIcon *status_icon,
1297 gboolean handled = FALSE;
1299 g_signal_emit (status_icon,
1300 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1309 /* rounds the pixel size to the nearest size avaiable in the theme */
1311 round_pixel_size (GtkWidget *widget,
1315 GtkSettings *settings;
1317 gint w, h, d, dist, size;
1319 screen = gtk_widget_get_screen (widget);
1322 return GTK_ICON_SIZE_MENU;
1324 settings = gtk_settings_get_for_screen (screen);
1329 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1331 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1332 w <= pixel_size && h <= pixel_size)
1334 d = MAX (pixel_size - w, pixel_size - h);
1347 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1349 GtkStatusIconPrivate *priv = status_icon->priv;
1350 #ifdef GDK_WINDOWING_WIN32
1353 GtkStyleContext *context;
1355 GtkImageType storage_type = _gtk_icon_helper_get_storage_type (priv->icon_helper);
1359 #ifdef GDK_WINDOWING_X11
1360 widget = priv->image;
1362 widget = priv->dummy_widget;
1365 context = gtk_widget_get_style_context (widget);
1366 round_size = round_pixel_size (widget, priv->size);
1368 if (storage_type == GTK_IMAGE_PIXBUF)
1374 pixbuf = _gtk_icon_helper_ensure_pixbuf (priv->icon_helper, context);
1376 width = gdk_pixbuf_get_width (pixbuf);
1377 height = gdk_pixbuf_get_height (pixbuf);
1379 if (width > round_size || height > round_size)
1381 scaled = gdk_pixbuf_scale_simple (pixbuf,
1382 MIN (round_size, width),
1383 MIN (round_size, height),
1384 GDK_INTERP_BILINEAR);
1385 g_object_unref (pixbuf);
1391 _gtk_icon_helper_set_pixel_size (priv->icon_helper, round_size);
1392 pixbuf = _gtk_icon_helper_ensure_pixbuf (priv->icon_helper, context);
1397 #ifdef GDK_WINDOWING_X11
1398 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
1400 #ifdef GDK_WINDOWING_WIN32
1401 prev_hicon = priv->nid.hIcon;
1402 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1403 priv->nid.uFlags |= NIF_ICON;
1404 if (priv->nid.hWnd != NULL && priv->visible)
1405 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1406 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1408 DestroyIcon (prev_hicon);
1410 #ifdef GDK_WINDOWING_QUARTZ
1412 [priv->status_item setImage:pixbuf];
1413 QUARTZ_POOL_RELEASE;
1418 #ifdef GDK_WINDOWING_X11
1419 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1421 #ifdef GDK_WINDOWING_WIN32
1422 priv->nid.uFlags &= ~NIF_ICON;
1423 if (priv->nid.hWnd != NULL && priv->visible)
1424 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1425 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1427 #ifdef GDK_WINDOWING_QUARTZ
1428 [priv->status_item setImage:NULL];
1432 g_clear_object (&pixbuf);
1435 #ifdef GDK_WINDOWING_X11
1438 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1439 GtkAllocation *allocation)
1441 GtkStatusIconPrivate *priv = status_icon->priv;
1442 GtkOrientation orientation;
1445 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1447 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1448 size = allocation->height;
1450 size = allocation->width;
1452 if (priv->size != size)
1456 g_object_notify (G_OBJECT (status_icon), "size");
1458 if (!emit_size_changed_signal (status_icon, size))
1459 gtk_status_icon_update_image (status_icon);
1464 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1465 GdkScreen *old_screen)
1467 GtkStatusIconPrivate *priv = status_icon->priv;
1469 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1471 g_object_notify (G_OBJECT (status_icon), "screen");
1477 #ifdef GDK_WINDOWING_X11
1480 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1482 GtkStatusIconPrivate *priv = status_icon->priv;
1483 GtkOrientation orientation;
1486 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1487 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1489 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1491 gtk_widget_set_margin_left (priv->image, padding);
1492 gtk_widget_set_margin_right (priv->image, padding);
1496 gtk_widget_set_margin_bottom (priv->image, padding);
1497 gtk_widget_set_margin_top (priv->image, padding);
1502 gtk_status_icon_icon_size_changed (GtkStatusIcon *status_icon)
1504 GtkStatusIconPrivate *priv = status_icon->priv;
1507 icon_size = _gtk_tray_icon_get_icon_size (GTK_TRAY_ICON (priv->tray_icon));
1510 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size);
1512 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), -1);
1516 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1518 gtk_status_icon_padding_changed (status_icon);
1519 gtk_status_icon_icon_size_changed (status_icon);
1520 g_object_notify (G_OBJECT (status_icon), "embedded");
1524 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1526 gtk_status_icon_padding_changed (status_icon);
1527 g_object_notify (G_OBJECT (status_icon), "orientation");
1531 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1533 GtkStatusIconPrivate *priv = status_icon->priv;
1536 g_object_get (priv->tray_icon, "fg-color", &rgba, NULL);
1538 gtk_widget_override_color (priv->image, GTK_STATE_FLAG_NORMAL, rgba);
1540 gdk_rgba_free (rgba);
1544 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1546 GtkStatusIcon *status_icon)
1548 GtkStatusIconPrivate *priv = status_icon->priv;
1551 switch (pspec->name[0])
1571 g_object_get (priv->tray_icon, pspec->name, &rgba, NULL);
1575 gtk_widget_override_symbolic_color (priv->image, name, &rgba);
1580 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1583 guint state, keyval;
1585 state = event->state & gtk_accelerator_get_default_mod_mask ();
1586 keyval = event->keyval;
1588 (keyval == GDK_KEY_Return ||
1589 keyval == GDK_KEY_KP_Enter ||
1590 keyval == GDK_KEY_ISO_Enter ||
1591 keyval == GDK_KEY_space ||
1592 keyval == GDK_KEY_KP_Space))
1594 emit_activate_signal (status_icon);
1602 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1604 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1610 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1611 GdkEventButton *event)
1613 gboolean handled = FALSE;
1615 g_signal_emit (status_icon,
1616 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1621 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
1623 emit_popup_menu_signal (status_icon, event->button, event->time);
1626 else if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
1628 emit_activate_signal (status_icon);
1636 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1637 GdkEventButton *event)
1639 gboolean handled = FALSE;
1640 g_signal_emit (status_icon,
1641 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1646 #ifdef GDK_WINDOWING_X11
1648 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1649 GdkEventScroll *event)
1651 gboolean handled = FALSE;
1652 g_signal_emit (status_icon,
1653 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1659 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1662 gboolean keyboard_tip,
1663 GtkTooltip *tooltip)
1665 gboolean handled = FALSE;
1666 g_signal_emit (status_icon,
1667 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1668 x, y, keyboard_tip, tooltip, &handled);
1671 #endif /* GDK_WINDOWING_X11 */
1674 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1676 GtkStatusIconPrivate *priv = status_icon->priv;
1677 GtkImageType storage_type = _gtk_icon_helper_get_storage_type (priv->icon_helper);
1679 switch (storage_type)
1681 case GTK_IMAGE_PIXBUF:
1682 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1684 case GTK_IMAGE_STOCK:
1685 g_object_notify (G_OBJECT (status_icon), "stock");
1687 case GTK_IMAGE_ICON_NAME:
1688 g_object_notify (G_OBJECT (status_icon), "icon-name");
1690 case GTK_IMAGE_GICON:
1691 g_object_notify (G_OBJECT (status_icon), "gicon");
1693 case GTK_IMAGE_EMPTY:
1696 g_assert_not_reached ();
1700 _gtk_icon_helper_clear (priv->icon_helper);
1701 g_object_notify (G_OBJECT (status_icon), "storage-type");
1705 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1706 GtkImageType storage_type,
1709 GtkStatusIconPrivate *priv = status_icon->priv;
1711 g_object_freeze_notify (G_OBJECT (status_icon));
1713 gtk_status_icon_reset_image_data (status_icon);
1715 g_object_notify (G_OBJECT (status_icon), "storage-type");
1717 /* the icon size we pass here doesn't really matter, since
1718 * we force a pixel size before doing the actual rendering anyway.
1720 switch (storage_type)
1722 case GTK_IMAGE_PIXBUF:
1723 _gtk_icon_helper_set_pixbuf (priv->icon_helper, data);
1724 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1726 case GTK_IMAGE_STOCK:
1727 _gtk_icon_helper_set_stock_id (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1728 g_object_notify (G_OBJECT (status_icon), "stock");
1730 case GTK_IMAGE_ICON_NAME:
1731 _gtk_icon_helper_set_icon_name (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1732 g_object_notify (G_OBJECT (status_icon), "icon-name");
1734 case GTK_IMAGE_GICON:
1735 _gtk_icon_helper_set_gicon (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1736 g_object_notify (G_OBJECT (status_icon), "gicon");
1739 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1742 g_object_thaw_notify (G_OBJECT (status_icon));
1744 gtk_status_icon_update_image (status_icon);
1748 * gtk_status_icon_set_from_pixbuf:
1749 * @status_icon: a #GtkStatusIcon
1750 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1752 * Makes @status_icon display @pixbuf.
1753 * See gtk_status_icon_new_from_pixbuf() for details.
1758 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1761 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1762 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1764 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1769 * gtk_status_icon_set_from_file:
1770 * @status_icon: a #GtkStatusIcon
1771 * @filename: (type filename): a filename
1773 * Makes @status_icon display the file @filename.
1774 * See gtk_status_icon_new_from_file() for details.
1779 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1780 const gchar *filename)
1784 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1785 g_return_if_fail (filename != NULL);
1787 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1789 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1792 g_object_unref (pixbuf);
1796 * gtk_status_icon_set_from_stock:
1797 * @status_icon: a #GtkStatusIcon
1798 * @stock_id: a stock icon id
1800 * Makes @status_icon display the stock icon with the id @stock_id.
1801 * See gtk_status_icon_new_from_stock() for details.
1806 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1807 const gchar *stock_id)
1809 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1810 g_return_if_fail (stock_id != NULL);
1812 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1813 (gpointer) stock_id);
1817 * gtk_status_icon_set_from_icon_name:
1818 * @status_icon: a #GtkStatusIcon
1819 * @icon_name: an icon name
1821 * Makes @status_icon display the icon named @icon_name from the
1822 * current icon theme.
1823 * See gtk_status_icon_new_from_icon_name() for details.
1828 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1829 const gchar *icon_name)
1831 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1832 g_return_if_fail (icon_name != NULL);
1834 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1835 (gpointer) icon_name);
1839 * gtk_status_icon_set_from_gicon:
1840 * @status_icon: a #GtkStatusIcon
1843 * Makes @status_icon display the #GIcon.
1844 * See gtk_status_icon_new_from_gicon() for details.
1849 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1852 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1853 g_return_if_fail (icon != NULL);
1855 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1860 * gtk_status_icon_get_storage_type:
1861 * @status_icon: a #GtkStatusIcon
1863 * Gets the type of representation being used by the #GtkStatusIcon
1864 * to store image data. If the #GtkStatusIcon has no image data,
1865 * the return value will be %GTK_IMAGE_EMPTY.
1867 * Return value: the image representation being used
1872 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1874 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1876 return _gtk_icon_helper_get_storage_type (status_icon->priv->icon_helper);
1879 * gtk_status_icon_get_pixbuf:
1880 * @status_icon: a #GtkStatusIcon
1882 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1883 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1884 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1885 * The caller of this function does not own a reference to the
1888 * Return value: (transfer none): the displayed pixbuf,
1889 * or %NULL if the image is empty.
1894 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1896 GtkStatusIconPrivate *priv;
1898 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1900 priv = status_icon->priv;
1902 return _gtk_icon_helper_peek_pixbuf (priv->icon_helper);
1906 * gtk_status_icon_get_stock:
1907 * @status_icon: a #GtkStatusIcon
1909 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1910 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1911 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1912 * The returned string is owned by the #GtkStatusIcon and should not
1913 * be freed or modified.
1915 * Return value: stock id of the displayed stock icon,
1916 * or %NULL if the image is empty.
1921 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
1923 GtkStatusIconPrivate *priv;
1925 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1927 priv = status_icon->priv;
1929 return _gtk_icon_helper_get_stock_id (priv->icon_helper);
1933 * gtk_status_icon_get_icon_name:
1934 * @status_icon: a #GtkStatusIcon
1936 * Gets the name of the icon being displayed by the #GtkStatusIcon.
1937 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1938 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
1939 * The returned string is owned by the #GtkStatusIcon and should not
1940 * be freed or modified.
1942 * Return value: name of the displayed icon, or %NULL if the image is empty.
1947 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
1949 GtkStatusIconPrivate *priv;
1951 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1953 priv = status_icon->priv;
1955 return _gtk_icon_helper_get_icon_name (priv->icon_helper);
1959 * gtk_status_icon_get_gicon:
1960 * @status_icon: a #GtkStatusIcon
1962 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
1963 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1964 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
1965 * The caller of this function does not own a reference to the
1968 * If this function fails, @icon is left unchanged;
1970 * Returns: (transfer none): the displayed icon, or %NULL if the image is empty
1975 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
1977 GtkStatusIconPrivate *priv;
1979 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1981 priv = status_icon->priv;
1983 return _gtk_icon_helper_peek_gicon (priv->icon_helper);
1987 * gtk_status_icon_get_size:
1988 * @status_icon: a #GtkStatusIcon
1990 * Gets the size in pixels that is available for the image.
1991 * Stock icons and named icons adapt their size automatically
1992 * if the size of the notification area changes. For other
1993 * storage types, the size-changed signal can be used to
1994 * react to size changes.
1996 * Note that the returned size is only meaningful while the
1997 * status icon is embedded (see gtk_status_icon_is_embedded()).
1999 * Return value: the size that is available for the image
2004 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2006 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2008 return status_icon->priv->size;
2012 * gtk_status_icon_set_screen:
2013 * @status_icon: a #GtkStatusIcon
2014 * @screen: a #GdkScreen
2016 * Sets the #GdkScreen where @status_icon is displayed; if
2017 * the icon is already mapped, it will be unmapped, and
2018 * then remapped on the new screen.
2023 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2026 g_return_if_fail (GDK_IS_SCREEN (screen));
2028 #ifdef GDK_WINDOWING_X11
2029 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2034 * gtk_status_icon_get_screen:
2035 * @status_icon: a #GtkStatusIcon
2037 * Returns the #GdkScreen associated with @status_icon.
2039 * Return value: (transfer none): a #GdkScreen.
2044 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2046 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2048 #ifdef GDK_WINDOWING_X11
2049 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2051 return gdk_screen_get_default ();
2056 * gtk_status_icon_set_visible:
2057 * @status_icon: a #GtkStatusIcon
2058 * @visible: %TRUE to show the status icon, %FALSE to hide it
2060 * Shows or hides a status icon.
2065 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2068 GtkStatusIconPrivate *priv;
2070 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2072 priv = status_icon->priv;
2074 visible = visible != FALSE;
2076 if (priv->visible != visible)
2078 priv->visible = visible;
2080 #ifdef GDK_WINDOWING_X11
2082 gtk_widget_show (priv->tray_icon);
2083 else if (gtk_widget_get_realized (priv->tray_icon))
2085 gtk_widget_hide (priv->tray_icon);
2086 gtk_widget_unrealize (priv->tray_icon);
2089 #ifdef GDK_WINDOWING_WIN32
2090 if (priv->nid.hWnd != NULL)
2093 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2095 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2098 #ifdef GDK_WINDOWING_QUARTZ
2100 [priv->status_item setVisible:visible];
2101 QUARTZ_POOL_RELEASE;
2103 g_object_notify (G_OBJECT (status_icon), "visible");
2108 * gtk_status_icon_get_visible:
2109 * @status_icon: a #GtkStatusIcon
2111 * Returns whether the status icon is visible or not.
2112 * Note that being visible does not guarantee that
2113 * the user can actually see the icon, see also
2114 * gtk_status_icon_is_embedded().
2116 * Return value: %TRUE if the status icon is visible
2121 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2123 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2125 return status_icon->priv->visible;
2129 * gtk_status_icon_is_embedded:
2130 * @status_icon: a #GtkStatusIcon
2132 * Returns whether the status icon is embedded in a notification
2135 * Return value: %TRUE if the status icon is embedded in
2136 * a notification area.
2141 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2143 #ifdef GDK_WINDOWING_X11
2147 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2149 #ifdef GDK_WINDOWING_X11
2150 plug = GTK_PLUG (status_icon->priv->tray_icon);
2152 if (gtk_plug_get_embedded (plug))
2157 #ifdef GDK_WINDOWING_WIN32
2160 #ifdef GDK_WINDOWING_QUARTZ
2166 * gtk_status_icon_position_menu:
2167 * @menu: the #GtkMenu
2168 * @x: (out): return location for the x position
2169 * @y: (out): return location for the y position
2170 * @push_in: (out): whether the first menu item should be offset
2171 * (pushed in) to be aligned with the menu popup position
2172 * (only useful for GtkOptionMenu).
2173 * @user_data: (type GtkStatusIcon): the status icon to position the menu on
2175 * Menu positioning function to use with gtk_menu_popup()
2176 * to position @menu aligned to the status icon @user_data.
2181 gtk_status_icon_position_menu (GtkMenu *menu,
2187 #ifdef GDK_WINDOWING_X11
2188 GtkAllocation allocation;
2189 GtkStatusIcon *status_icon;
2190 GtkStatusIconPrivate *priv;
2191 GtkTrayIcon *tray_icon;
2194 GtkTextDirection direction;
2195 GtkRequisition menu_req;
2196 GdkRectangle monitor;
2198 gint monitor_num, height, width, xoffset, yoffset;
2200 g_return_if_fail (GTK_IS_MENU (menu));
2201 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2203 status_icon = GTK_STATUS_ICON (user_data);
2204 priv = status_icon->priv;
2205 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2206 widget = priv->tray_icon;
2208 direction = gtk_widget_get_direction (widget);
2210 screen = gtk_widget_get_screen (widget);
2211 gtk_menu_set_screen (menu, screen);
2213 window = gtk_widget_get_window (widget);
2214 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2215 if (monitor_num < 0)
2217 gtk_menu_set_monitor (menu, monitor_num);
2219 gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
2221 gdk_window_get_origin (window, x, y);
2223 menu_req.width = gtk_widget_get_allocated_width (GTK_WIDGET (menu));
2224 menu_req.height = gtk_widget_get_allocated_height (GTK_WIDGET (menu));
2226 gtk_widget_get_allocation (widget, &allocation);
2227 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2230 height = allocation.height;
2231 xoffset = allocation.width;
2236 width = allocation.width;
2239 yoffset = allocation.height;
2242 if (direction == GTK_TEXT_DIR_RTL)
2244 if ((*x - (menu_req.width - width)) >= monitor.x)
2245 *x -= menu_req.width - width;
2246 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2248 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2249 *x -= menu_req.width - width;
2255 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2257 else if ((*x - (menu_req.width - width)) >= monitor.x)
2258 *x -= menu_req.width - width;
2259 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2262 *x -= menu_req.width - width;
2265 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2267 else if ((*y - (menu_req.height - height)) >= monitor.y)
2268 *y -= menu_req.height - height;
2269 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2272 *y -= menu_req.height - height;
2275 #endif /* GDK_WINDOWING_X11 */
2277 #ifdef GDK_WINDOWING_WIN32
2278 GtkStatusIcon *status_icon;
2279 GtkStatusIconPrivate *priv;
2280 GtkRequisition menu_req;
2282 g_return_if_fail (GTK_IS_MENU (menu));
2283 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2285 status_icon = GTK_STATUS_ICON (user_data);
2286 priv = status_icon->priv;
2288 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2290 *x = priv->last_click_x;
2291 *y = priv->taskbar_top - menu_req.height;
2298 * gtk_status_icon_get_geometry:
2299 * @status_icon: a #GtkStatusIcon
2300 * @screen: (out) (transfer none) (allow-none): return location for
2301 * the screen, or %NULL if the information is not needed
2302 * @area: (out) (allow-none): return location for the area occupied by
2303 * the status icon, or %NULL
2304 * @orientation: (out) (allow-none): return location for the
2305 * orientation of the panel in which the status icon is embedded,
2306 * or %NULL. A panel at the top or bottom of the screen is
2307 * horizontal, a panel at the left or right is vertical.
2309 * Obtains information about the location of the status icon
2310 * on screen. This information can be used to e.g. position
2311 * popups like notification bubbles.
2313 * See gtk_status_icon_position_menu() for a more convenient
2314 * alternative for positioning menus.
2316 * Note that some platforms do not allow GTK+ to provide
2317 * this information, and even on platforms that do allow it,
2318 * the information is not reliable unless the status icon
2319 * is embedded in a notification area, see
2320 * gtk_status_icon_is_embedded().
2322 * Return value: %TRUE if the location information has
2328 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2331 GtkOrientation *orientation)
2333 #ifdef GDK_WINDOWING_X11
2334 GtkAllocation allocation;
2336 GtkStatusIconPrivate *priv;
2339 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2341 priv = status_icon->priv;
2342 widget = priv->tray_icon;
2345 *screen = gtk_widget_get_screen (widget);
2349 gdk_window_get_origin (gtk_widget_get_window (widget),
2352 gtk_widget_get_allocation (widget, &allocation);
2355 area->width = allocation.width;
2356 area->height = allocation.height;
2360 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2365 #endif /* GDK_WINDOWING_X11 */
2369 * gtk_status_icon_set_has_tooltip:
2370 * @status_icon: a #GtkStatusIcon
2371 * @has_tooltip: whether or not @status_icon has a tooltip
2373 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2374 * See #GtkStatusIcon:has-tooltip for more information.
2379 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2380 gboolean has_tooltip)
2382 GtkStatusIconPrivate *priv;
2384 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2386 priv = status_icon->priv;
2388 #ifdef GDK_WINDOWING_X11
2389 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2391 #ifdef GDK_WINDOWING_WIN32
2392 if (!has_tooltip && priv->tooltip_text)
2393 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2395 #ifdef GDK_WINDOWING_QUARTZ
2396 if (!has_tooltip && priv->tooltip_text)
2397 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2402 * gtk_status_icon_get_has_tooltip:
2403 * @status_icon: a #GtkStatusIcon
2405 * Returns the current value of the has-tooltip property.
2406 * See #GtkStatusIcon:has-tooltip for more information.
2408 * Return value: current value of has-tooltip on @status_icon.
2413 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2415 GtkStatusIconPrivate *priv;
2416 gboolean has_tooltip = FALSE;
2418 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2420 priv = status_icon->priv;
2422 #ifdef GDK_WINDOWING_X11
2423 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2425 #ifdef GDK_WINDOWING_WIN32
2426 has_tooltip = (priv->tooltip_text != NULL);
2428 #ifdef GDK_WINDOWING_QUARTZ
2429 has_tooltip = (priv->tooltip_text != NULL);
2436 * gtk_status_icon_set_tooltip_text:
2437 * @status_icon: a #GtkStatusIcon
2438 * @text: the contents of the tooltip for @status_icon
2440 * Sets @text as the contents of the tooltip.
2442 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2443 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2446 * See also the #GtkStatusIcon:tooltip-text property and
2447 * gtk_tooltip_set_text().
2452 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2455 GtkStatusIconPrivate *priv;
2457 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2459 priv = status_icon->priv;
2461 #ifdef GDK_WINDOWING_X11
2463 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2466 #ifdef GDK_WINDOWING_WIN32
2468 priv->nid.uFlags &= ~NIF_TIP;
2471 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2473 priv->nid.uFlags |= NIF_TIP;
2474 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2475 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2478 if (priv->nid.hWnd != NULL && priv->visible)
2479 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2480 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2482 g_free (priv->tooltip_text);
2483 priv->tooltip_text = g_strdup (text);
2485 #ifdef GDK_WINDOWING_QUARTZ
2487 [priv->status_item setToolTip:text];
2488 QUARTZ_POOL_RELEASE;
2490 g_free (priv->tooltip_text);
2491 priv->tooltip_text = g_strdup (text);
2496 * gtk_status_icon_get_tooltip_text:
2497 * @status_icon: a #GtkStatusIcon
2499 * Gets the contents of the tooltip for @status_icon.
2501 * Return value: the tooltip text, or %NULL. You should free the
2502 * returned string with g_free() when done.
2507 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2509 GtkStatusIconPrivate *priv;
2510 gchar *tooltip_text = NULL;
2512 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2514 priv = status_icon->priv;
2516 #ifdef GDK_WINDOWING_X11
2517 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2519 #ifdef GDK_WINDOWING_WIN32
2520 if (priv->tooltip_text)
2521 tooltip_text = g_strdup (priv->tooltip_text);
2523 #ifdef GDK_WINDOWING_QUARTZ
2524 if (priv->tooltip_text)
2525 tooltip_text = g_strdup (priv->tooltip_text);
2528 return tooltip_text;
2532 * gtk_status_icon_set_tooltip_markup:
2533 * @status_icon: a #GtkStatusIcon
2534 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2536 * Sets @markup as the contents of the tooltip, which is marked up with
2537 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2539 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2540 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2542 * See also the #GtkStatusIcon:tooltip-markup property and
2543 * gtk_tooltip_set_markup().
2548 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2549 const gchar *markup)
2551 GtkStatusIconPrivate *priv;
2552 #ifndef GDK_WINDOWING_X11
2556 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2558 priv = status_icon->priv;
2560 #ifdef GDK_WINDOWING_X11
2561 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2563 #ifdef GDK_WINDOWING_WIN32
2565 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2566 gtk_status_icon_set_tooltip_text (status_icon, text);
2569 #ifdef GDK_WINDOWING_QUARTZ
2571 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2572 gtk_status_icon_set_tooltip_text (status_icon, text);
2578 * gtk_status_icon_get_tooltip_markup:
2579 * @status_icon: a #GtkStatusIcon
2581 * Gets the contents of the tooltip for @status_icon.
2583 * Return value: the tooltip text, or %NULL. You should free the
2584 * returned string with g_free() when done.
2589 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2591 GtkStatusIconPrivate *priv;
2592 gchar *markup = NULL;
2594 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2596 priv = status_icon->priv;
2598 #ifdef GDK_WINDOWING_X11
2599 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2601 #ifdef GDK_WINDOWING_WIN32
2602 if (priv->tooltip_text)
2603 markup = g_markup_escape_text (priv->tooltip_text, -1);
2605 #ifdef GDK_WINDOWING_QUARTZ
2606 if (priv->tooltip_text)
2607 markup = g_markup_escape_text (priv->tooltip_text, -1);
2614 * gtk_status_icon_get_x11_window_id:
2615 * @status_icon: a #GtkStatusIcon
2617 * This function is only useful on the X11/freedesktop.org platform.
2618 * It returns a window ID for the widget in the underlying
2619 * status icon implementation. This is useful for the Galago
2620 * notification service, which can send a window ID in the protocol
2621 * in order for the server to position notification windows
2622 * pointing to a status icon reliably.
2624 * This function is not intended for other use cases which are
2625 * more likely to be met by one of the non-X11 specific methods, such
2626 * as gtk_status_icon_position_menu().
2628 * Return value: An 32 bit unsigned integer identifier for the
2629 * underlying X11 Window
2634 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2636 #ifdef GDK_WINDOWING_X11
2637 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2638 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2645 * gtk_status_icon_set_title:
2646 * @status_icon: a #GtkStatusIcon
2649 * Sets the title of this tray icon.
2650 * This should be a short, human-readable, localized string
2651 * describing the tray icon. It may be used by tools like screen
2652 * readers to render the tray icon.
2657 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2660 GtkStatusIconPrivate *priv;
2662 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2664 priv = status_icon->priv;
2666 #ifdef GDK_WINDOWING_X11
2667 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2669 #ifdef GDK_WINDOWING_QUARTZ
2670 g_free (priv->title);
2671 priv->title = g_strdup (title);
2673 #ifdef GDK_WINDOWING_WIN32
2674 g_free (priv->title);
2675 priv->title = g_strdup (title);
2678 g_object_notify (G_OBJECT (status_icon), "title");
2682 * gtk_status_icon_get_title:
2683 * @status_icon: a #GtkStatusIcon
2685 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2687 * Returns: the title of the status icon
2692 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2694 GtkStatusIconPrivate *priv;
2696 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2698 priv = status_icon->priv;
2700 #ifdef GDK_WINDOWING_X11
2701 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2703 #ifdef GDK_WINDOWING_QUARTZ
2706 #ifdef GDK_WINDOWING_WIN32
2713 * gtk_status_icon_set_name:
2714 * @status_icon: a #GtkStatusIcon
2717 * Sets the name of this tray icon.
2718 * This should be a string identifying this icon. It is may be
2719 * used for sorting the icons in the tray and will not be shown to
2725 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2728 GtkStatusIconPrivate *priv;
2730 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2732 priv = status_icon->priv;
2734 #ifdef GDK_WINDOWING_X11
2735 if (gtk_widget_get_realized (priv->tray_icon))
2737 /* gtk_window_set_wmclass() only operates on non-realized windows,
2738 * so temporarily unrealize the tray here
2740 gtk_widget_hide (priv->tray_icon);
2741 gtk_widget_unrealize (priv->tray_icon);
2742 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
2743 gtk_widget_show (priv->tray_icon);
2746 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);