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"
39 #include "gtkmarshalers.h"
40 #include "gtksizerequest.h"
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
43 #include "gtktooltip.h"
44 #include "gtkicontheme.h"
46 #include "gtktypebuiltins.h"
48 #ifdef GDK_WINDOWING_X11
49 #include "gdk/x11/gdkx.h"
50 #include "gtktrayicon.h"
53 #ifdef GDK_WINDOWING_WIN32
54 #include "gdk/win32/gdkwin32.h"
55 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
60 * SECTION:gtkstatusicon
61 * @Short_description: Display an icon in the system tray
62 * @Title: GtkStatusIcon
64 * The "system tray" or notification area is normally used for transient icons
65 * that indicate some special state. For example, a system tray icon might
66 * appear to tell the user that they have new mail, or have an incoming instant
67 * message, or something along those lines. The basic idea is that creating an
68 * icon in the notification area is less annoying than popping up a dialog.
70 * A #GtkStatusIcon object can be used to display an icon in a "system tray".
71 * The icon can have a tooltip, and the user can interact with it by
72 * activating it or popping up a context menu. Critical information should
73 * not solely be displayed in a #GtkStatusIcon, since it may not be
74 * visible (e.g. when the user doesn't have a notification area on his panel).
75 * This can be checked with gtk_status_icon_is_embedded().
77 * On X11, the implementation follows the freedesktop.org "System Tray"
78 * <ulink url="http://www.freedesktop.org/wiki/Specifications/systemtray-spec">specification</ulink>.
79 * Implementations of the "tray" side of this specification can
80 * be found e.g. in the GNOME 2 and KDE panel applications.
82 * Note that a GtkStatusIcon is <emphasis>not</emphasis> a widget, but just
83 * a #GObject. Making it a widget would be impractical, since the system tray
84 * on Win32 doesn't allow to embed arbitrary widgets.
88 #define BLINK_TIMEOUT 500
116 BUTTON_PRESS_EVENT_SIGNAL,
117 BUTTON_RELEASE_EVENT_SIGNAL,
119 QUERY_TOOLTIP_SIGNAL,
123 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
125 #ifdef GDK_WINDOWING_QUARTZ
126 #include "gtkstatusicon-quartz.c"
129 struct _GtkStatusIconPrivate
131 #ifdef GDK_WINDOWING_X11
132 GtkWidget *tray_icon;
136 #ifdef GDK_WINDOWING_WIN32
137 GtkWidget *dummy_widget;
139 gint last_click_x, last_click_y;
140 GtkOrientation orientation;
145 #ifdef GDK_WINDOWING_QUARTZ
146 GtkWidget *dummy_widget;
147 GtkQuartzStatusIcon *status_item;
157 GtkImageType storage_type;
170 static GObject* gtk_status_icon_constructor (GType type,
171 guint n_construct_properties,
172 GObjectConstructParam *construct_params);
173 static void gtk_status_icon_finalize (GObject *object);
174 static void gtk_status_icon_set_property (GObject *object,
178 static void gtk_status_icon_get_property (GObject *object,
183 #ifdef GDK_WINDOWING_X11
184 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
185 GtkAllocation *allocation);
186 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
187 GdkScreen *old_screen);
188 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
189 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
190 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
191 static void gtk_status_icon_icon_size_changed(GtkStatusIcon *status_icon);
192 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
193 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
195 GtkStatusIcon *status_icon);
196 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
197 GdkEventScroll *event);
198 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
201 gboolean keyboard_tip,
202 GtkTooltip *tooltip);
204 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
206 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
208 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
209 GdkEventButton *event);
210 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
211 GdkEventButton *event);
212 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
213 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
215 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
218 gtk_status_icon_class_init (GtkStatusIconClass *class)
220 GObjectClass *gobject_class = (GObjectClass *) class;
222 gobject_class->constructor = gtk_status_icon_constructor;
223 gobject_class->finalize = gtk_status_icon_finalize;
224 gobject_class->set_property = gtk_status_icon_set_property;
225 gobject_class->get_property = gtk_status_icon_get_property;
227 class->button_press_event = NULL;
228 class->button_release_event = NULL;
229 class->scroll_event = NULL;
230 class->query_tooltip = NULL;
232 g_object_class_install_property (gobject_class,
234 g_param_spec_object ("pixbuf",
236 P_("A GdkPixbuf to display"),
238 GTK_PARAM_READWRITE));
240 g_object_class_install_property (gobject_class,
242 g_param_spec_string ("file",
244 P_("Filename to load and display"),
246 GTK_PARAM_WRITABLE));
248 g_object_class_install_property (gobject_class,
250 g_param_spec_string ("stock",
252 P_("Stock ID for a stock image to display"),
254 GTK_PARAM_READWRITE));
256 g_object_class_install_property (gobject_class,
258 g_param_spec_string ("icon-name",
260 P_("The name of the icon from the icon theme"),
262 GTK_PARAM_READWRITE));
265 * GtkStatusIcon:gicon:
267 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
268 * the image will be updated automatically if the theme changes.
272 g_object_class_install_property (gobject_class,
274 g_param_spec_object ("gicon",
276 P_("The GIcon being displayed"),
278 GTK_PARAM_READWRITE));
280 g_object_class_install_property (gobject_class,
282 g_param_spec_enum ("storage-type",
284 P_("The representation being used for image data"),
287 GTK_PARAM_READABLE));
289 g_object_class_install_property (gobject_class,
291 g_param_spec_int ("size",
293 P_("The size of the icon"),
297 GTK_PARAM_READABLE));
299 g_object_class_install_property (gobject_class,
301 g_param_spec_object ("screen",
303 P_("The screen where this status icon will be displayed"),
305 GTK_PARAM_READWRITE));
307 g_object_class_install_property (gobject_class,
309 g_param_spec_boolean ("visible",
311 P_("Whether the status icon is visible"),
313 GTK_PARAM_READWRITE));
317 * GtkStatusIcon:embedded:
319 * %TRUE if the statusicon is embedded in a notification area.
323 g_object_class_install_property (gobject_class,
325 g_param_spec_boolean ("embedded",
327 P_("Whether the status icon is embedded"),
329 GTK_PARAM_READABLE));
332 * GtkStatusIcon:orientation:
334 * The orientation of the tray in which the statusicon
339 g_object_class_install_property (gobject_class,
341 g_param_spec_enum ("orientation",
343 P_("The orientation of the tray"),
344 GTK_TYPE_ORIENTATION,
345 GTK_ORIENTATION_HORIZONTAL,
346 GTK_PARAM_READABLE));
349 * GtkStatusIcon:has-tooltip:
351 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
352 * @status_icon. A value of %TRUE indicates that @status_icon can have a
353 * tooltip, in this case the status icon will be queried using
354 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
357 * Note that setting this property to %TRUE for the first time will change
358 * the event masks of the windows of this status icon to include leave-notify
359 * and motion-notify events. This will not be undone when the property is set
362 * Whether this property is respected is platform dependent.
363 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
367 g_object_class_install_property (gobject_class,
369 g_param_spec_boolean ("has-tooltip",
371 P_("Whether this tray icon has a tooltip"),
373 GTK_PARAM_READWRITE));
375 * GtkStatusIcon:tooltip-text:
377 * Sets the text of tooltip to be the given string.
379 * Also see gtk_tooltip_set_text().
381 * This is a convenience property which will take care of getting the
382 * tooltip shown if the given string is not %NULL.
383 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
384 * the default handler for the #GtkStatusIcon::query-tooltip signal
385 * will take care of displaying the tooltip.
387 * Note that some platforms have limitations on the length of tooltips
388 * that they allow on status icons, e.g. Windows only shows the first
393 g_object_class_install_property (gobject_class,
395 g_param_spec_string ("tooltip-text",
397 P_("The contents of the tooltip for this widget"),
399 GTK_PARAM_READWRITE));
401 * GtkStatusIcon:tooltip-markup:
403 * Sets the text of tooltip to be the given string, which is marked up
404 * with the <link linkend="PangoMarkupFormat">Pango text markup
405 * language</link>. Also see gtk_tooltip_set_markup().
407 * This is a convenience property which will take care of getting the
408 * tooltip shown if the given string is not %NULL.
409 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
410 * the default handler for the #GtkStatusIcon::query-tooltip signal
411 * will take care of displaying the tooltip.
413 * On some platforms, embedded markup will be ignored.
417 g_object_class_install_property (gobject_class,
419 g_param_spec_string ("tooltip-markup",
420 P_("Tooltip markup"),
421 P_("The contents of the tooltip for this tray icon"),
423 GTK_PARAM_READWRITE));
427 * GtkStatusIcon:title:
429 * The title of this tray icon. This should be a short, human-readable,
430 * localized string describing the tray icon. It may be used by tools
431 * like screen readers to render the tray icon.
435 g_object_class_install_property (gobject_class,
437 g_param_spec_string ("title",
439 P_("The title of this tray icon"),
441 GTK_PARAM_READWRITE));
444 * GtkStatusIcon::activate:
445 * @status_icon: the object which received the signal
447 * Gets emitted when the user activates the status icon.
448 * If and how status icons can activated is platform-dependent.
450 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
451 * be used by applications and should be wrapped by language bindings.
455 status_icon_signals [ACTIVATE_SIGNAL] =
456 g_signal_new (I_("activate"),
457 G_TYPE_FROM_CLASS (gobject_class),
458 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
459 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
462 g_cclosure_marshal_VOID__VOID,
467 * GtkStatusIcon::popup-menu:
468 * @status_icon: the object which received the signal
469 * @button: the button that was pressed, or 0 if the
470 * signal is not emitted in response to a button press event
471 * @activate_time: the timestamp of the event that
472 * triggered the signal emission
474 * Gets emitted when the user brings up the context menu
475 * of the status icon. Whether status icons can have context
476 * menus and how these are activated is platform-dependent.
478 * The @button and @activate_time parameters should be
479 * passed as the last to arguments to gtk_menu_popup().
481 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
482 * be used by applications and should be wrapped by language bindings.
486 status_icon_signals [POPUP_MENU_SIGNAL] =
487 g_signal_new (I_("popup-menu"),
488 G_TYPE_FROM_CLASS (gobject_class),
489 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
490 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
493 _gtk_marshal_VOID__UINT_UINT,
500 * GtkStatusIcon::size-changed:
501 * @status_icon: the object which received the signal
502 * @size: the new size
504 * Gets emitted when the size available for the image
505 * changes, e.g. because the notification area got resized.
507 * Return value: %TRUE if the icon was updated for the new
508 * size. Otherwise, GTK+ will scale the icon as necessary.
512 status_icon_signals [SIZE_CHANGED_SIGNAL] =
513 g_signal_new (I_("size-changed"),
514 G_TYPE_FROM_CLASS (gobject_class),
516 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
517 g_signal_accumulator_true_handled,
519 _gtk_marshal_BOOLEAN__INT,
525 * GtkStatusIcon::button-press-event:
526 * @status_icon: the object which received the signal
527 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
530 * The ::button-press-event signal will be emitted when a button
531 * (typically from a mouse) is pressed.
533 * Whether this event is emitted is platform-dependent. Use the ::activate
534 * and ::popup-menu signals in preference.
536 * Return value: %TRUE to stop other handlers from being invoked
537 * for the event. %FALSE to propagate the event further.
541 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
542 g_signal_new (I_("button_press_event"),
543 G_TYPE_FROM_CLASS (gobject_class),
545 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
546 g_signal_accumulator_true_handled, NULL,
547 _gtk_marshal_BOOLEAN__BOXED,
549 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
552 * GtkStatusIcon::button-release-event:
553 * @status_icon: the object which received the signal
554 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
557 * The ::button-release-event signal will be emitted when a button
558 * (typically from a mouse) is released.
560 * Whether this event is emitted is platform-dependent. Use the ::activate
561 * and ::popup-menu signals in preference.
563 * Return value: %TRUE to stop other handlers from being invoked
564 * for the event. %FALSE to propagate the event further.
568 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
569 g_signal_new (I_("button_release_event"),
570 G_TYPE_FROM_CLASS (gobject_class),
572 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
573 g_signal_accumulator_true_handled, NULL,
574 _gtk_marshal_BOOLEAN__BOXED,
576 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
579 * GtkStatusIcon::scroll-event:
580 * @status_icon: the object which received the signal.
581 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
584 * The ::scroll-event signal is emitted when a button in the 4 to 7
585 * range is pressed. Wheel mice are usually configured to generate
586 * button press events for buttons 4 and 5 when the wheel is turned.
588 * Whether this event is emitted is platform-dependent.
590 * Returns: %TRUE to stop other handlers from being invoked for the event.
591 * %FALSE to propagate the event further.
595 status_icon_signals[SCROLL_EVENT_SIGNAL] =
596 g_signal_new (I_("scroll_event"),
597 G_TYPE_FROM_CLASS (gobject_class),
599 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
600 g_signal_accumulator_true_handled, NULL,
601 _gtk_marshal_BOOLEAN__BOXED,
603 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
606 * GtkStatusIcon::query-tooltip:
607 * @status_icon: the object which received the signal
608 * @x: the x coordinate of the cursor position where the request has been
609 * emitted, relative to @status_icon
610 * @y: the y coordinate of the cursor position where the request has been
611 * emitted, relative to @status_icon
612 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
613 * @tooltip: a #GtkTooltip
615 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
616 * cursor hovering above @status_icon; or emitted when @status_icon got
617 * focus in keyboard mode.
619 * Using the given coordinates, the signal handler should determine
620 * whether a tooltip should be shown for @status_icon. If this is
621 * the case %TRUE should be returned, %FALSE otherwise. Note that if
622 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
623 * should not be used.
625 * The signal handler is free to manipulate @tooltip with the therefore
626 * destined function calls.
628 * Whether this signal is emitted is platform-dependent.
629 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
631 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
635 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
636 g_signal_new (I_("query_tooltip"),
637 G_TYPE_FROM_CLASS (gobject_class),
639 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
640 g_signal_accumulator_true_handled, NULL,
641 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
648 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
651 #ifdef GDK_WINDOWING_WIN32
654 build_button_event (GtkStatusIconPrivate *priv,
659 GdkRectangle monitor0;
661 /* We know that gdk/win32 puts the primary monitor at index 0 */
662 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
663 e->window = g_object_ref (gdk_get_default_root_window ());
664 e->send_event = TRUE;
665 e->time = GetTickCount ();
667 priv->last_click_x = e->x = pos.x + monitor0.x;
668 priv->last_click_y = e->y = pos.y + monitor0.y;
672 //FIXME: e->device = gdk_display_get_default ()->core_pointer;
679 GtkStatusIcon *status_icon;
680 GdkEventButton *event;
681 } ButtonCallbackData;
684 button_callback (gpointer data)
686 ButtonCallbackData *bc = (ButtonCallbackData *) data;
688 if (bc->event->type == GDK_BUTTON_PRESS)
689 gtk_status_icon_button_press (bc->status_icon, bc->event);
691 gtk_status_icon_button_release (bc->status_icon, bc->event);
693 gdk_event_free ((GdkEvent *) bc->event);
699 static UINT taskbar_created_msg = 0;
700 static GSList *status_icons = NULL;
702 static LRESULT CALLBACK
708 if (message == taskbar_created_msg)
712 for (rover = status_icons; rover != NULL; rover = rover->next)
714 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
715 GtkStatusIconPrivate *priv = status_icon->priv;
717 priv->nid.hWnd = hwnd;
718 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
719 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
720 priv->nid.uFlags = NIF_MESSAGE;
722 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
724 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
725 priv->nid.hWnd = NULL;
729 gtk_status_icon_update_image (status_icon);
734 if (message == WM_GTK_TRAY_NOTIFICATION)
736 ButtonCallbackData *bc;
754 if (HIWORD (wparam) == XBUTTON1)
760 bc = g_new (ButtonCallbackData, 1);
761 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
762 bc->status_icon = GTK_STATUS_ICON (wparam);
763 build_button_event (bc->status_icon->priv, bc->event, button);
764 g_idle_add (button_callback, bc);
780 if (HIWORD (wparam) == XBUTTON1)
786 bc = g_new (ButtonCallbackData, 1);
787 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
788 bc->status_icon = GTK_STATUS_ICON (wparam);
789 build_button_event (bc->status_icon->priv, bc->event, button);
790 g_idle_add (button_callback, bc);
800 return DefWindowProc (hwnd, message, wparam, lparam);
805 create_tray_observer (void)
808 static HWND hwnd = NULL;
810 HINSTANCE hmodule = GetModuleHandle (NULL);
815 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
817 memset (&wclass, 0, sizeof(WNDCLASS));
818 wclass.lpszClassName = "gtkstatusicon-observer";
819 wclass.lpfnWndProc = wndproc;
820 wclass.hInstance = hmodule;
822 klass = RegisterClass (&wclass);
826 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
828 0, 0, 1, 1, NULL, NULL,
832 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
842 gtk_status_icon_init (GtkStatusIcon *status_icon)
844 GtkStatusIconPrivate *priv;
846 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
847 GtkStatusIconPrivate);
848 status_icon->priv = priv;
850 priv->storage_type = GTK_IMAGE_EMPTY;
851 priv->visible = TRUE;
853 #ifdef GDK_WINDOWING_X11
855 priv->image_width = 0;
856 priv->image_height = 0;
858 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
860 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
861 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
864 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
865 G_CALLBACK (gtk_status_icon_key_press), status_icon);
866 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
867 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
868 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
869 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
870 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
871 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
872 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
873 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
874 g_signal_connect_swapped (priv->tray_icon, "notify::icon-size",
875 G_CALLBACK (gtk_status_icon_icon_size_changed), status_icon);
876 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
877 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
878 g_signal_connect (priv->tray_icon, "notify::error-color",
879 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
880 g_signal_connect (priv->tray_icon, "notify::warning-color",
881 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
882 g_signal_connect (priv->tray_icon, "notify::success-color",
883 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
884 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
885 G_CALLBACK (gtk_status_icon_button_press), status_icon);
886 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
887 G_CALLBACK (gtk_status_icon_button_release), status_icon);
888 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
889 G_CALLBACK (gtk_status_icon_scroll), status_icon);
890 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
891 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
892 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
893 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
894 priv->image = gtk_image_new ();
895 gtk_widget_set_can_focus (priv->image, TRUE);
896 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
897 gtk_widget_show (priv->image);
899 /* Force-initialize the symbolic colors */
900 g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
901 g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
902 g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
903 g_object_notify (G_OBJECT (priv->tray_icon), "success-color");
905 g_signal_connect_swapped (priv->image, "size-allocate",
906 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
910 #ifdef GDK_WINDOWING_WIN32
912 /* Get position and orientation of Windows taskbar. */
916 abd.cbSize = sizeof (abd);
917 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
918 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
919 priv->orientation = GTK_ORIENTATION_VERTICAL;
921 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
924 priv->last_click_x = priv->last_click_y = 0;
926 /* Are the system tray icons always 16 pixels square? */
928 priv->image_width = 16;
929 priv->image_height = 16;
931 priv->dummy_widget = gtk_label_new ("");
933 memset (&priv->nid, 0, sizeof (priv->nid));
935 priv->nid.hWnd = create_tray_observer ();
936 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
937 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
938 priv->nid.uFlags = NIF_MESSAGE;
940 /* To help win7 identify the icon create it with an application "unique" tip */
941 if (g_get_prgname ())
943 WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
945 priv->nid.uFlags |= NIF_TIP;
946 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
947 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
951 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
953 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
954 priv->nid.hWnd = NULL;
957 status_icons = g_slist_append (status_icons, status_icon);
961 #ifdef GDK_WINDOWING_QUARTZ
962 priv->dummy_widget = gtk_label_new ("");
966 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
968 priv->image_width = priv->image_height = [priv->status_item getHeight];
969 priv->size = priv->image_height;
977 gtk_status_icon_constructor (GType type,
978 guint n_construct_properties,
979 GObjectConstructParam *construct_params)
982 #ifdef GDK_WINDOWING_X11
983 GtkStatusIcon *status_icon;
984 GtkStatusIconPrivate *priv;
987 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
988 n_construct_properties,
991 #ifdef GDK_WINDOWING_X11
992 status_icon = GTK_STATUS_ICON (object);
993 priv = status_icon->priv;
996 gtk_widget_show (priv->tray_icon);
1003 gtk_status_icon_finalize (GObject *object)
1005 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1006 GtkStatusIconPrivate *priv = status_icon->priv;
1008 gtk_status_icon_reset_image_data (status_icon);
1010 #ifdef GDK_WINDOWING_X11
1011 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1012 gtk_status_icon_key_press, status_icon);
1013 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1014 gtk_status_icon_popup_menu, status_icon);
1015 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1016 gtk_status_icon_embedded_changed, status_icon);
1017 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1018 gtk_status_icon_orientation_changed, status_icon);
1019 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1020 gtk_status_icon_padding_changed, status_icon);
1021 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1022 gtk_status_icon_icon_size_changed, status_icon);
1023 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1024 gtk_status_icon_fg_changed, status_icon);
1025 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1026 gtk_status_icon_color_changed, status_icon);
1027 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1028 gtk_status_icon_button_press, status_icon);
1029 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1030 gtk_status_icon_button_release, status_icon);
1031 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1032 gtk_status_icon_scroll, status_icon);
1033 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1034 gtk_status_icon_query_tooltip, status_icon);
1035 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1036 gtk_status_icon_screen_changed, status_icon);
1037 gtk_widget_destroy (priv->image);
1038 gtk_widget_destroy (priv->tray_icon);
1041 #ifdef GDK_WINDOWING_WIN32
1042 if (priv->nid.hWnd != NULL && priv->visible)
1043 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1044 if (priv->nid.hIcon)
1045 DestroyIcon (priv->nid.hIcon);
1046 g_free (priv->tooltip_text);
1048 gtk_widget_destroy (priv->dummy_widget);
1050 status_icons = g_slist_remove (status_icons, status_icon);
1053 #ifdef GDK_WINDOWING_QUARTZ
1055 [priv->status_item release];
1056 QUARTZ_POOL_RELEASE;
1057 g_free (priv->tooltip_text);
1060 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1064 gtk_status_icon_set_property (GObject *object,
1066 const GValue *value,
1069 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1074 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1077 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1080 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1082 case PROP_ICON_NAME:
1083 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1086 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1089 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1092 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1094 case PROP_HAS_TOOLTIP:
1095 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1097 case PROP_TOOLTIP_TEXT:
1098 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1100 case PROP_TOOLTIP_MARKUP:
1101 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1104 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1113 gtk_status_icon_get_property (GObject *object,
1118 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1119 GtkStatusIconPrivate *priv = status_icon->priv;
1121 /* The "getter" functions whine if you try to get the wrong
1122 * storage type. This function is instead robust against that,
1123 * so that GUI builders don't have to jump through hoops
1124 * to avoid g_warning
1130 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1131 g_value_set_object (value, NULL);
1133 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1136 if (priv->storage_type != GTK_IMAGE_STOCK)
1137 g_value_set_string (value, NULL);
1139 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1141 case PROP_ICON_NAME:
1142 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1143 g_value_set_string (value, NULL);
1145 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1148 if (priv->storage_type != GTK_IMAGE_GICON)
1149 g_value_set_object (value, NULL);
1151 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1153 case PROP_STORAGE_TYPE:
1154 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1157 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1160 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1163 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1166 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1168 case PROP_ORIENTATION:
1169 #ifdef GDK_WINDOWING_X11
1170 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1172 #ifdef GDK_WINDOWING_WIN32
1173 g_value_set_enum (value, status_icon->priv->orientation);
1176 case PROP_HAS_TOOLTIP:
1177 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1179 case PROP_TOOLTIP_TEXT:
1180 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1182 case PROP_TOOLTIP_MARKUP:
1183 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1186 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1195 * gtk_status_icon_new:
1197 * Creates an empty status icon object.
1199 * Return value: a new #GtkStatusIcon
1204 gtk_status_icon_new (void)
1206 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1210 * gtk_status_icon_new_from_pixbuf:
1211 * @pixbuf: a #GdkPixbuf
1213 * Creates a status icon displaying @pixbuf.
1215 * The image will be scaled down to fit in the available
1216 * space in the notification area, if necessary.
1218 * Return value: a new #GtkStatusIcon
1223 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1225 return g_object_new (GTK_TYPE_STATUS_ICON,
1231 * gtk_status_icon_new_from_file:
1232 * @filename: (type filename): a filename
1234 * Creates a status icon displaying the file @filename.
1236 * The image will be scaled down to fit in the available
1237 * space in the notification area, if necessary.
1239 * Return value: a new #GtkStatusIcon
1244 gtk_status_icon_new_from_file (const gchar *filename)
1246 return g_object_new (GTK_TYPE_STATUS_ICON,
1252 * gtk_status_icon_new_from_stock:
1253 * @stock_id: a stock icon id
1255 * Creates a status icon displaying a stock icon. Sample stock icon
1256 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1257 * own stock icon names, see gtk_icon_factory_add_default() and
1258 * gtk_icon_factory_add().
1260 * Return value: a new #GtkStatusIcon
1265 gtk_status_icon_new_from_stock (const gchar *stock_id)
1267 return g_object_new (GTK_TYPE_STATUS_ICON,
1273 * gtk_status_icon_new_from_icon_name:
1274 * @icon_name: an icon name
1276 * Creates a status icon displaying an icon from the current icon theme.
1277 * If the current icon theme is changed, the icon will be updated
1280 * Return value: a new #GtkStatusIcon
1285 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1287 return g_object_new (GTK_TYPE_STATUS_ICON,
1288 "icon-name", icon_name,
1293 * gtk_status_icon_new_from_gicon:
1296 * Creates a status icon displaying a #GIcon. If the icon is a
1297 * themed icon, it will be updated when the theme changes.
1299 * Return value: a new #GtkStatusIcon
1304 gtk_status_icon_new_from_gicon (GIcon *icon)
1306 return g_object_new (GTK_TYPE_STATUS_ICON,
1312 emit_activate_signal (GtkStatusIcon *status_icon)
1314 g_signal_emit (status_icon,
1315 status_icon_signals [ACTIVATE_SIGNAL], 0);
1319 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1321 guint32 activate_time)
1323 g_signal_emit (status_icon,
1324 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1329 #ifdef GDK_WINDOWING_X11
1332 emit_size_changed_signal (GtkStatusIcon *status_icon,
1335 gboolean handled = FALSE;
1337 g_signal_emit (status_icon,
1338 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1347 #ifdef GDK_WINDOWING_X11
1350 find_icon_size (GtkWidget *widget,
1354 GtkSettings *settings;
1355 GtkIconSize s, size;
1358 screen = gtk_widget_get_screen (widget);
1361 return GTK_ICON_SIZE_MENU;
1363 settings = gtk_settings_get_for_screen (screen);
1366 size = GTK_ICON_SIZE_MENU;
1368 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1370 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1371 w <= pixel_size && h <= pixel_size)
1373 d = MAX (pixel_size - w, pixel_size - h);
1388 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1390 GtkStatusIconPrivate *priv = status_icon->priv;
1391 #ifdef GDK_WINDOWING_WIN32
1395 switch (priv->storage_type)
1397 case GTK_IMAGE_PIXBUF:
1401 pixbuf = priv->image_data.pixbuf;
1412 width = gdk_pixbuf_get_width (pixbuf);
1413 height = gdk_pixbuf_get_height (pixbuf);
1415 if (width > size || height > size)
1416 scaled = gdk_pixbuf_scale_simple (pixbuf,
1419 GDK_INTERP_BILINEAR);
1421 scaled = g_object_ref (pixbuf);
1423 #ifdef GDK_WINDOWING_X11
1424 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1426 #ifdef GDK_WINDOWING_WIN32
1427 prev_hicon = priv->nid.hIcon;
1428 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1429 priv->nid.uFlags |= NIF_ICON;
1430 if (priv->nid.hWnd != NULL && priv->visible)
1431 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1432 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1434 DestroyIcon (prev_hicon);
1436 #ifdef GDK_WINDOWING_QUARTZ
1438 [priv->status_item setImage:scaled];
1439 QUARTZ_POOL_RELEASE;
1442 g_object_unref (scaled);
1446 #ifdef GDK_WINDOWING_X11
1447 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1449 #ifdef GDK_WINDOWING_WIN32
1450 priv->nid.uFlags &= ~NIF_ICON;
1451 if (priv->nid.hWnd != NULL && priv->visible)
1452 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1453 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1455 #ifdef GDK_WINDOWING_QUARTZ
1456 [priv->status_item setImage:NULL];
1462 case GTK_IMAGE_STOCK:
1464 #ifdef GDK_WINDOWING_X11
1465 GtkIconSize size = find_icon_size (priv->image, priv->size);
1466 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1467 priv->image_data.stock_id,
1470 #ifdef GDK_WINDOWING_WIN32
1473 gtk_widget_render_icon_pixbuf (priv->dummy_widget,
1474 priv->image_data.stock_id,
1475 GTK_ICON_SIZE_SMALL_TOOLBAR);
1477 prev_hicon = priv->nid.hIcon;
1478 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1479 priv->nid.uFlags |= NIF_ICON;
1480 if (priv->nid.hWnd != NULL && priv->visible)
1481 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1482 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1484 DestroyIcon (prev_hicon);
1485 g_object_unref (pixbuf);
1488 #ifdef GDK_WINDOWING_QUARTZ
1492 pixbuf = gtk_widget_render_icon_pixbuf (priv->dummy_widget,
1493 priv->image_data.stock_id,
1494 GTK_ICON_SIZE_SMALL_TOOLBAR);
1496 [priv->status_item setImage:pixbuf];
1497 QUARTZ_POOL_RELEASE;
1498 g_object_unref (pixbuf);
1504 case GTK_IMAGE_ICON_NAME:
1506 #ifdef GDK_WINDOWING_X11
1507 GtkIconSize size = find_icon_size (priv->image, priv->size);
1508 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1509 priv->image_data.icon_name,
1512 #ifdef GDK_WINDOWING_WIN32
1515 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1516 priv->image_data.icon_name,
1520 prev_hicon = priv->nid.hIcon;
1521 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1522 priv->nid.uFlags |= NIF_ICON;
1523 if (priv->nid.hWnd != NULL && priv->visible)
1524 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1525 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1527 DestroyIcon (prev_hicon);
1528 g_object_unref (pixbuf);
1531 #ifdef GDK_WINDOWING_QUARTZ
1535 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1536 priv->image_data.icon_name,
1541 [priv->status_item setImage:pixbuf];
1542 QUARTZ_POOL_RELEASE;
1543 g_object_unref (pixbuf);
1550 case GTK_IMAGE_GICON:
1552 #ifdef GDK_WINDOWING_X11
1553 GtkIconSize size = find_icon_size (priv->image, priv->size);
1554 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1555 priv->image_data.gicon,
1558 #ifdef GDK_WINDOWING_WIN32
1561 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1562 priv->image_data.gicon,
1565 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1567 prev_hicon = priv->nid.hIcon;
1568 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1569 priv->nid.uFlags |= NIF_ICON;
1570 if (priv->nid.hWnd != NULL && priv->visible)
1571 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1572 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1574 DestroyIcon (prev_hicon);
1575 g_object_unref (pixbuf);
1578 #ifdef GDK_WINDOWING_QUARTZ
1581 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1582 priv->image_data.gicon,
1585 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1588 [priv->status_item setImage:pixbuf];
1589 QUARTZ_POOL_RELEASE;
1590 g_object_unref (pixbuf);
1597 case GTK_IMAGE_EMPTY:
1598 #ifdef GDK_WINDOWING_X11
1599 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1601 #ifdef GDK_WINDOWING_WIN32
1602 priv->nid.uFlags &= ~NIF_ICON;
1603 if (priv->nid.hWnd != NULL && priv->visible)
1604 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1605 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1607 #ifdef GDK_WINDOWING_QUARTZ
1610 [priv->status_item setImage:NULL];
1611 QUARTZ_POOL_RELEASE;
1616 g_assert_not_reached ();
1621 #ifdef GDK_WINDOWING_X11
1624 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1625 GtkAllocation *allocation)
1627 GtkStatusIconPrivate *priv = status_icon->priv;
1628 GtkOrientation orientation;
1632 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1634 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1635 size = allocation->height;
1637 size = allocation->width;
1639 gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);
1641 priv->image_width = allocation->width - xpad * 2;
1642 priv->image_height = allocation->height - ypad * 2;
1644 if (priv->size != size)
1648 g_object_notify (G_OBJECT (status_icon), "size");
1650 if (!emit_size_changed_signal (status_icon, size))
1651 gtk_status_icon_update_image (status_icon);
1656 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1657 GdkScreen *old_screen)
1659 GtkStatusIconPrivate *priv = status_icon->priv;
1661 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1663 g_object_notify (G_OBJECT (status_icon), "screen");
1669 #ifdef GDK_WINDOWING_X11
1672 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1674 GtkStatusIconPrivate *priv = status_icon->priv;
1675 GtkOrientation orientation;
1678 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1679 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1681 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1683 gtk_widget_set_margin_left (priv->image, padding);
1684 gtk_widget_set_margin_right (priv->image, padding);
1688 gtk_widget_set_margin_bottom (priv->image, padding);
1689 gtk_widget_set_margin_top (priv->image, padding);
1694 gtk_status_icon_icon_size_changed (GtkStatusIcon *status_icon)
1696 GtkStatusIconPrivate *priv = status_icon->priv;
1699 icon_size = _gtk_tray_icon_get_icon_size (GTK_TRAY_ICON (priv->tray_icon));
1702 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size);
1704 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), -1);
1708 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1710 gtk_status_icon_padding_changed (status_icon);
1711 gtk_status_icon_icon_size_changed (status_icon);
1712 g_object_notify (G_OBJECT (status_icon), "embedded");
1716 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1718 gtk_status_icon_padding_changed (status_icon);
1719 g_object_notify (G_OBJECT (status_icon), "orientation");
1723 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1725 GtkStatusIconPrivate *priv = status_icon->priv;
1728 g_object_get (priv->tray_icon, "fg-color", &rgba, NULL);
1730 gtk_widget_override_color (priv->image, GTK_STATE_FLAG_NORMAL, rgba);
1732 gdk_rgba_free (rgba);
1736 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1738 GtkStatusIcon *status_icon)
1740 GtkStatusIconPrivate *priv = status_icon->priv;
1743 switch (pspec->name[0])
1763 g_object_get (priv->tray_icon, pspec->name, &rgba, NULL);
1767 gtk_widget_override_symbolic_color (priv->image, name, &rgba);
1772 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1775 guint state, keyval;
1777 state = event->state & gtk_accelerator_get_default_mod_mask ();
1778 keyval = event->keyval;
1780 (keyval == GDK_KEY_Return ||
1781 keyval == GDK_KEY_KP_Enter ||
1782 keyval == GDK_KEY_ISO_Enter ||
1783 keyval == GDK_KEY_space ||
1784 keyval == GDK_KEY_KP_Space))
1786 emit_activate_signal (status_icon);
1794 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1796 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1802 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1803 GdkEventButton *event)
1805 gboolean handled = FALSE;
1807 g_signal_emit (status_icon,
1808 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1813 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1815 emit_activate_signal (status_icon);
1818 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1820 emit_popup_menu_signal (status_icon, event->button, event->time);
1828 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1829 GdkEventButton *event)
1831 gboolean handled = FALSE;
1832 g_signal_emit (status_icon,
1833 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1838 #ifdef GDK_WINDOWING_X11
1840 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1841 GdkEventScroll *event)
1843 gboolean handled = FALSE;
1844 g_signal_emit (status_icon,
1845 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1851 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1854 gboolean keyboard_tip,
1855 GtkTooltip *tooltip)
1857 gboolean handled = FALSE;
1858 g_signal_emit (status_icon,
1859 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1860 x, y, keyboard_tip, tooltip, &handled);
1863 #endif /* GDK_WINDOWING_X11 */
1866 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1868 GtkStatusIconPrivate *priv = status_icon->priv;
1870 switch (priv->storage_type)
1872 case GTK_IMAGE_PIXBUF:
1873 if (priv->image_data.pixbuf)
1874 g_object_unref (priv->image_data.pixbuf);
1875 priv->image_data.pixbuf = NULL;
1876 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1879 case GTK_IMAGE_STOCK:
1880 g_free (priv->image_data.stock_id);
1881 priv->image_data.stock_id = NULL;
1883 g_object_notify (G_OBJECT (status_icon), "stock");
1886 case GTK_IMAGE_ICON_NAME:
1887 g_free (priv->image_data.icon_name);
1888 priv->image_data.icon_name = NULL;
1890 g_object_notify (G_OBJECT (status_icon), "icon-name");
1893 case GTK_IMAGE_GICON:
1894 if (priv->image_data.gicon)
1895 g_object_unref (priv->image_data.gicon);
1896 priv->image_data.gicon = NULL;
1898 g_object_notify (G_OBJECT (status_icon), "gicon");
1901 case GTK_IMAGE_EMPTY:
1904 g_assert_not_reached ();
1908 priv->storage_type = GTK_IMAGE_EMPTY;
1909 g_object_notify (G_OBJECT (status_icon), "storage-type");
1913 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1914 GtkImageType storage_type,
1917 GtkStatusIconPrivate *priv = status_icon->priv;
1919 g_object_freeze_notify (G_OBJECT (status_icon));
1921 gtk_status_icon_reset_image_data (status_icon);
1923 priv->storage_type = storage_type;
1924 g_object_notify (G_OBJECT (status_icon), "storage-type");
1926 switch (storage_type)
1928 case GTK_IMAGE_PIXBUF:
1929 priv->image_data.pixbuf = (GdkPixbuf *)data;
1930 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1932 case GTK_IMAGE_STOCK:
1933 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1934 g_object_notify (G_OBJECT (status_icon), "stock");
1936 case GTK_IMAGE_ICON_NAME:
1937 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1938 g_object_notify (G_OBJECT (status_icon), "icon-name");
1940 case GTK_IMAGE_GICON:
1941 priv->image_data.gicon = (GIcon *)data;
1942 g_object_notify (G_OBJECT (status_icon), "gicon");
1945 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1948 g_object_thaw_notify (G_OBJECT (status_icon));
1950 gtk_status_icon_update_image (status_icon);
1954 * gtk_status_icon_set_from_pixbuf:
1955 * @status_icon: a #GtkStatusIcon
1956 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1958 * Makes @status_icon display @pixbuf.
1959 * See gtk_status_icon_new_from_pixbuf() for details.
1964 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1967 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1968 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1971 g_object_ref (pixbuf);
1973 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1978 * gtk_status_icon_set_from_file:
1979 * @status_icon: a #GtkStatusIcon
1980 * @filename: (type filename): a filename
1982 * Makes @status_icon display the file @filename.
1983 * See gtk_status_icon_new_from_file() for details.
1988 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1989 const gchar *filename)
1993 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1994 g_return_if_fail (filename != NULL);
1996 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1998 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
2001 g_object_unref (pixbuf);
2005 * gtk_status_icon_set_from_stock:
2006 * @status_icon: a #GtkStatusIcon
2007 * @stock_id: a stock icon id
2009 * Makes @status_icon display the stock icon with the id @stock_id.
2010 * See gtk_status_icon_new_from_stock() for details.
2015 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
2016 const gchar *stock_id)
2018 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2019 g_return_if_fail (stock_id != NULL);
2021 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
2022 (gpointer) stock_id);
2026 * gtk_status_icon_set_from_icon_name:
2027 * @status_icon: a #GtkStatusIcon
2028 * @icon_name: an icon name
2030 * Makes @status_icon display the icon named @icon_name from the
2031 * current icon theme.
2032 * See gtk_status_icon_new_from_icon_name() for details.
2037 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
2038 const gchar *icon_name)
2040 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2041 g_return_if_fail (icon_name != NULL);
2043 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
2044 (gpointer) icon_name);
2048 * gtk_status_icon_set_from_gicon:
2049 * @status_icon: a #GtkStatusIcon
2052 * Makes @status_icon display the #GIcon.
2053 * See gtk_status_icon_new_from_gicon() for details.
2058 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
2061 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2062 g_return_if_fail (icon != NULL);
2065 g_object_ref (icon);
2067 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
2072 * gtk_status_icon_get_storage_type:
2073 * @status_icon: a #GtkStatusIcon
2075 * Gets the type of representation being used by the #GtkStatusIcon
2076 * to store image data. If the #GtkStatusIcon has no image data,
2077 * the return value will be %GTK_IMAGE_EMPTY.
2079 * Return value: the image representation being used
2084 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2086 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2088 return status_icon->priv->storage_type;
2091 * gtk_status_icon_get_pixbuf:
2092 * @status_icon: a #GtkStatusIcon
2094 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2095 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2096 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2097 * The caller of this function does not own a reference to the
2100 * Return value: (transfer none): the displayed pixbuf,
2101 * or %NULL if the image is empty.
2106 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2108 GtkStatusIconPrivate *priv;
2110 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2112 priv = status_icon->priv;
2114 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2115 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2117 if (priv->storage_type == GTK_IMAGE_EMPTY)
2118 priv->image_data.pixbuf = NULL;
2120 return priv->image_data.pixbuf;
2124 * gtk_status_icon_get_stock:
2125 * @status_icon: a #GtkStatusIcon
2127 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2128 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2129 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2130 * The returned string is owned by the #GtkStatusIcon and should not
2131 * be freed or modified.
2133 * Return value: stock id of the displayed stock icon,
2134 * or %NULL if the image is empty.
2138 G_CONST_RETURN gchar *
2139 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
2141 GtkStatusIconPrivate *priv;
2143 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2145 priv = status_icon->priv;
2147 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
2148 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2150 if (priv->storage_type == GTK_IMAGE_EMPTY)
2151 priv->image_data.stock_id = NULL;
2153 return priv->image_data.stock_id;
2157 * gtk_status_icon_get_icon_name:
2158 * @status_icon: a #GtkStatusIcon
2160 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2161 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2162 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
2163 * The returned string is owned by the #GtkStatusIcon and should not
2164 * be freed or modified.
2166 * Return value: name of the displayed icon, or %NULL if the image is empty.
2170 G_CONST_RETURN gchar *
2171 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2173 GtkStatusIconPrivate *priv;
2175 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2177 priv = status_icon->priv;
2179 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2180 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2182 if (priv->storage_type == GTK_IMAGE_EMPTY)
2183 priv->image_data.icon_name = NULL;
2185 return priv->image_data.icon_name;
2189 * gtk_status_icon_get_gicon:
2190 * @status_icon: a #GtkStatusIcon
2192 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2193 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2194 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2195 * The caller of this function does not own a reference to the
2198 * If this function fails, @icon is left unchanged;
2200 * Returns: (transfer none): the displayed icon, or %NULL if the image is empty
2205 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2207 GtkStatusIconPrivate *priv;
2209 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2211 priv = status_icon->priv;
2213 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2214 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2216 if (priv->storage_type == GTK_IMAGE_EMPTY)
2217 priv->image_data.gicon = NULL;
2219 return priv->image_data.gicon;
2223 * gtk_status_icon_get_size:
2224 * @status_icon: a #GtkStatusIcon
2226 * Gets the size in pixels that is available for the image.
2227 * Stock icons and named icons adapt their size automatically
2228 * if the size of the notification area changes. For other
2229 * storage types, the size-changed signal can be used to
2230 * react to size changes.
2232 * Note that the returned size is only meaningful while the
2233 * status icon is embedded (see gtk_status_icon_is_embedded()).
2235 * Return value: the size that is available for the image
2240 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2242 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2244 return status_icon->priv->size;
2248 * gtk_status_icon_set_screen:
2249 * @status_icon: a #GtkStatusIcon
2250 * @screen: a #GdkScreen
2252 * Sets the #GdkScreen where @status_icon is displayed; if
2253 * the icon is already mapped, it will be unmapped, and
2254 * then remapped on the new screen.
2259 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2262 g_return_if_fail (GDK_IS_SCREEN (screen));
2264 #ifdef GDK_WINDOWING_X11
2265 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2270 * gtk_status_icon_get_screen:
2271 * @status_icon: a #GtkStatusIcon
2273 * Returns the #GdkScreen associated with @status_icon.
2275 * Return value: (transfer none): a #GdkScreen.
2280 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2282 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2284 #ifdef GDK_WINDOWING_X11
2285 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2287 return gdk_screen_get_default ();
2292 * gtk_status_icon_set_visible:
2293 * @status_icon: a #GtkStatusIcon
2294 * @visible: %TRUE to show the status icon, %FALSE to hide it
2296 * Shows or hides a status icon.
2301 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2304 GtkStatusIconPrivate *priv;
2306 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2308 priv = status_icon->priv;
2310 visible = visible != FALSE;
2312 if (priv->visible != visible)
2314 priv->visible = visible;
2316 #ifdef GDK_WINDOWING_X11
2318 gtk_widget_show (priv->tray_icon);
2319 else if (gtk_widget_get_realized (priv->tray_icon))
2321 gtk_widget_hide (priv->tray_icon);
2322 gtk_widget_unrealize (priv->tray_icon);
2325 #ifdef GDK_WINDOWING_WIN32
2326 if (priv->nid.hWnd != NULL)
2329 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2331 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2334 #ifdef GDK_WINDOWING_QUARTZ
2336 [priv->status_item setVisible:visible];
2337 QUARTZ_POOL_RELEASE;
2339 g_object_notify (G_OBJECT (status_icon), "visible");
2344 * gtk_status_icon_get_visible:
2345 * @status_icon: a #GtkStatusIcon
2347 * Returns whether the status icon is visible or not.
2348 * Note that being visible does not guarantee that
2349 * the user can actually see the icon, see also
2350 * gtk_status_icon_is_embedded().
2352 * Return value: %TRUE if the status icon is visible
2357 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2359 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2361 return status_icon->priv->visible;
2365 * gtk_status_icon_is_embedded:
2366 * @status_icon: a #GtkStatusIcon
2368 * Returns whether the status icon is embedded in a notification
2371 * Return value: %TRUE if the status icon is embedded in
2372 * a notification area.
2377 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2379 #ifdef GDK_WINDOWING_X11
2383 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2385 #ifdef GDK_WINDOWING_X11
2386 plug = GTK_PLUG (status_icon->priv->tray_icon);
2388 if (gtk_plug_get_embedded (plug))
2393 #ifdef GDK_WINDOWING_WIN32
2396 #ifdef GDK_WINDOWING_QUARTZ
2402 * gtk_status_icon_position_menu:
2403 * @menu: the #GtkMenu
2404 * @x: (out): return location for the x position
2405 * @y: (out): return location for the y position
2406 * @push_in: (out): whether the first menu item should be offset
2407 * (pushed in) to be aligned with the menu popup position
2408 * (only useful for GtkOptionMenu).
2409 * @user_data: (type GtkStatusIcon): the status icon to position the menu on
2411 * Menu positioning function to use with gtk_menu_popup()
2412 * to position @menu aligned to the status icon @user_data.
2417 gtk_status_icon_position_menu (GtkMenu *menu,
2423 #ifdef GDK_WINDOWING_X11
2424 GtkAllocation allocation;
2425 GtkStatusIcon *status_icon;
2426 GtkStatusIconPrivate *priv;
2427 GtkTrayIcon *tray_icon;
2430 GtkTextDirection direction;
2431 GtkRequisition menu_req;
2432 GdkRectangle monitor;
2434 gint monitor_num, height, width, xoffset, yoffset;
2436 g_return_if_fail (GTK_IS_MENU (menu));
2437 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2439 status_icon = GTK_STATUS_ICON (user_data);
2440 priv = status_icon->priv;
2441 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2442 widget = priv->tray_icon;
2444 direction = gtk_widget_get_direction (widget);
2446 screen = gtk_widget_get_screen (widget);
2447 gtk_menu_set_screen (menu, screen);
2449 window = gtk_widget_get_window (widget);
2450 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2451 if (monitor_num < 0)
2453 gtk_menu_set_monitor (menu, monitor_num);
2455 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2457 gdk_window_get_origin (window, x, y);
2459 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2462 gtk_widget_get_allocation (widget, &allocation);
2463 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2466 height = allocation.height;
2467 xoffset = allocation.width;
2472 width = allocation.width;
2475 yoffset = allocation.height;
2478 if (direction == GTK_TEXT_DIR_RTL)
2480 if ((*x - (menu_req.width - width)) >= monitor.x)
2481 *x -= menu_req.width - width;
2482 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2484 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2485 *x -= menu_req.width - width;
2491 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2493 else if ((*x - (menu_req.width - width)) >= monitor.x)
2494 *x -= menu_req.width - width;
2495 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2498 *x -= menu_req.width - width;
2501 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2503 else if ((*y - (menu_req.height - height)) >= monitor.y)
2504 *y -= menu_req.height - height;
2505 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2508 *y -= menu_req.height - height;
2511 #endif /* GDK_WINDOWING_X11 */
2513 #ifdef GDK_WINDOWING_WIN32
2514 GtkStatusIcon *status_icon;
2515 GtkStatusIconPrivate *priv;
2517 g_return_if_fail (GTK_IS_MENU (menu));
2518 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2520 status_icon = GTK_STATUS_ICON (user_data);
2521 priv = status_icon->priv;
2523 *x = priv->last_click_x;
2524 *y = priv->last_click_y;
2530 * gtk_status_icon_get_geometry:
2531 * @status_icon: a #GtkStatusIcon
2532 * @screen: (out) (transfer none) (allow-none): return location for
2533 * the screen, or %NULL if the information is not needed
2534 * @area: (out) (allow-none): return location for the area occupied by
2535 * the status icon, or %NULL
2536 * @orientation: (out) (allow-none): return location for the
2537 * orientation of the panel in which the status icon is embedded,
2538 * or %NULL. A panel at the top or bottom of the screen is
2539 * horizontal, a panel at the left or right is vertical.
2541 * Obtains information about the location of the status icon
2542 * on screen. This information can be used to e.g. position
2543 * popups like notification bubbles.
2545 * See gtk_status_icon_position_menu() for a more convenient
2546 * alternative for positioning menus.
2548 * Note that some platforms do not allow GTK+ to provide
2549 * this information, and even on platforms that do allow it,
2550 * the information is not reliable unless the status icon
2551 * is embedded in a notification area, see
2552 * gtk_status_icon_is_embedded().
2554 * Return value: %TRUE if the location information has
2560 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2563 GtkOrientation *orientation)
2565 #ifdef GDK_WINDOWING_X11
2566 GtkAllocation allocation;
2568 GtkStatusIconPrivate *priv;
2571 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2573 priv = status_icon->priv;
2574 widget = priv->tray_icon;
2577 *screen = gtk_widget_get_screen (widget);
2581 gdk_window_get_origin (gtk_widget_get_window (widget),
2584 gtk_widget_get_allocation (widget, &allocation);
2587 area->width = allocation.width;
2588 area->height = allocation.height;
2592 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2597 #endif /* GDK_WINDOWING_X11 */
2601 * gtk_status_icon_set_has_tooltip:
2602 * @status_icon: a #GtkStatusIcon
2603 * @has_tooltip: whether or not @status_icon has a tooltip
2605 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2606 * See #GtkStatusIcon:has-tooltip for more information.
2611 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2612 gboolean has_tooltip)
2614 GtkStatusIconPrivate *priv;
2616 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2618 priv = status_icon->priv;
2620 #ifdef GDK_WINDOWING_X11
2621 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2623 #ifdef GDK_WINDOWING_WIN32
2624 if (!has_tooltip && priv->tooltip_text)
2625 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2627 #ifdef GDK_WINDOWING_QUARTZ
2628 if (!has_tooltip && priv->tooltip_text)
2629 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2634 * gtk_status_icon_get_has_tooltip:
2635 * @status_icon: a #GtkStatusIcon
2637 * Returns the current value of the has-tooltip property.
2638 * See #GtkStatusIcon:has-tooltip for more information.
2640 * Return value: current value of has-tooltip on @status_icon.
2645 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2647 GtkStatusIconPrivate *priv;
2648 gboolean has_tooltip = FALSE;
2650 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2652 priv = status_icon->priv;
2654 #ifdef GDK_WINDOWING_X11
2655 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2657 #ifdef GDK_WINDOWING_WIN32
2658 has_tooltip = (priv->tooltip_text != NULL);
2660 #ifdef GDK_WINDOWING_QUARTZ
2661 has_tooltip = (priv->tooltip_text != NULL);
2668 * gtk_status_icon_set_tooltip_text:
2669 * @status_icon: a #GtkStatusIcon
2670 * @text: the contents of the tooltip for @status_icon
2672 * Sets @text as the contents of the tooltip.
2674 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2675 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2678 * See also the #GtkStatusIcon:tooltip-text property and
2679 * gtk_tooltip_set_text().
2684 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2687 GtkStatusIconPrivate *priv;
2689 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2691 priv = status_icon->priv;
2693 #ifdef GDK_WINDOWING_X11
2695 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2698 #ifdef GDK_WINDOWING_WIN32
2700 priv->nid.uFlags &= ~NIF_TIP;
2703 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2705 priv->nid.uFlags |= NIF_TIP;
2706 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2707 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2710 if (priv->nid.hWnd != NULL && priv->visible)
2711 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2712 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2714 g_free (priv->tooltip_text);
2715 priv->tooltip_text = g_strdup (text);
2717 #ifdef GDK_WINDOWING_QUARTZ
2719 [priv->status_item setToolTip:text];
2720 QUARTZ_POOL_RELEASE;
2722 g_free (priv->tooltip_text);
2723 priv->tooltip_text = g_strdup (text);
2728 * gtk_status_icon_get_tooltip_text:
2729 * @status_icon: a #GtkStatusIcon
2731 * Gets the contents of the tooltip for @status_icon.
2733 * Return value: the tooltip text, or %NULL. You should free the
2734 * returned string with g_free() when done.
2739 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2741 GtkStatusIconPrivate *priv;
2742 gchar *tooltip_text = NULL;
2744 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2746 priv = status_icon->priv;
2748 #ifdef GDK_WINDOWING_X11
2749 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2751 #ifdef GDK_WINDOWING_WIN32
2752 if (priv->tooltip_text)
2753 tooltip_text = g_strdup (priv->tooltip_text);
2755 #ifdef GDK_WINDOWING_QUARTZ
2756 if (priv->tooltip_text)
2757 tooltip_text = g_strdup (priv->tooltip_text);
2760 return tooltip_text;
2764 * gtk_status_icon_set_tooltip_markup:
2765 * @status_icon: a #GtkStatusIcon
2766 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2768 * Sets @markup as the contents of the tooltip, which is marked up with
2769 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2771 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2772 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2774 * See also the #GtkStatusIcon:tooltip-markup property and
2775 * gtk_tooltip_set_markup().
2780 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2781 const gchar *markup)
2783 GtkStatusIconPrivate *priv;
2784 #ifndef GDK_WINDOWING_X11
2788 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2790 priv = status_icon->priv;
2792 #ifdef GDK_WINDOWING_X11
2793 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2795 #ifdef GDK_WINDOWING_WIN32
2797 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2798 gtk_status_icon_set_tooltip_text (status_icon, text);
2801 #ifdef GDK_WINDOWING_QUARTZ
2803 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2804 gtk_status_icon_set_tooltip_text (status_icon, text);
2810 * gtk_status_icon_get_tooltip_markup:
2811 * @status_icon: a #GtkStatusIcon
2813 * Gets the contents of the tooltip for @status_icon.
2815 * Return value: the tooltip text, or %NULL. You should free the
2816 * returned string with g_free() when done.
2821 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2823 GtkStatusIconPrivate *priv;
2824 gchar *markup = NULL;
2826 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2828 priv = status_icon->priv;
2830 #ifdef GDK_WINDOWING_X11
2831 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2833 #ifdef GDK_WINDOWING_WIN32
2834 if (priv->tooltip_text)
2835 markup = g_markup_escape_text (priv->tooltip_text, -1);
2837 #ifdef GDK_WINDOWING_QUARTZ
2838 if (priv->tooltip_text)
2839 markup = g_markup_escape_text (priv->tooltip_text, -1);
2846 * gtk_status_icon_get_x11_window_id:
2847 * @status_icon: a #GtkStatusIcon
2849 * This function is only useful on the X11/freedesktop.org platform.
2850 * It returns a window ID for the widget in the underlying
2851 * status icon implementation. This is useful for the Galago
2852 * notification service, which can send a window ID in the protocol
2853 * in order for the server to position notification windows
2854 * pointing to a status icon reliably.
2856 * This function is not intended for other use cases which are
2857 * more likely to be met by one of the non-X11 specific methods, such
2858 * as gtk_status_icon_position_menu().
2860 * Return value: An 32 bit unsigned integer identifier for the
2861 * underlying X11 Window
2866 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2868 #ifdef GDK_WINDOWING_X11
2869 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2870 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2877 * gtk_status_icon_set_title:
2878 * @status_icon: a #GtkStatusIcon
2881 * Sets the title of this tray icon.
2882 * This should be a short, human-readable, localized string
2883 * describing the tray icon. It may be used by tools like screen
2884 * readers to render the tray icon.
2889 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2892 GtkStatusIconPrivate *priv;
2894 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2896 priv = status_icon->priv;
2898 #ifdef GDK_WINDOWING_X11
2899 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2901 #ifdef GDK_WINDOWING_QUARTZ
2902 g_free (priv->title);
2903 priv->title = g_strdup (title);
2905 #ifdef GDK_WINDOWING_WIN32
2906 g_free (priv->title);
2907 priv->title = g_strdup (title);
2910 g_object_notify (G_OBJECT (status_icon), "title");
2914 * gtk_status_icon_get_title:
2915 * @status_icon: a #GtkStatusIcon
2917 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2919 * Returns: the title of the status icon
2923 G_CONST_RETURN gchar *
2924 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2926 GtkStatusIconPrivate *priv;
2928 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2930 priv = status_icon->priv;
2932 #ifdef GDK_WINDOWING_X11
2933 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2935 #ifdef GDK_WINDOWING_QUARTZ
2938 #ifdef GDK_WINDOWING_WIN32
2945 * gtk_status_icon_set_name:
2946 * @status_icon: a #GtkStatusIcon
2949 * Sets the name of this tray icon.
2950 * This should be a string identifying this icon. It is may be
2951 * used for sorting the icons in the tray and will not be shown to
2957 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2960 GtkStatusIconPrivate *priv;
2962 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2964 priv = status_icon->priv;
2966 #ifdef GDK_WINDOWING_X11
2967 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);