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>
34 #include "gtkstatusicon.h"
37 #include "gtkiconfactory.h"
38 #include "gtkiconhelperprivate.h"
40 #include "gtkmarshalers.h"
41 #include "gtksizerequest.h"
42 #include "gtkprivate.h"
43 #include "gtkwidget.h"
44 #include "gtktooltip.h"
45 #include "gtkicontheme.h"
47 #include "gtktypebuiltins.h"
49 #ifdef GDK_WINDOWING_X11
50 #include "gdk/x11/gdkx.h"
51 #include "gtktrayicon.h"
54 #ifdef GDK_WINDOWING_WIN32
55 #include "gdk/win32/gdkwin32.h"
56 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
61 * SECTION:gtkstatusicon
62 * @Short_description: Display an icon in the system tray
63 * @Title: GtkStatusIcon
65 * The "system tray" or notification area is normally used for transient icons
66 * that indicate some special state. For example, a system tray icon might
67 * appear to tell the user that they have new mail, or have an incoming instant
68 * message, or something along those lines. The basic idea is that creating an
69 * icon in the notification area is less annoying than popping up a dialog.
71 * A #GtkStatusIcon object can be used to display an icon in a "system tray".
72 * The icon can have a tooltip, and the user can interact with it by
73 * activating it or popping up a context menu. Critical information should
74 * not solely be displayed in a #GtkStatusIcon, since it may not be
75 * visible (e.g. when the user doesn't have a notification area on his panel).
76 * This can be checked with gtk_status_icon_is_embedded().
78 * On X11, the implementation follows the freedesktop.org "System Tray"
79 * <ulink url="http://www.freedesktop.org/wiki/Specifications/systemtray-spec">specification</ulink>.
80 * Implementations of the "tray" side of this specification can
81 * be found e.g. in the GNOME 2 and KDE panel applications.
83 * Note that a GtkStatusIcon is <emphasis>not</emphasis> a widget, but just
84 * a #GObject. Making it a widget would be impractical, since the system tray
85 * on Win32 doesn't allow to embed arbitrary widgets.
89 #define BLINK_TIMEOUT 500
117 BUTTON_PRESS_EVENT_SIGNAL,
118 BUTTON_RELEASE_EVENT_SIGNAL,
120 QUERY_TOOLTIP_SIGNAL,
124 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
126 #ifdef GDK_WINDOWING_QUARTZ
127 #include "gtkstatusicon-quartz.c"
130 struct _GtkStatusIconPrivate
132 #ifdef GDK_WINDOWING_X11
133 GtkWidget *tray_icon;
136 GtkWidget *dummy_widget;
139 #ifdef GDK_WINDOWING_WIN32
142 gint last_click_x, last_click_y;
143 GtkOrientation orientation;
148 #ifdef GDK_WINDOWING_QUARTZ
149 GtkQuartzStatusIcon *status_item;
155 GtkIconHelper *icon_helper;
159 static GObject* gtk_status_icon_constructor (GType type,
160 guint n_construct_properties,
161 GObjectConstructParam *construct_params);
162 static void gtk_status_icon_finalize (GObject *object);
163 static void gtk_status_icon_set_property (GObject *object,
167 static void gtk_status_icon_get_property (GObject *object,
172 #ifdef GDK_WINDOWING_X11
173 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
174 GtkAllocation *allocation);
175 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
176 GdkScreen *old_screen);
177 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
178 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
179 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
180 static void gtk_status_icon_icon_size_changed(GtkStatusIcon *status_icon);
181 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
182 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
184 GtkStatusIcon *status_icon);
185 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
186 GdkEventScroll *event);
187 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
190 gboolean keyboard_tip,
191 GtkTooltip *tooltip);
193 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
195 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
197 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
198 GdkEventButton *event);
199 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
200 GdkEventButton *event);
201 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
202 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
204 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
207 gtk_status_icon_class_init (GtkStatusIconClass *class)
209 GObjectClass *gobject_class = (GObjectClass *) class;
211 gobject_class->constructor = gtk_status_icon_constructor;
212 gobject_class->finalize = gtk_status_icon_finalize;
213 gobject_class->set_property = gtk_status_icon_set_property;
214 gobject_class->get_property = gtk_status_icon_get_property;
216 class->button_press_event = NULL;
217 class->button_release_event = NULL;
218 class->scroll_event = NULL;
219 class->query_tooltip = NULL;
221 g_object_class_install_property (gobject_class,
223 g_param_spec_object ("pixbuf",
225 P_("A GdkPixbuf to display"),
227 GTK_PARAM_READWRITE));
229 g_object_class_install_property (gobject_class,
231 g_param_spec_string ("file",
233 P_("Filename to load and display"),
235 GTK_PARAM_WRITABLE));
237 g_object_class_install_property (gobject_class,
239 g_param_spec_string ("stock",
241 P_("Stock ID for a stock image to display"),
243 GTK_PARAM_READWRITE));
245 g_object_class_install_property (gobject_class,
247 g_param_spec_string ("icon-name",
249 P_("The name of the icon from the icon theme"),
251 GTK_PARAM_READWRITE));
254 * GtkStatusIcon:gicon:
256 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
257 * the image will be updated automatically if the theme changes.
261 g_object_class_install_property (gobject_class,
263 g_param_spec_object ("gicon",
265 P_("The GIcon being displayed"),
267 GTK_PARAM_READWRITE));
269 g_object_class_install_property (gobject_class,
271 g_param_spec_enum ("storage-type",
273 P_("The representation being used for image data"),
276 GTK_PARAM_READABLE));
278 g_object_class_install_property (gobject_class,
280 g_param_spec_int ("size",
282 P_("The size of the icon"),
286 GTK_PARAM_READABLE));
288 g_object_class_install_property (gobject_class,
290 g_param_spec_object ("screen",
292 P_("The screen where this status icon will be displayed"),
294 GTK_PARAM_READWRITE));
296 g_object_class_install_property (gobject_class,
298 g_param_spec_boolean ("visible",
300 P_("Whether the status icon is visible"),
302 GTK_PARAM_READWRITE));
306 * GtkStatusIcon:embedded:
308 * %TRUE if the statusicon is embedded in a notification area.
312 g_object_class_install_property (gobject_class,
314 g_param_spec_boolean ("embedded",
316 P_("Whether the status icon is embedded"),
318 GTK_PARAM_READABLE));
321 * GtkStatusIcon:orientation:
323 * The orientation of the tray in which the statusicon
328 g_object_class_install_property (gobject_class,
330 g_param_spec_enum ("orientation",
332 P_("The orientation of the tray"),
333 GTK_TYPE_ORIENTATION,
334 GTK_ORIENTATION_HORIZONTAL,
335 GTK_PARAM_READABLE));
338 * GtkStatusIcon:has-tooltip:
340 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
341 * @status_icon. A value of %TRUE indicates that @status_icon can have a
342 * tooltip, in this case the status icon will be queried using
343 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
346 * Note that setting this property to %TRUE for the first time will change
347 * the event masks of the windows of this status icon to include leave-notify
348 * and motion-notify events. This will not be undone when the property is set
351 * Whether this property is respected is platform dependent.
352 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
356 g_object_class_install_property (gobject_class,
358 g_param_spec_boolean ("has-tooltip",
360 P_("Whether this tray icon has a tooltip"),
362 GTK_PARAM_READWRITE));
364 * GtkStatusIcon:tooltip-text:
366 * Sets the text of tooltip to be the given string.
368 * Also see gtk_tooltip_set_text().
370 * This is a convenience property which will take care of getting the
371 * tooltip shown if the given string is not %NULL.
372 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
373 * the default handler for the #GtkStatusIcon::query-tooltip signal
374 * will take care of displaying the tooltip.
376 * Note that some platforms have limitations on the length of tooltips
377 * that they allow on status icons, e.g. Windows only shows the first
382 g_object_class_install_property (gobject_class,
384 g_param_spec_string ("tooltip-text",
386 P_("The contents of the tooltip for this widget"),
388 GTK_PARAM_READWRITE));
390 * GtkStatusIcon:tooltip-markup:
392 * Sets the text of tooltip to be the given string, which is marked up
393 * with the <link linkend="PangoMarkupFormat">Pango text markup
394 * language</link>. Also see gtk_tooltip_set_markup().
396 * This is a convenience property which will take care of getting the
397 * tooltip shown if the given string is not %NULL.
398 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
399 * the default handler for the #GtkStatusIcon::query-tooltip signal
400 * will take care of displaying the tooltip.
402 * On some platforms, embedded markup will be ignored.
406 g_object_class_install_property (gobject_class,
408 g_param_spec_string ("tooltip-markup",
409 P_("Tooltip markup"),
410 P_("The contents of the tooltip for this tray icon"),
412 GTK_PARAM_READWRITE));
416 * GtkStatusIcon:title:
418 * The title of this tray icon. This should be a short, human-readable,
419 * localized string describing the tray icon. It may be used by tools
420 * like screen readers to render the tray icon.
424 g_object_class_install_property (gobject_class,
426 g_param_spec_string ("title",
428 P_("The title of this tray icon"),
430 GTK_PARAM_READWRITE));
433 * GtkStatusIcon::activate:
434 * @status_icon: the object which received the signal
436 * Gets emitted when the user activates the status icon.
437 * If and how status icons can activated is platform-dependent.
439 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
440 * be used by applications and should be wrapped by language bindings.
444 status_icon_signals [ACTIVATE_SIGNAL] =
445 g_signal_new (I_("activate"),
446 G_TYPE_FROM_CLASS (gobject_class),
447 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
448 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
451 g_cclosure_marshal_VOID__VOID,
456 * GtkStatusIcon::popup-menu:
457 * @status_icon: the object which received the signal
458 * @button: the button that was pressed, or 0 if the
459 * signal is not emitted in response to a button press event
460 * @activate_time: the timestamp of the event that
461 * triggered the signal emission
463 * Gets emitted when the user brings up the context menu
464 * of the status icon. Whether status icons can have context
465 * menus and how these are activated is platform-dependent.
467 * The @button and @activate_time parameters should be
468 * passed as the last to arguments to gtk_menu_popup().
470 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
471 * be used by applications and should be wrapped by language bindings.
475 status_icon_signals [POPUP_MENU_SIGNAL] =
476 g_signal_new (I_("popup-menu"),
477 G_TYPE_FROM_CLASS (gobject_class),
478 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
479 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
482 _gtk_marshal_VOID__UINT_UINT,
489 * GtkStatusIcon::size-changed:
490 * @status_icon: the object which received the signal
491 * @size: the new size
493 * Gets emitted when the size available for the image
494 * changes, e.g. because the notification area got resized.
496 * Return value: %TRUE if the icon was updated for the new
497 * size. Otherwise, GTK+ will scale the icon as necessary.
501 status_icon_signals [SIZE_CHANGED_SIGNAL] =
502 g_signal_new (I_("size-changed"),
503 G_TYPE_FROM_CLASS (gobject_class),
505 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
506 g_signal_accumulator_true_handled,
508 _gtk_marshal_BOOLEAN__INT,
514 * GtkStatusIcon::button-press-event:
515 * @status_icon: the object which received the signal
516 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
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: (type Gdk.EventButton): the #GdkEventButton which triggered
546 * The ::button-release-event signal will be emitted when a button
547 * (typically from a mouse) is released.
549 * Whether this event is emitted is platform-dependent. Use the ::activate
550 * and ::popup-menu signals in preference.
552 * Return value: %TRUE to stop other handlers from being invoked
553 * for the event. %FALSE to propagate the event further.
557 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
558 g_signal_new (I_("button_release_event"),
559 G_TYPE_FROM_CLASS (gobject_class),
561 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
562 g_signal_accumulator_true_handled, NULL,
563 _gtk_marshal_BOOLEAN__BOXED,
565 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
568 * GtkStatusIcon::scroll-event:
569 * @status_icon: the object which received the signal.
570 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
573 * The ::scroll-event signal is emitted when a button in the 4 to 7
574 * range is pressed. Wheel mice are usually configured to generate
575 * button press events for buttons 4 and 5 when the wheel is turned.
577 * Whether this event is emitted is platform-dependent.
579 * Returns: %TRUE to stop other handlers from being invoked for the event.
580 * %FALSE to propagate the event further.
584 status_icon_signals[SCROLL_EVENT_SIGNAL] =
585 g_signal_new (I_("scroll_event"),
586 G_TYPE_FROM_CLASS (gobject_class),
588 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
589 g_signal_accumulator_true_handled, NULL,
590 _gtk_marshal_BOOLEAN__BOXED,
592 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
595 * GtkStatusIcon::query-tooltip:
596 * @status_icon: the object which received the signal
597 * @x: the x coordinate of the cursor position where the request has been
598 * emitted, relative to @status_icon
599 * @y: the y coordinate of the cursor position where the request has been
600 * emitted, relative to @status_icon
601 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
602 * @tooltip: a #GtkTooltip
604 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
605 * cursor hovering above @status_icon; or emitted when @status_icon got
606 * focus in keyboard mode.
608 * Using the given coordinates, the signal handler should determine
609 * whether a tooltip should be shown for @status_icon. If this is
610 * the case %TRUE should be returned, %FALSE otherwise. Note that if
611 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
612 * should not be used.
614 * The signal handler is free to manipulate @tooltip with the therefore
615 * destined function calls.
617 * Whether this signal is emitted is platform-dependent.
618 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
620 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
624 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
625 g_signal_new (I_("query_tooltip"),
626 G_TYPE_FROM_CLASS (gobject_class),
628 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
629 g_signal_accumulator_true_handled, NULL,
630 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
637 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
640 #ifdef GDK_WINDOWING_WIN32
643 build_button_event (GtkStatusIconPrivate *priv,
648 GdkRectangle monitor0;
650 /* We know that gdk/win32 puts the primary monitor at index 0 */
651 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
652 e->window = g_object_ref (gdk_get_default_root_window ());
653 e->send_event = TRUE;
654 e->time = GetTickCount ();
656 priv->last_click_x = e->x = pos.x + monitor0.x;
657 priv->last_click_y = e->y = pos.y + monitor0.y;
661 //FIXME: e->device = gdk_display_get_default ()->core_pointer;
668 GtkStatusIcon *status_icon;
669 GdkEventButton *event;
670 } ButtonCallbackData;
673 button_callback (gpointer data)
675 ButtonCallbackData *bc = (ButtonCallbackData *) data;
677 if (bc->event->type == GDK_BUTTON_PRESS)
678 gtk_status_icon_button_press (bc->status_icon, bc->event);
680 gtk_status_icon_button_release (bc->status_icon, bc->event);
682 gdk_event_free ((GdkEvent *) bc->event);
688 static UINT taskbar_created_msg = 0;
689 static GSList *status_icons = NULL;
691 static LRESULT CALLBACK
697 if (message == taskbar_created_msg)
701 for (rover = status_icons; rover != NULL; rover = rover->next)
703 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
704 GtkStatusIconPrivate *priv = status_icon->priv;
706 priv->nid.hWnd = hwnd;
707 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
708 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
709 priv->nid.uFlags = NIF_MESSAGE;
711 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
713 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
714 priv->nid.hWnd = NULL;
718 gtk_status_icon_update_image (status_icon);
723 if (message == WM_GTK_TRAY_NOTIFICATION)
725 ButtonCallbackData *bc;
743 if (HIWORD (wparam) == XBUTTON1)
749 bc = g_new (ButtonCallbackData, 1);
750 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
751 bc->status_icon = GTK_STATUS_ICON (wparam);
752 build_button_event (bc->status_icon->priv, bc->event, button);
753 g_idle_add (button_callback, bc);
769 if (HIWORD (wparam) == XBUTTON1)
775 bc = g_new (ButtonCallbackData, 1);
776 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
777 bc->status_icon = GTK_STATUS_ICON (wparam);
778 build_button_event (bc->status_icon->priv, bc->event, button);
779 g_idle_add (button_callback, bc);
789 return DefWindowProc (hwnd, message, wparam, lparam);
794 create_tray_observer (void)
797 static HWND hwnd = NULL;
799 HINSTANCE hmodule = GetModuleHandle (NULL);
804 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
806 memset (&wclass, 0, sizeof(WNDCLASS));
807 wclass.lpszClassName = "gtkstatusicon-observer";
808 wclass.lpfnWndProc = wndproc;
809 wclass.hInstance = hmodule;
811 klass = RegisterClass (&wclass);
815 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
817 0, 0, 1, 1, NULL, NULL,
821 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
831 gtk_status_icon_init (GtkStatusIcon *status_icon)
833 GtkStatusIconPrivate *priv;
835 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
836 GtkStatusIconPrivate);
837 status_icon->priv = priv;
839 priv->icon_helper = _gtk_icon_helper_new ();
840 priv->visible = TRUE;
842 #ifdef GDK_WINDOWING_X11
844 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
846 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
847 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
850 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
851 G_CALLBACK (gtk_status_icon_key_press), status_icon);
852 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
853 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
854 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
855 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
856 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
857 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
858 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
859 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
860 g_signal_connect_swapped (priv->tray_icon, "notify::icon-size",
861 G_CALLBACK (gtk_status_icon_icon_size_changed), status_icon);
862 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
863 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
864 g_signal_connect (priv->tray_icon, "notify::error-color",
865 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
866 g_signal_connect (priv->tray_icon, "notify::warning-color",
867 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
868 g_signal_connect (priv->tray_icon, "notify::success-color",
869 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
870 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
871 G_CALLBACK (gtk_status_icon_button_press), status_icon);
872 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
873 G_CALLBACK (gtk_status_icon_button_release), status_icon);
874 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
875 G_CALLBACK (gtk_status_icon_scroll), status_icon);
876 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
877 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
878 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
879 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
880 priv->image = gtk_image_new ();
881 gtk_widget_set_can_focus (priv->image, TRUE);
882 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
883 gtk_widget_show (priv->image);
885 /* Force-initialize the symbolic colors */
886 g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
887 g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
888 g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
889 g_object_notify (G_OBJECT (priv->tray_icon), "success-color");
891 g_signal_connect_swapped (priv->image, "size-allocate",
892 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
894 #else /* !GDK_WINDOWING_X11 */
895 priv->dummy_widget = gtk_label_new ("");
898 #ifdef GDK_WINDOWING_WIN32
900 /* Get position and orientation of Windows taskbar. */
904 abd.cbSize = sizeof (abd);
905 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
906 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
907 priv->orientation = GTK_ORIENTATION_VERTICAL;
909 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
911 priv->taskbar_top = abd.rc.top;
914 priv->last_click_x = priv->last_click_y = 0;
916 /* Are the system tray icons always 16 pixels square? */
919 memset (&priv->nid, 0, sizeof (priv->nid));
921 priv->nid.hWnd = create_tray_observer ();
922 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
923 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
924 priv->nid.uFlags = NIF_MESSAGE;
926 /* To help win7 identify the icon create it with an application "unique" tip */
927 if (g_get_prgname ())
929 WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
931 priv->nid.uFlags |= NIF_TIP;
932 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
933 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
937 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
939 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
940 priv->nid.hWnd = NULL;
943 status_icons = g_slist_append (status_icons, status_icon);
947 #ifdef GDK_WINDOWING_QUARTZ
950 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
951 priv->size = [priv->status_item getHeight];
959 gtk_status_icon_constructor (GType type,
960 guint n_construct_properties,
961 GObjectConstructParam *construct_params)
964 #ifdef GDK_WINDOWING_X11
965 GtkStatusIcon *status_icon;
966 GtkStatusIconPrivate *priv;
969 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
970 n_construct_properties,
973 #ifdef GDK_WINDOWING_X11
974 status_icon = GTK_STATUS_ICON (object);
975 priv = status_icon->priv;
978 gtk_widget_show (priv->tray_icon);
985 gtk_status_icon_finalize (GObject *object)
987 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
988 GtkStatusIconPrivate *priv = status_icon->priv;
990 gtk_status_icon_reset_image_data (status_icon);
991 g_clear_object (&priv->icon_helper);
993 #ifdef GDK_WINDOWING_X11
994 g_signal_handlers_disconnect_by_func (priv->tray_icon,
995 gtk_status_icon_key_press, status_icon);
996 g_signal_handlers_disconnect_by_func (priv->tray_icon,
997 gtk_status_icon_popup_menu, status_icon);
998 g_signal_handlers_disconnect_by_func (priv->tray_icon,
999 gtk_status_icon_embedded_changed, status_icon);
1000 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1001 gtk_status_icon_orientation_changed, status_icon);
1002 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1003 gtk_status_icon_padding_changed, status_icon);
1004 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1005 gtk_status_icon_icon_size_changed, status_icon);
1006 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1007 gtk_status_icon_fg_changed, status_icon);
1008 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1009 gtk_status_icon_color_changed, status_icon);
1010 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1011 gtk_status_icon_button_press, status_icon);
1012 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1013 gtk_status_icon_button_release, status_icon);
1014 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1015 gtk_status_icon_scroll, status_icon);
1016 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1017 gtk_status_icon_query_tooltip, status_icon);
1018 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1019 gtk_status_icon_screen_changed, status_icon);
1020 gtk_widget_destroy (priv->image);
1021 gtk_widget_destroy (priv->tray_icon);
1022 #else /* !GDK_WINDOWING_X11 */
1023 gtk_widget_destroy (priv->dummy_widget);
1026 #ifdef GDK_WINDOWING_WIN32
1027 if (priv->nid.hWnd != NULL && priv->visible)
1028 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1029 if (priv->nid.hIcon)
1030 DestroyIcon (priv->nid.hIcon);
1031 g_free (priv->tooltip_text);
1033 status_icons = g_slist_remove (status_icons, status_icon);
1036 #ifdef GDK_WINDOWING_QUARTZ
1038 [priv->status_item release];
1039 QUARTZ_POOL_RELEASE;
1040 g_free (priv->tooltip_text);
1043 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1047 gtk_status_icon_set_property (GObject *object,
1049 const GValue *value,
1052 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1057 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1060 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1063 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1065 case PROP_ICON_NAME:
1066 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1069 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1072 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1075 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1077 case PROP_HAS_TOOLTIP:
1078 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1080 case PROP_TOOLTIP_TEXT:
1081 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1083 case PROP_TOOLTIP_MARKUP:
1084 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1087 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1090 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1096 gtk_status_icon_get_property (GObject *object,
1101 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1106 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1109 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1111 case PROP_ICON_NAME:
1112 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1115 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1117 case PROP_STORAGE_TYPE:
1118 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1121 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1124 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1127 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1130 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1132 case PROP_ORIENTATION:
1133 #ifdef GDK_WINDOWING_X11
1134 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1136 #ifdef GDK_WINDOWING_WIN32
1137 g_value_set_enum (value, status_icon->priv->orientation);
1140 case PROP_HAS_TOOLTIP:
1141 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1143 case PROP_TOOLTIP_TEXT:
1144 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1146 case PROP_TOOLTIP_MARKUP:
1147 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1150 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1159 * gtk_status_icon_new:
1161 * Creates an empty status icon object.
1163 * Return value: a new #GtkStatusIcon
1168 gtk_status_icon_new (void)
1170 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1174 * gtk_status_icon_new_from_pixbuf:
1175 * @pixbuf: a #GdkPixbuf
1177 * Creates a status icon displaying @pixbuf.
1179 * The image will be scaled down to fit in the available
1180 * space in the notification area, if necessary.
1182 * Return value: a new #GtkStatusIcon
1187 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1189 return g_object_new (GTK_TYPE_STATUS_ICON,
1195 * gtk_status_icon_new_from_file:
1196 * @filename: (type filename): a filename
1198 * Creates a status icon displaying the file @filename.
1200 * The image will be scaled down to fit in the available
1201 * space in the notification area, if necessary.
1203 * Return value: a new #GtkStatusIcon
1208 gtk_status_icon_new_from_file (const gchar *filename)
1210 return g_object_new (GTK_TYPE_STATUS_ICON,
1216 * gtk_status_icon_new_from_stock:
1217 * @stock_id: a stock icon id
1219 * Creates a status icon displaying a stock icon. Sample stock icon
1220 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1221 * own stock icon names, see gtk_icon_factory_add_default() and
1222 * gtk_icon_factory_add().
1224 * Return value: a new #GtkStatusIcon
1229 gtk_status_icon_new_from_stock (const gchar *stock_id)
1231 return g_object_new (GTK_TYPE_STATUS_ICON,
1237 * gtk_status_icon_new_from_icon_name:
1238 * @icon_name: an icon name
1240 * Creates a status icon displaying an icon from the current icon theme.
1241 * If the current icon theme is changed, the icon will be updated
1244 * Return value: a new #GtkStatusIcon
1249 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1251 return g_object_new (GTK_TYPE_STATUS_ICON,
1252 "icon-name", icon_name,
1257 * gtk_status_icon_new_from_gicon:
1260 * Creates a status icon displaying a #GIcon. If the icon is a
1261 * themed icon, it will be updated when the theme changes.
1263 * Return value: a new #GtkStatusIcon
1268 gtk_status_icon_new_from_gicon (GIcon *icon)
1270 return g_object_new (GTK_TYPE_STATUS_ICON,
1276 emit_activate_signal (GtkStatusIcon *status_icon)
1278 g_signal_emit (status_icon,
1279 status_icon_signals [ACTIVATE_SIGNAL], 0);
1283 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1285 guint32 activate_time)
1287 g_signal_emit (status_icon,
1288 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1293 #ifdef GDK_WINDOWING_X11
1296 emit_size_changed_signal (GtkStatusIcon *status_icon,
1299 gboolean handled = FALSE;
1301 g_signal_emit (status_icon,
1302 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1311 /* rounds the pixel size to the nearest size avaiable in the theme */
1313 round_pixel_size (GtkWidget *widget,
1317 GtkSettings *settings;
1319 gint w, h, d, dist, size;
1321 screen = gtk_widget_get_screen (widget);
1324 return GTK_ICON_SIZE_MENU;
1326 settings = gtk_settings_get_for_screen (screen);
1331 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1333 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1334 w <= pixel_size && h <= pixel_size)
1336 d = MAX (pixel_size - w, pixel_size - h);
1349 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1351 GtkStatusIconPrivate *priv = status_icon->priv;
1352 #ifdef GDK_WINDOWING_WIN32
1355 GtkStyleContext *context;
1357 GtkImageType storage_type = _gtk_icon_helper_get_storage_type (priv->icon_helper);
1361 #ifdef GDK_WINDOWING_X11
1362 widget = priv->image;
1364 widget = priv->dummy_widget;
1367 context = gtk_widget_get_style_context (widget);
1368 round_size = round_pixel_size (widget, priv->size);
1370 if (storage_type == GTK_IMAGE_PIXBUF)
1376 pixbuf = _gtk_icon_helper_ensure_pixbuf (priv->icon_helper, context);
1378 width = gdk_pixbuf_get_width (pixbuf);
1379 height = gdk_pixbuf_get_height (pixbuf);
1381 if (width > round_size || height > round_size)
1383 scaled = gdk_pixbuf_scale_simple (pixbuf,
1384 MIN (round_size, width),
1385 MIN (round_size, height),
1386 GDK_INTERP_BILINEAR);
1387 g_object_unref (pixbuf);
1393 _gtk_icon_helper_set_pixel_size (priv->icon_helper, round_size);
1394 pixbuf = _gtk_icon_helper_ensure_pixbuf (priv->icon_helper, context);
1399 #ifdef GDK_WINDOWING_X11
1400 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
1402 #ifdef GDK_WINDOWING_WIN32
1403 prev_hicon = priv->nid.hIcon;
1404 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1405 priv->nid.uFlags |= NIF_ICON;
1406 if (priv->nid.hWnd != NULL && priv->visible)
1407 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1408 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1410 DestroyIcon (prev_hicon);
1412 #ifdef GDK_WINDOWING_QUARTZ
1414 [priv->status_item setImage:pixbuf];
1415 QUARTZ_POOL_RELEASE;
1420 #ifdef GDK_WINDOWING_X11
1421 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1423 #ifdef GDK_WINDOWING_WIN32
1424 priv->nid.uFlags &= ~NIF_ICON;
1425 if (priv->nid.hWnd != NULL && priv->visible)
1426 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1427 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1429 #ifdef GDK_WINDOWING_QUARTZ
1430 [priv->status_item setImage:NULL];
1434 g_clear_object (&pixbuf);
1437 #ifdef GDK_WINDOWING_X11
1440 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1441 GtkAllocation *allocation)
1443 GtkStatusIconPrivate *priv = status_icon->priv;
1444 GtkOrientation orientation;
1447 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1449 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1450 size = allocation->height;
1452 size = allocation->width;
1454 if (priv->size != size)
1458 g_object_notify (G_OBJECT (status_icon), "size");
1460 if (!emit_size_changed_signal (status_icon, size))
1461 gtk_status_icon_update_image (status_icon);
1466 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1467 GdkScreen *old_screen)
1469 GtkStatusIconPrivate *priv = status_icon->priv;
1471 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1473 g_object_notify (G_OBJECT (status_icon), "screen");
1479 #ifdef GDK_WINDOWING_X11
1482 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1484 GtkStatusIconPrivate *priv = status_icon->priv;
1485 GtkOrientation orientation;
1488 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1489 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1491 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1493 gtk_widget_set_margin_left (priv->image, padding);
1494 gtk_widget_set_margin_right (priv->image, padding);
1498 gtk_widget_set_margin_bottom (priv->image, padding);
1499 gtk_widget_set_margin_top (priv->image, padding);
1504 gtk_status_icon_icon_size_changed (GtkStatusIcon *status_icon)
1506 GtkStatusIconPrivate *priv = status_icon->priv;
1509 icon_size = _gtk_tray_icon_get_icon_size (GTK_TRAY_ICON (priv->tray_icon));
1512 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size);
1514 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), -1);
1518 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1520 gtk_status_icon_padding_changed (status_icon);
1521 gtk_status_icon_icon_size_changed (status_icon);
1522 g_object_notify (G_OBJECT (status_icon), "embedded");
1526 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1528 gtk_status_icon_padding_changed (status_icon);
1529 g_object_notify (G_OBJECT (status_icon), "orientation");
1533 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1535 GtkStatusIconPrivate *priv = status_icon->priv;
1538 g_object_get (priv->tray_icon, "fg-color", &rgba, NULL);
1540 gtk_widget_override_color (priv->image, GTK_STATE_FLAG_NORMAL, rgba);
1542 gdk_rgba_free (rgba);
1546 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1548 GtkStatusIcon *status_icon)
1550 GtkStatusIconPrivate *priv = status_icon->priv;
1553 switch (pspec->name[0])
1573 g_object_get (priv->tray_icon, pspec->name, &rgba, NULL);
1577 gtk_widget_override_symbolic_color (priv->image, name, &rgba);
1582 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1585 guint state, keyval;
1587 state = event->state & gtk_accelerator_get_default_mod_mask ();
1588 keyval = event->keyval;
1590 (keyval == GDK_KEY_Return ||
1591 keyval == GDK_KEY_KP_Enter ||
1592 keyval == GDK_KEY_ISO_Enter ||
1593 keyval == GDK_KEY_space ||
1594 keyval == GDK_KEY_KP_Space))
1596 emit_activate_signal (status_icon);
1604 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1606 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1612 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1613 GdkEventButton *event)
1615 gboolean handled = FALSE;
1617 g_signal_emit (status_icon,
1618 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1623 if (gdk_event_triggers_context_menu ((GdkEvent *) event))
1625 emit_popup_menu_signal (status_icon, event->button, event->time);
1628 else if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1630 emit_activate_signal (status_icon);
1638 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1639 GdkEventButton *event)
1641 gboolean handled = FALSE;
1642 g_signal_emit (status_icon,
1643 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1648 #ifdef GDK_WINDOWING_X11
1650 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1651 GdkEventScroll *event)
1653 gboolean handled = FALSE;
1654 g_signal_emit (status_icon,
1655 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1661 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1664 gboolean keyboard_tip,
1665 GtkTooltip *tooltip)
1667 gboolean handled = FALSE;
1668 g_signal_emit (status_icon,
1669 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1670 x, y, keyboard_tip, tooltip, &handled);
1673 #endif /* GDK_WINDOWING_X11 */
1676 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1678 GtkStatusIconPrivate *priv = status_icon->priv;
1679 GtkImageType storage_type = _gtk_icon_helper_get_storage_type (priv->icon_helper);
1681 switch (storage_type)
1683 case GTK_IMAGE_PIXBUF:
1684 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1686 case GTK_IMAGE_STOCK:
1687 g_object_notify (G_OBJECT (status_icon), "stock");
1689 case GTK_IMAGE_ICON_NAME:
1690 g_object_notify (G_OBJECT (status_icon), "icon-name");
1692 case GTK_IMAGE_GICON:
1693 g_object_notify (G_OBJECT (status_icon), "gicon");
1695 case GTK_IMAGE_EMPTY:
1698 g_assert_not_reached ();
1702 _gtk_icon_helper_clear (priv->icon_helper);
1703 g_object_notify (G_OBJECT (status_icon), "storage-type");
1707 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1708 GtkImageType storage_type,
1711 GtkStatusIconPrivate *priv = status_icon->priv;
1713 g_object_freeze_notify (G_OBJECT (status_icon));
1715 gtk_status_icon_reset_image_data (status_icon);
1717 g_object_notify (G_OBJECT (status_icon), "storage-type");
1719 /* the icon size we pass here doesn't really matter, since
1720 * we force a pixel size before doing the actual rendering anyway.
1722 switch (storage_type)
1724 case GTK_IMAGE_PIXBUF:
1725 _gtk_icon_helper_set_pixbuf (priv->icon_helper, data);
1726 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1728 case GTK_IMAGE_STOCK:
1729 _gtk_icon_helper_set_stock_id (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1730 g_object_notify (G_OBJECT (status_icon), "stock");
1732 case GTK_IMAGE_ICON_NAME:
1733 _gtk_icon_helper_set_icon_name (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1734 g_object_notify (G_OBJECT (status_icon), "icon-name");
1736 case GTK_IMAGE_GICON:
1737 _gtk_icon_helper_set_gicon (priv->icon_helper, data, GTK_ICON_SIZE_SMALL_TOOLBAR);
1738 g_object_notify (G_OBJECT (status_icon), "gicon");
1741 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1744 g_object_thaw_notify (G_OBJECT (status_icon));
1746 gtk_status_icon_update_image (status_icon);
1750 * gtk_status_icon_set_from_pixbuf:
1751 * @status_icon: a #GtkStatusIcon
1752 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1754 * Makes @status_icon display @pixbuf.
1755 * See gtk_status_icon_new_from_pixbuf() for details.
1760 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1763 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1764 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1766 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1771 * gtk_status_icon_set_from_file:
1772 * @status_icon: a #GtkStatusIcon
1773 * @filename: (type filename): a filename
1775 * Makes @status_icon display the file @filename.
1776 * See gtk_status_icon_new_from_file() for details.
1781 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1782 const gchar *filename)
1786 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1787 g_return_if_fail (filename != NULL);
1789 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1791 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1794 g_object_unref (pixbuf);
1798 * gtk_status_icon_set_from_stock:
1799 * @status_icon: a #GtkStatusIcon
1800 * @stock_id: a stock icon id
1802 * Makes @status_icon display the stock icon with the id @stock_id.
1803 * See gtk_status_icon_new_from_stock() for details.
1808 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1809 const gchar *stock_id)
1811 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1812 g_return_if_fail (stock_id != NULL);
1814 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1815 (gpointer) stock_id);
1819 * gtk_status_icon_set_from_icon_name:
1820 * @status_icon: a #GtkStatusIcon
1821 * @icon_name: an icon name
1823 * Makes @status_icon display the icon named @icon_name from the
1824 * current icon theme.
1825 * See gtk_status_icon_new_from_icon_name() for details.
1830 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1831 const gchar *icon_name)
1833 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1834 g_return_if_fail (icon_name != NULL);
1836 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1837 (gpointer) icon_name);
1841 * gtk_status_icon_set_from_gicon:
1842 * @status_icon: a #GtkStatusIcon
1845 * Makes @status_icon display the #GIcon.
1846 * See gtk_status_icon_new_from_gicon() for details.
1851 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1854 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1855 g_return_if_fail (icon != NULL);
1857 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1862 * gtk_status_icon_get_storage_type:
1863 * @status_icon: a #GtkStatusIcon
1865 * Gets the type of representation being used by the #GtkStatusIcon
1866 * to store image data. If the #GtkStatusIcon has no image data,
1867 * the return value will be %GTK_IMAGE_EMPTY.
1869 * Return value: the image representation being used
1874 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1876 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1878 return _gtk_icon_helper_get_storage_type (status_icon->priv->icon_helper);
1881 * gtk_status_icon_get_pixbuf:
1882 * @status_icon: a #GtkStatusIcon
1884 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1885 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1886 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1887 * The caller of this function does not own a reference to the
1890 * Return value: (transfer none): the displayed pixbuf,
1891 * or %NULL if the image is empty.
1896 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1898 GtkStatusIconPrivate *priv;
1900 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1902 priv = status_icon->priv;
1904 return _gtk_icon_helper_peek_pixbuf (priv->icon_helper);
1908 * gtk_status_icon_get_stock:
1909 * @status_icon: a #GtkStatusIcon
1911 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1912 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1913 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1914 * The returned string is owned by the #GtkStatusIcon and should not
1915 * be freed or modified.
1917 * Return value: stock id of the displayed stock icon,
1918 * or %NULL if the image is empty.
1923 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
1925 GtkStatusIconPrivate *priv;
1927 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1929 priv = status_icon->priv;
1931 return _gtk_icon_helper_get_stock_id (priv->icon_helper);
1935 * gtk_status_icon_get_icon_name:
1936 * @status_icon: a #GtkStatusIcon
1938 * Gets the name of the icon being displayed by the #GtkStatusIcon.
1939 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1940 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
1941 * The returned string is owned by the #GtkStatusIcon and should not
1942 * be freed or modified.
1944 * Return value: name of the displayed icon, or %NULL if the image is empty.
1949 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
1951 GtkStatusIconPrivate *priv;
1953 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1955 priv = status_icon->priv;
1957 return _gtk_icon_helper_get_icon_name (priv->icon_helper);
1961 * gtk_status_icon_get_gicon:
1962 * @status_icon: a #GtkStatusIcon
1964 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
1965 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1966 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
1967 * The caller of this function does not own a reference to the
1970 * If this function fails, @icon is left unchanged;
1972 * Returns: (transfer none): the displayed icon, or %NULL if the image is empty
1977 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
1979 GtkStatusIconPrivate *priv;
1981 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1983 priv = status_icon->priv;
1985 return _gtk_icon_helper_peek_gicon (priv->icon_helper);
1989 * gtk_status_icon_get_size:
1990 * @status_icon: a #GtkStatusIcon
1992 * Gets the size in pixels that is available for the image.
1993 * Stock icons and named icons adapt their size automatically
1994 * if the size of the notification area changes. For other
1995 * storage types, the size-changed signal can be used to
1996 * react to size changes.
1998 * Note that the returned size is only meaningful while the
1999 * status icon is embedded (see gtk_status_icon_is_embedded()).
2001 * Return value: the size that is available for the image
2006 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2008 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2010 return status_icon->priv->size;
2014 * gtk_status_icon_set_screen:
2015 * @status_icon: a #GtkStatusIcon
2016 * @screen: a #GdkScreen
2018 * Sets the #GdkScreen where @status_icon is displayed; if
2019 * the icon is already mapped, it will be unmapped, and
2020 * then remapped on the new screen.
2025 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2028 g_return_if_fail (GDK_IS_SCREEN (screen));
2030 #ifdef GDK_WINDOWING_X11
2031 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2036 * gtk_status_icon_get_screen:
2037 * @status_icon: a #GtkStatusIcon
2039 * Returns the #GdkScreen associated with @status_icon.
2041 * Return value: (transfer none): a #GdkScreen.
2046 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2048 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2050 #ifdef GDK_WINDOWING_X11
2051 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2053 return gdk_screen_get_default ();
2058 * gtk_status_icon_set_visible:
2059 * @status_icon: a #GtkStatusIcon
2060 * @visible: %TRUE to show the status icon, %FALSE to hide it
2062 * Shows or hides a status icon.
2067 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2070 GtkStatusIconPrivate *priv;
2072 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2074 priv = status_icon->priv;
2076 visible = visible != FALSE;
2078 if (priv->visible != visible)
2080 priv->visible = visible;
2082 #ifdef GDK_WINDOWING_X11
2084 gtk_widget_show (priv->tray_icon);
2085 else if (gtk_widget_get_realized (priv->tray_icon))
2087 gtk_widget_hide (priv->tray_icon);
2088 gtk_widget_unrealize (priv->tray_icon);
2091 #ifdef GDK_WINDOWING_WIN32
2092 if (priv->nid.hWnd != NULL)
2095 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2097 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2100 #ifdef GDK_WINDOWING_QUARTZ
2102 [priv->status_item setVisible:visible];
2103 QUARTZ_POOL_RELEASE;
2105 g_object_notify (G_OBJECT (status_icon), "visible");
2110 * gtk_status_icon_get_visible:
2111 * @status_icon: a #GtkStatusIcon
2113 * Returns whether the status icon is visible or not.
2114 * Note that being visible does not guarantee that
2115 * the user can actually see the icon, see also
2116 * gtk_status_icon_is_embedded().
2118 * Return value: %TRUE if the status icon is visible
2123 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2125 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2127 return status_icon->priv->visible;
2131 * gtk_status_icon_is_embedded:
2132 * @status_icon: a #GtkStatusIcon
2134 * Returns whether the status icon is embedded in a notification
2137 * Return value: %TRUE if the status icon is embedded in
2138 * a notification area.
2143 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2145 #ifdef GDK_WINDOWING_X11
2149 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2151 #ifdef GDK_WINDOWING_X11
2152 plug = GTK_PLUG (status_icon->priv->tray_icon);
2154 if (gtk_plug_get_embedded (plug))
2159 #ifdef GDK_WINDOWING_WIN32
2162 #ifdef GDK_WINDOWING_QUARTZ
2168 * gtk_status_icon_position_menu:
2169 * @menu: the #GtkMenu
2170 * @x: (out): return location for the x position
2171 * @y: (out): return location for the y position
2172 * @push_in: (out): whether the first menu item should be offset
2173 * (pushed in) to be aligned with the menu popup position
2174 * (only useful for GtkOptionMenu).
2175 * @user_data: (type GtkStatusIcon): the status icon to position the menu on
2177 * Menu positioning function to use with gtk_menu_popup()
2178 * to position @menu aligned to the status icon @user_data.
2183 gtk_status_icon_position_menu (GtkMenu *menu,
2189 #ifdef GDK_WINDOWING_X11
2190 GtkAllocation allocation;
2191 GtkStatusIcon *status_icon;
2192 GtkStatusIconPrivate *priv;
2193 GtkTrayIcon *tray_icon;
2196 GtkTextDirection direction;
2197 GtkRequisition menu_req;
2198 GdkRectangle monitor;
2200 gint monitor_num, height, width, xoffset, yoffset;
2202 g_return_if_fail (GTK_IS_MENU (menu));
2203 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2205 status_icon = GTK_STATUS_ICON (user_data);
2206 priv = status_icon->priv;
2207 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2208 widget = priv->tray_icon;
2210 direction = gtk_widget_get_direction (widget);
2212 screen = gtk_widget_get_screen (widget);
2213 gtk_menu_set_screen (menu, screen);
2215 window = gtk_widget_get_window (widget);
2216 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2217 if (monitor_num < 0)
2219 gtk_menu_set_monitor (menu, monitor_num);
2221 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2223 gdk_window_get_origin (window, x, y);
2225 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2228 gtk_widget_get_allocation (widget, &allocation);
2229 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2232 height = allocation.height;
2233 xoffset = allocation.width;
2238 width = allocation.width;
2241 yoffset = allocation.height;
2244 if (direction == GTK_TEXT_DIR_RTL)
2246 if ((*x - (menu_req.width - width)) >= monitor.x)
2247 *x -= menu_req.width - width;
2248 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2250 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2251 *x -= menu_req.width - width;
2257 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2259 else if ((*x - (menu_req.width - width)) >= monitor.x)
2260 *x -= menu_req.width - width;
2261 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2264 *x -= menu_req.width - width;
2267 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2269 else if ((*y - (menu_req.height - height)) >= monitor.y)
2270 *y -= menu_req.height - height;
2271 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2274 *y -= menu_req.height - height;
2277 #endif /* GDK_WINDOWING_X11 */
2279 #ifdef GDK_WINDOWING_WIN32
2280 GtkStatusIcon *status_icon;
2281 GtkStatusIconPrivate *priv;
2282 GtkRequisition menu_req;
2284 g_return_if_fail (GTK_IS_MENU (menu));
2285 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2287 status_icon = GTK_STATUS_ICON (user_data);
2288 priv = status_icon->priv;
2290 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2292 *x = priv->last_click_x;
2293 *y = priv->taskbar_top - menu_req.height;
2300 * gtk_status_icon_get_geometry:
2301 * @status_icon: a #GtkStatusIcon
2302 * @screen: (out) (transfer none) (allow-none): return location for
2303 * the screen, or %NULL if the information is not needed
2304 * @area: (out) (allow-none): return location for the area occupied by
2305 * the status icon, or %NULL
2306 * @orientation: (out) (allow-none): return location for the
2307 * orientation of the panel in which the status icon is embedded,
2308 * or %NULL. A panel at the top or bottom of the screen is
2309 * horizontal, a panel at the left or right is vertical.
2311 * Obtains information about the location of the status icon
2312 * on screen. This information can be used to e.g. position
2313 * popups like notification bubbles.
2315 * See gtk_status_icon_position_menu() for a more convenient
2316 * alternative for positioning menus.
2318 * Note that some platforms do not allow GTK+ to provide
2319 * this information, and even on platforms that do allow it,
2320 * the information is not reliable unless the status icon
2321 * is embedded in a notification area, see
2322 * gtk_status_icon_is_embedded().
2324 * Return value: %TRUE if the location information has
2330 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2333 GtkOrientation *orientation)
2335 #ifdef GDK_WINDOWING_X11
2336 GtkAllocation allocation;
2338 GtkStatusIconPrivate *priv;
2341 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2343 priv = status_icon->priv;
2344 widget = priv->tray_icon;
2347 *screen = gtk_widget_get_screen (widget);
2351 gdk_window_get_origin (gtk_widget_get_window (widget),
2354 gtk_widget_get_allocation (widget, &allocation);
2357 area->width = allocation.width;
2358 area->height = allocation.height;
2362 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2367 #endif /* GDK_WINDOWING_X11 */
2371 * gtk_status_icon_set_has_tooltip:
2372 * @status_icon: a #GtkStatusIcon
2373 * @has_tooltip: whether or not @status_icon has a tooltip
2375 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2376 * See #GtkStatusIcon:has-tooltip for more information.
2381 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2382 gboolean has_tooltip)
2384 GtkStatusIconPrivate *priv;
2386 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2388 priv = status_icon->priv;
2390 #ifdef GDK_WINDOWING_X11
2391 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2393 #ifdef GDK_WINDOWING_WIN32
2394 if (!has_tooltip && priv->tooltip_text)
2395 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2397 #ifdef GDK_WINDOWING_QUARTZ
2398 if (!has_tooltip && priv->tooltip_text)
2399 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2404 * gtk_status_icon_get_has_tooltip:
2405 * @status_icon: a #GtkStatusIcon
2407 * Returns the current value of the has-tooltip property.
2408 * See #GtkStatusIcon:has-tooltip for more information.
2410 * Return value: current value of has-tooltip on @status_icon.
2415 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2417 GtkStatusIconPrivate *priv;
2418 gboolean has_tooltip = FALSE;
2420 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2422 priv = status_icon->priv;
2424 #ifdef GDK_WINDOWING_X11
2425 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2427 #ifdef GDK_WINDOWING_WIN32
2428 has_tooltip = (priv->tooltip_text != NULL);
2430 #ifdef GDK_WINDOWING_QUARTZ
2431 has_tooltip = (priv->tooltip_text != NULL);
2438 * gtk_status_icon_set_tooltip_text:
2439 * @status_icon: a #GtkStatusIcon
2440 * @text: the contents of the tooltip for @status_icon
2442 * Sets @text as the contents of the tooltip.
2444 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2445 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2448 * See also the #GtkStatusIcon:tooltip-text property and
2449 * gtk_tooltip_set_text().
2454 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2457 GtkStatusIconPrivate *priv;
2459 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2461 priv = status_icon->priv;
2463 #ifdef GDK_WINDOWING_X11
2465 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2468 #ifdef GDK_WINDOWING_WIN32
2470 priv->nid.uFlags &= ~NIF_TIP;
2473 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2475 priv->nid.uFlags |= NIF_TIP;
2476 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2477 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2480 if (priv->nid.hWnd != NULL && priv->visible)
2481 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2482 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2484 g_free (priv->tooltip_text);
2485 priv->tooltip_text = g_strdup (text);
2487 #ifdef GDK_WINDOWING_QUARTZ
2489 [priv->status_item setToolTip:text];
2490 QUARTZ_POOL_RELEASE;
2492 g_free (priv->tooltip_text);
2493 priv->tooltip_text = g_strdup (text);
2498 * gtk_status_icon_get_tooltip_text:
2499 * @status_icon: a #GtkStatusIcon
2501 * Gets the contents of the tooltip for @status_icon.
2503 * Return value: the tooltip text, or %NULL. You should free the
2504 * returned string with g_free() when done.
2509 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2511 GtkStatusIconPrivate *priv;
2512 gchar *tooltip_text = NULL;
2514 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2516 priv = status_icon->priv;
2518 #ifdef GDK_WINDOWING_X11
2519 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2521 #ifdef GDK_WINDOWING_WIN32
2522 if (priv->tooltip_text)
2523 tooltip_text = g_strdup (priv->tooltip_text);
2525 #ifdef GDK_WINDOWING_QUARTZ
2526 if (priv->tooltip_text)
2527 tooltip_text = g_strdup (priv->tooltip_text);
2530 return tooltip_text;
2534 * gtk_status_icon_set_tooltip_markup:
2535 * @status_icon: a #GtkStatusIcon
2536 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2538 * Sets @markup as the contents of the tooltip, which is marked up with
2539 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2541 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2542 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2544 * See also the #GtkStatusIcon:tooltip-markup property and
2545 * gtk_tooltip_set_markup().
2550 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2551 const gchar *markup)
2553 GtkStatusIconPrivate *priv;
2554 #ifndef GDK_WINDOWING_X11
2558 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2560 priv = status_icon->priv;
2562 #ifdef GDK_WINDOWING_X11
2563 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2565 #ifdef GDK_WINDOWING_WIN32
2567 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2568 gtk_status_icon_set_tooltip_text (status_icon, text);
2571 #ifdef GDK_WINDOWING_QUARTZ
2573 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2574 gtk_status_icon_set_tooltip_text (status_icon, text);
2580 * gtk_status_icon_get_tooltip_markup:
2581 * @status_icon: a #GtkStatusIcon
2583 * Gets the contents of the tooltip for @status_icon.
2585 * Return value: the tooltip text, or %NULL. You should free the
2586 * returned string with g_free() when done.
2591 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2593 GtkStatusIconPrivate *priv;
2594 gchar *markup = NULL;
2596 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2598 priv = status_icon->priv;
2600 #ifdef GDK_WINDOWING_X11
2601 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2603 #ifdef GDK_WINDOWING_WIN32
2604 if (priv->tooltip_text)
2605 markup = g_markup_escape_text (priv->tooltip_text, -1);
2607 #ifdef GDK_WINDOWING_QUARTZ
2608 if (priv->tooltip_text)
2609 markup = g_markup_escape_text (priv->tooltip_text, -1);
2616 * gtk_status_icon_get_x11_window_id:
2617 * @status_icon: a #GtkStatusIcon
2619 * This function is only useful on the X11/freedesktop.org platform.
2620 * It returns a window ID for the widget in the underlying
2621 * status icon implementation. This is useful for the Galago
2622 * notification service, which can send a window ID in the protocol
2623 * in order for the server to position notification windows
2624 * pointing to a status icon reliably.
2626 * This function is not intended for other use cases which are
2627 * more likely to be met by one of the non-X11 specific methods, such
2628 * as gtk_status_icon_position_menu().
2630 * Return value: An 32 bit unsigned integer identifier for the
2631 * underlying X11 Window
2636 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2638 #ifdef GDK_WINDOWING_X11
2639 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2640 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2647 * gtk_status_icon_set_title:
2648 * @status_icon: a #GtkStatusIcon
2651 * Sets the title of this tray icon.
2652 * This should be a short, human-readable, localized string
2653 * describing the tray icon. It may be used by tools like screen
2654 * readers to render the tray icon.
2659 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2662 GtkStatusIconPrivate *priv;
2664 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2666 priv = status_icon->priv;
2668 #ifdef GDK_WINDOWING_X11
2669 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2671 #ifdef GDK_WINDOWING_QUARTZ
2672 g_free (priv->title);
2673 priv->title = g_strdup (title);
2675 #ifdef GDK_WINDOWING_WIN32
2676 g_free (priv->title);
2677 priv->title = g_strdup (title);
2680 g_object_notify (G_OBJECT (status_icon), "title");
2684 * gtk_status_icon_get_title:
2685 * @status_icon: a #GtkStatusIcon
2687 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2689 * Returns: the title of the status icon
2694 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2696 GtkStatusIconPrivate *priv;
2698 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2700 priv = status_icon->priv;
2702 #ifdef GDK_WINDOWING_X11
2703 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2705 #ifdef GDK_WINDOWING_QUARTZ
2708 #ifdef GDK_WINDOWING_WIN32
2715 * gtk_status_icon_set_name:
2716 * @status_icon: a #GtkStatusIcon
2719 * Sets the name of this tray icon.
2720 * This should be a string identifying this icon. It is may be
2721 * used for sorting the icons in the tray and will not be shown to
2727 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2730 GtkStatusIconPrivate *priv;
2732 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2734 priv = status_icon->priv;
2736 #ifdef GDK_WINDOWING_X11
2737 if (gtk_widget_get_realized (priv->tray_icon))
2739 /* gtk_window_set_wmclass() only operates on non-realized windows,
2740 * so temporarily unrealize the tray here
2742 gtk_widget_hide (priv->tray_icon);
2743 gtk_widget_unrealize (priv->tray_icon);
2744 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
2745 gtk_widget_show (priv->tray_icon);
2748 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);