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)
58 #define BLINK_TIMEOUT 500
86 BUTTON_PRESS_EVENT_SIGNAL,
87 BUTTON_RELEASE_EVENT_SIGNAL,
93 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
95 #ifdef GDK_WINDOWING_QUARTZ
96 #include "gtkstatusicon-quartz.c"
99 struct _GtkStatusIconPrivate
101 #ifdef GDK_WINDOWING_X11
102 GtkWidget *tray_icon;
106 #ifdef GDK_WINDOWING_WIN32
107 GtkWidget *dummy_widget;
109 gint last_click_x, last_click_y;
110 GtkOrientation orientation;
115 #ifdef GDK_WINDOWING_QUARTZ
116 GtkWidget *dummy_widget;
117 GtkQuartzStatusIcon *status_item;
127 GtkImageType storage_type;
140 static GObject* gtk_status_icon_constructor (GType type,
141 guint n_construct_properties,
142 GObjectConstructParam *construct_params);
143 static void gtk_status_icon_finalize (GObject *object);
144 static void gtk_status_icon_set_property (GObject *object,
148 static void gtk_status_icon_get_property (GObject *object,
153 #ifdef GDK_WINDOWING_X11
154 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
155 GtkAllocation *allocation);
156 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
157 GdkScreen *old_screen);
158 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
159 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
160 static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
161 static void gtk_status_icon_icon_size_changed(GtkStatusIcon *status_icon);
162 static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
163 static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
165 GtkStatusIcon *status_icon);
166 static gboolean gtk_status_icon_scroll (GtkStatusIcon *status_icon,
167 GdkEventScroll *event);
168 static gboolean gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
171 gboolean keyboard_tip,
172 GtkTooltip *tooltip);
174 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
176 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
178 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
179 GdkEventButton *event);
180 static gboolean gtk_status_icon_button_release (GtkStatusIcon *status_icon,
181 GdkEventButton *event);
182 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
183 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
185 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
188 gtk_status_icon_class_init (GtkStatusIconClass *class)
190 GObjectClass *gobject_class = (GObjectClass *) class;
192 gobject_class->constructor = gtk_status_icon_constructor;
193 gobject_class->finalize = gtk_status_icon_finalize;
194 gobject_class->set_property = gtk_status_icon_set_property;
195 gobject_class->get_property = gtk_status_icon_get_property;
197 class->button_press_event = NULL;
198 class->button_release_event = NULL;
199 class->scroll_event = NULL;
200 class->query_tooltip = NULL;
202 g_object_class_install_property (gobject_class,
204 g_param_spec_object ("pixbuf",
206 P_("A GdkPixbuf to display"),
208 GTK_PARAM_READWRITE));
210 g_object_class_install_property (gobject_class,
212 g_param_spec_string ("file",
214 P_("Filename to load and display"),
216 GTK_PARAM_WRITABLE));
218 g_object_class_install_property (gobject_class,
220 g_param_spec_string ("stock",
222 P_("Stock ID for a stock image to display"),
224 GTK_PARAM_READWRITE));
226 g_object_class_install_property (gobject_class,
228 g_param_spec_string ("icon-name",
230 P_("The name of the icon from the icon theme"),
232 GTK_PARAM_READWRITE));
235 * GtkStatusIcon:gicon:
237 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
238 * the image will be updated automatically if the theme changes.
242 g_object_class_install_property (gobject_class,
244 g_param_spec_object ("gicon",
246 P_("The GIcon being displayed"),
248 GTK_PARAM_READWRITE));
250 g_object_class_install_property (gobject_class,
252 g_param_spec_enum ("storage-type",
254 P_("The representation being used for image data"),
257 GTK_PARAM_READABLE));
259 g_object_class_install_property (gobject_class,
261 g_param_spec_int ("size",
263 P_("The size of the icon"),
267 GTK_PARAM_READABLE));
269 g_object_class_install_property (gobject_class,
271 g_param_spec_object ("screen",
273 P_("The screen where this status icon will be displayed"),
275 GTK_PARAM_READWRITE));
277 g_object_class_install_property (gobject_class,
279 g_param_spec_boolean ("visible",
281 P_("Whether the status icon is visible"),
283 GTK_PARAM_READWRITE));
287 * GtkStatusIcon:embedded:
289 * %TRUE if the statusicon is embedded in a notification area.
293 g_object_class_install_property (gobject_class,
295 g_param_spec_boolean ("embedded",
297 P_("Whether the status icon is embedded"),
299 GTK_PARAM_READABLE));
302 * GtkStatusIcon:orientation:
304 * The orientation of the tray in which the statusicon
309 g_object_class_install_property (gobject_class,
311 g_param_spec_enum ("orientation",
313 P_("The orientation of the tray"),
314 GTK_TYPE_ORIENTATION,
315 GTK_ORIENTATION_HORIZONTAL,
316 GTK_PARAM_READABLE));
319 * GtkStatusIcon:has-tooltip:
321 * Enables or disables the emission of #GtkStatusIcon::query-tooltip on
322 * @status_icon. A value of %TRUE indicates that @status_icon can have a
323 * tooltip, in this case the status icon will be queried using
324 * #GtkStatusIcon::query-tooltip to determine whether it will provide a
327 * Note that setting this property to %TRUE for the first time will change
328 * the event masks of the windows of this status icon to include leave-notify
329 * and motion-notify events. This will not be undone when the property is set
332 * Whether this property is respected is platform dependent.
333 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
337 g_object_class_install_property (gobject_class,
339 g_param_spec_boolean ("has-tooltip",
341 P_("Whether this tray icon has a tooltip"),
343 GTK_PARAM_READWRITE));
345 * GtkStatusIcon:tooltip-text:
347 * Sets the text of tooltip to be the given string.
349 * Also see gtk_tooltip_set_text().
351 * This is a convenience property which will take care of getting the
352 * tooltip shown if the given string is not %NULL.
353 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
354 * the default handler for the #GtkStatusIcon::query-tooltip signal
355 * will take care of displaying the tooltip.
357 * Note that some platforms have limitations on the length of tooltips
358 * that they allow on status icons, e.g. Windows only shows the first
363 g_object_class_install_property (gobject_class,
365 g_param_spec_string ("tooltip-text",
367 P_("The contents of the tooltip for this widget"),
369 GTK_PARAM_READWRITE));
371 * GtkStatusIcon:tooltip-markup:
373 * Sets the text of tooltip to be the given string, which is marked up
374 * with the <link linkend="PangoMarkupFormat">Pango text markup
375 * language</link>. Also see gtk_tooltip_set_markup().
377 * This is a convenience property which will take care of getting the
378 * tooltip shown if the given string is not %NULL.
379 * #GtkStatusIcon:has-tooltip will automatically be set to %TRUE and
380 * the default handler for the #GtkStatusIcon::query-tooltip signal
381 * will take care of displaying the tooltip.
383 * On some platforms, embedded markup will be ignored.
387 g_object_class_install_property (gobject_class,
389 g_param_spec_string ("tooltip-markup",
390 P_("Tooltip markup"),
391 P_("The contents of the tooltip for this tray icon"),
393 GTK_PARAM_READWRITE));
397 * GtkStatusIcon:title:
399 * The title of this tray icon. This should be a short, human-readable,
400 * localized string describing the tray icon. It may be used by tools
401 * like screen readers to render the tray icon.
405 g_object_class_install_property (gobject_class,
407 g_param_spec_string ("title",
409 P_("The title of this tray icon"),
411 GTK_PARAM_READWRITE));
414 * GtkStatusIcon::activate:
415 * @status_icon: the object which received the signal
417 * Gets emitted when the user activates the status icon.
418 * If and how status icons can activated is platform-dependent.
420 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
421 * be used by applications and should be wrapped by language bindings.
425 status_icon_signals [ACTIVATE_SIGNAL] =
426 g_signal_new (I_("activate"),
427 G_TYPE_FROM_CLASS (gobject_class),
428 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
429 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
432 g_cclosure_marshal_VOID__VOID,
437 * GtkStatusIcon::popup-menu:
438 * @status_icon: the object which received the signal
439 * @button: the button that was pressed, or 0 if the
440 * signal is not emitted in response to a button press event
441 * @activate_time: the timestamp of the event that
442 * triggered the signal emission
444 * Gets emitted when the user brings up the context menu
445 * of the status icon. Whether status icons can have context
446 * menus and how these are activated is platform-dependent.
448 * The @button and @activate_time parameters should be
449 * passed as the last to arguments to gtk_menu_popup().
451 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
452 * be used by applications and should be wrapped by language bindings.
456 status_icon_signals [POPUP_MENU_SIGNAL] =
457 g_signal_new (I_("popup-menu"),
458 G_TYPE_FROM_CLASS (gobject_class),
459 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
460 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
463 _gtk_marshal_VOID__UINT_UINT,
470 * GtkStatusIcon::size-changed:
471 * @status_icon: the object which received the signal
472 * @size: the new size
474 * Gets emitted when the size available for the image
475 * changes, e.g. because the notification area got resized.
477 * Return value: %TRUE if the icon was updated for the new
478 * size. Otherwise, GTK+ will scale the icon as necessary.
482 status_icon_signals [SIZE_CHANGED_SIGNAL] =
483 g_signal_new (I_("size-changed"),
484 G_TYPE_FROM_CLASS (gobject_class),
486 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
487 g_signal_accumulator_true_handled,
489 _gtk_marshal_BOOLEAN__INT,
495 * GtkStatusIcon::button-press-event:
496 * @status_icon: the object which received the signal
497 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
500 * The ::button-press-event signal will be emitted when a button
501 * (typically from a mouse) is pressed.
503 * Whether this event is emitted is platform-dependent. Use the ::activate
504 * and ::popup-menu signals in preference.
506 * Return value: %TRUE to stop other handlers from being invoked
507 * for the event. %FALSE to propagate the event further.
511 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL] =
512 g_signal_new (I_("button_press_event"),
513 G_TYPE_FROM_CLASS (gobject_class),
515 G_STRUCT_OFFSET (GtkStatusIconClass, button_press_event),
516 g_signal_accumulator_true_handled, NULL,
517 _gtk_marshal_BOOLEAN__BOXED,
519 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
522 * GtkStatusIcon::button-release-event:
523 * @status_icon: the object which received the signal
524 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
527 * The ::button-release-event signal will be emitted when a button
528 * (typically from a mouse) is released.
530 * Whether this event is emitted is platform-dependent. Use the ::activate
531 * and ::popup-menu signals in preference.
533 * Return value: %TRUE to stop other handlers from being invoked
534 * for the event. %FALSE to propagate the event further.
538 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL] =
539 g_signal_new (I_("button_release_event"),
540 G_TYPE_FROM_CLASS (gobject_class),
542 G_STRUCT_OFFSET (GtkStatusIconClass, button_release_event),
543 g_signal_accumulator_true_handled, NULL,
544 _gtk_marshal_BOOLEAN__BOXED,
546 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
549 * GtkStatusIcon::scroll-event:
550 * @status_icon: the object which received the signal.
551 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
554 * The ::scroll-event signal is emitted when a button in the 4 to 7
555 * range is pressed. Wheel mice are usually configured to generate
556 * button press events for buttons 4 and 5 when the wheel is turned.
558 * Whether this event is emitted is platform-dependent.
560 * Returns: %TRUE to stop other handlers from being invoked for the event.
561 * %FALSE to propagate the event further.
565 status_icon_signals[SCROLL_EVENT_SIGNAL] =
566 g_signal_new (I_("scroll_event"),
567 G_TYPE_FROM_CLASS (gobject_class),
569 G_STRUCT_OFFSET (GtkStatusIconClass, scroll_event),
570 g_signal_accumulator_true_handled, NULL,
571 _gtk_marshal_BOOLEAN__BOXED,
573 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
576 * GtkStatusIcon::query-tooltip:
577 * @status_icon: the object which received the signal
578 * @x: the x coordinate of the cursor position where the request has been
579 * emitted, relative to @status_icon
580 * @y: the y coordinate of the cursor position where the request has been
581 * emitted, relative to @status_icon
582 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
583 * @tooltip: a #GtkTooltip
585 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with the
586 * cursor hovering above @status_icon; or emitted when @status_icon got
587 * focus in keyboard mode.
589 * Using the given coordinates, the signal handler should determine
590 * whether a tooltip should be shown for @status_icon. If this is
591 * the case %TRUE should be returned, %FALSE otherwise. Note that if
592 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
593 * should not be used.
595 * The signal handler is free to manipulate @tooltip with the therefore
596 * destined function calls.
598 * Whether this signal is emitted is platform-dependent.
599 * For plain text tooltips, use #GtkStatusIcon:tooltip-text in preference.
601 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
605 status_icon_signals [QUERY_TOOLTIP_SIGNAL] =
606 g_signal_new (I_("query_tooltip"),
607 G_TYPE_FROM_CLASS (gobject_class),
609 G_STRUCT_OFFSET (GtkStatusIconClass, query_tooltip),
610 g_signal_accumulator_true_handled, NULL,
611 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
618 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
621 #ifdef GDK_WINDOWING_WIN32
624 build_button_event (GtkStatusIconPrivate *priv,
629 GdkRectangle monitor0;
631 /* We know that gdk/win32 puts the primary monitor at index 0 */
632 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
633 e->window = g_object_ref (gdk_get_default_root_window ());
634 e->send_event = TRUE;
635 e->time = GetTickCount ();
637 priv->last_click_x = e->x = pos.x + monitor0.x;
638 priv->last_click_y = e->y = pos.y + monitor0.y;
642 //FIXME: e->device = gdk_display_get_default ()->core_pointer;
649 GtkStatusIcon *status_icon;
650 GdkEventButton *event;
651 } ButtonCallbackData;
654 button_callback (gpointer data)
656 ButtonCallbackData *bc = (ButtonCallbackData *) data;
658 if (bc->event->type == GDK_BUTTON_PRESS)
659 gtk_status_icon_button_press (bc->status_icon, bc->event);
661 gtk_status_icon_button_release (bc->status_icon, bc->event);
663 gdk_event_free ((GdkEvent *) bc->event);
669 static UINT taskbar_created_msg = 0;
670 static GSList *status_icons = NULL;
672 static LRESULT CALLBACK
678 if (message == taskbar_created_msg)
682 for (rover = status_icons; rover != NULL; rover = rover->next)
684 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
685 GtkStatusIconPrivate *priv = status_icon->priv;
687 priv->nid.hWnd = hwnd;
688 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
689 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
690 priv->nid.uFlags = NIF_MESSAGE;
692 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
694 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
695 priv->nid.hWnd = NULL;
699 gtk_status_icon_update_image (status_icon);
704 if (message == WM_GTK_TRAY_NOTIFICATION)
706 ButtonCallbackData *bc;
724 if (HIWORD (wparam) == XBUTTON1)
730 bc = g_new (ButtonCallbackData, 1);
731 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
732 bc->status_icon = GTK_STATUS_ICON (wparam);
733 build_button_event (bc->status_icon->priv, bc->event, button);
734 g_idle_add (button_callback, bc);
750 if (HIWORD (wparam) == XBUTTON1)
756 bc = g_new (ButtonCallbackData, 1);
757 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_RELEASE);
758 bc->status_icon = GTK_STATUS_ICON (wparam);
759 build_button_event (bc->status_icon->priv, bc->event, button);
760 g_idle_add (button_callback, bc);
770 return DefWindowProc (hwnd, message, wparam, lparam);
775 create_tray_observer (void)
778 static HWND hwnd = NULL;
780 HINSTANCE hmodule = GetModuleHandle (NULL);
785 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
787 memset (&wclass, 0, sizeof(WNDCLASS));
788 wclass.lpszClassName = "gtkstatusicon-observer";
789 wclass.lpfnWndProc = wndproc;
790 wclass.hInstance = hmodule;
792 klass = RegisterClass (&wclass);
796 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
798 0, 0, 1, 1, NULL, NULL,
802 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
812 gtk_status_icon_init (GtkStatusIcon *status_icon)
814 GtkStatusIconPrivate *priv;
816 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
817 GtkStatusIconPrivate);
818 status_icon->priv = priv;
820 priv->storage_type = GTK_IMAGE_EMPTY;
821 priv->visible = TRUE;
823 #ifdef GDK_WINDOWING_X11
825 priv->image_width = 0;
826 priv->image_height = 0;
828 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
830 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
831 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
834 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
835 G_CALLBACK (gtk_status_icon_key_press), status_icon);
836 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
837 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
838 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
839 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
840 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
841 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
842 g_signal_connect_swapped (priv->tray_icon, "notify::padding",
843 G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
844 g_signal_connect_swapped (priv->tray_icon, "notify::icon-size",
845 G_CALLBACK (gtk_status_icon_icon_size_changed), status_icon);
846 g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
847 G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
848 g_signal_connect (priv->tray_icon, "notify::error-color",
849 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
850 g_signal_connect (priv->tray_icon, "notify::warning-color",
851 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
852 g_signal_connect (priv->tray_icon, "notify::success-color",
853 G_CALLBACK (gtk_status_icon_color_changed), status_icon);
854 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
855 G_CALLBACK (gtk_status_icon_button_press), status_icon);
856 g_signal_connect_swapped (priv->tray_icon, "button-release-event",
857 G_CALLBACK (gtk_status_icon_button_release), status_icon);
858 g_signal_connect_swapped (priv->tray_icon, "scroll-event",
859 G_CALLBACK (gtk_status_icon_scroll), status_icon);
860 g_signal_connect_swapped (priv->tray_icon, "query-tooltip",
861 G_CALLBACK (gtk_status_icon_query_tooltip), status_icon);
862 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
863 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
864 priv->image = gtk_image_new ();
865 gtk_widget_set_can_focus (priv->image, TRUE);
866 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
867 gtk_widget_show (priv->image);
869 /* Force-initialize the symbolic colors */
870 g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
871 g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
872 g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
873 g_object_notify (G_OBJECT (priv->tray_icon), "success-color");
875 g_signal_connect_swapped (priv->image, "size-allocate",
876 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
880 #ifdef GDK_WINDOWING_WIN32
882 /* Get position and orientation of Windows taskbar. */
886 abd.cbSize = sizeof (abd);
887 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
888 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
889 priv->orientation = GTK_ORIENTATION_VERTICAL;
891 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
894 priv->last_click_x = priv->last_click_y = 0;
896 /* Are the system tray icons always 16 pixels square? */
898 priv->image_width = 16;
899 priv->image_height = 16;
901 priv->dummy_widget = gtk_label_new ("");
903 memset (&priv->nid, 0, sizeof (priv->nid));
905 priv->nid.hWnd = create_tray_observer ();
906 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
907 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
908 priv->nid.uFlags = NIF_MESSAGE;
910 /* To help win7 identify the icon create it with an application "unique" tip */
911 if (g_get_prgname ())
913 WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
915 priv->nid.uFlags |= NIF_TIP;
916 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
917 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
921 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
923 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
924 priv->nid.hWnd = NULL;
927 status_icons = g_slist_append (status_icons, status_icon);
931 #ifdef GDK_WINDOWING_QUARTZ
932 priv->dummy_widget = gtk_label_new ("");
936 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
938 priv->image_width = priv->image_height = [priv->status_item getHeight];
939 priv->size = priv->image_height;
947 gtk_status_icon_constructor (GType type,
948 guint n_construct_properties,
949 GObjectConstructParam *construct_params)
952 #ifdef GDK_WINDOWING_X11
953 GtkStatusIcon *status_icon;
954 GtkStatusIconPrivate *priv;
957 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
958 n_construct_properties,
961 #ifdef GDK_WINDOWING_X11
962 status_icon = GTK_STATUS_ICON (object);
963 priv = status_icon->priv;
966 gtk_widget_show (priv->tray_icon);
973 gtk_status_icon_finalize (GObject *object)
975 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
976 GtkStatusIconPrivate *priv = status_icon->priv;
978 gtk_status_icon_reset_image_data (status_icon);
980 #ifdef GDK_WINDOWING_X11
981 g_signal_handlers_disconnect_by_func (priv->tray_icon,
982 gtk_status_icon_key_press, status_icon);
983 g_signal_handlers_disconnect_by_func (priv->tray_icon,
984 gtk_status_icon_popup_menu, status_icon);
985 g_signal_handlers_disconnect_by_func (priv->tray_icon,
986 gtk_status_icon_embedded_changed, status_icon);
987 g_signal_handlers_disconnect_by_func (priv->tray_icon,
988 gtk_status_icon_orientation_changed, status_icon);
989 g_signal_handlers_disconnect_by_func (priv->tray_icon,
990 gtk_status_icon_padding_changed, status_icon);
991 g_signal_handlers_disconnect_by_func (priv->tray_icon,
992 gtk_status_icon_icon_size_changed, status_icon);
993 g_signal_handlers_disconnect_by_func (priv->tray_icon,
994 gtk_status_icon_fg_changed, status_icon);
995 g_signal_handlers_disconnect_by_func (priv->tray_icon,
996 gtk_status_icon_color_changed, status_icon);
997 g_signal_handlers_disconnect_by_func (priv->tray_icon,
998 gtk_status_icon_button_press, status_icon);
999 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1000 gtk_status_icon_button_release, status_icon);
1001 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1002 gtk_status_icon_scroll, status_icon);
1003 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1004 gtk_status_icon_query_tooltip, status_icon);
1005 g_signal_handlers_disconnect_by_func (priv->tray_icon,
1006 gtk_status_icon_screen_changed, status_icon);
1007 gtk_widget_destroy (priv->image);
1008 gtk_widget_destroy (priv->tray_icon);
1011 #ifdef GDK_WINDOWING_WIN32
1012 if (priv->nid.hWnd != NULL && priv->visible)
1013 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1014 if (priv->nid.hIcon)
1015 DestroyIcon (priv->nid.hIcon);
1016 g_free (priv->tooltip_text);
1018 gtk_widget_destroy (priv->dummy_widget);
1020 status_icons = g_slist_remove (status_icons, status_icon);
1023 #ifdef GDK_WINDOWING_QUARTZ
1025 [priv->status_item release];
1026 QUARTZ_POOL_RELEASE;
1027 g_free (priv->tooltip_text);
1030 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
1034 gtk_status_icon_set_property (GObject *object,
1036 const GValue *value,
1039 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1044 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
1047 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
1050 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
1052 case PROP_ICON_NAME:
1053 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
1056 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
1059 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
1062 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
1064 case PROP_HAS_TOOLTIP:
1065 gtk_status_icon_set_has_tooltip (status_icon, g_value_get_boolean (value));
1067 case PROP_TOOLTIP_TEXT:
1068 gtk_status_icon_set_tooltip_text (status_icon, g_value_get_string (value));
1070 case PROP_TOOLTIP_MARKUP:
1071 gtk_status_icon_set_tooltip_markup (status_icon, g_value_get_string (value));
1074 gtk_status_icon_set_title (status_icon, g_value_get_string (value));
1077 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1083 gtk_status_icon_get_property (GObject *object,
1088 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
1089 GtkStatusIconPrivate *priv = status_icon->priv;
1091 /* The "getter" functions whine if you try to get the wrong
1092 * storage type. This function is instead robust against that,
1093 * so that GUI builders don't have to jump through hoops
1094 * to avoid g_warning
1100 if (priv->storage_type != GTK_IMAGE_PIXBUF)
1101 g_value_set_object (value, NULL);
1103 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
1106 if (priv->storage_type != GTK_IMAGE_STOCK)
1107 g_value_set_string (value, NULL);
1109 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
1111 case PROP_ICON_NAME:
1112 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
1113 g_value_set_string (value, NULL);
1115 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
1118 if (priv->storage_type != GTK_IMAGE_GICON)
1119 g_value_set_object (value, NULL);
1121 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
1123 case PROP_STORAGE_TYPE:
1124 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
1127 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
1130 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
1133 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
1136 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
1138 case PROP_ORIENTATION:
1139 #ifdef GDK_WINDOWING_X11
1140 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
1142 #ifdef GDK_WINDOWING_WIN32
1143 g_value_set_enum (value, status_icon->priv->orientation);
1146 case PROP_HAS_TOOLTIP:
1147 g_value_set_boolean (value, gtk_status_icon_get_has_tooltip (status_icon));
1149 case PROP_TOOLTIP_TEXT:
1150 g_value_set_string (value, gtk_status_icon_get_tooltip_text (status_icon));
1152 case PROP_TOOLTIP_MARKUP:
1153 g_value_set_string (value, gtk_status_icon_get_tooltip_markup (status_icon));
1156 g_value_set_string (value, gtk_status_icon_get_title (status_icon));
1159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1165 * gtk_status_icon_new:
1167 * Creates an empty status icon object.
1169 * Return value: a new #GtkStatusIcon
1174 gtk_status_icon_new (void)
1176 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
1180 * gtk_status_icon_new_from_pixbuf:
1181 * @pixbuf: a #GdkPixbuf
1183 * Creates a status icon displaying @pixbuf.
1185 * The image will be scaled down to fit in the available
1186 * space in the notification area, if necessary.
1188 * Return value: a new #GtkStatusIcon
1193 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
1195 return g_object_new (GTK_TYPE_STATUS_ICON,
1201 * gtk_status_icon_new_from_file:
1202 * @filename: (type filename): a filename
1204 * Creates a status icon displaying the file @filename.
1206 * The image will be scaled down to fit in the available
1207 * space in the notification area, if necessary.
1209 * Return value: a new #GtkStatusIcon
1214 gtk_status_icon_new_from_file (const gchar *filename)
1216 return g_object_new (GTK_TYPE_STATUS_ICON,
1222 * gtk_status_icon_new_from_stock:
1223 * @stock_id: a stock icon id
1225 * Creates a status icon displaying a stock icon. Sample stock icon
1226 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
1227 * own stock icon names, see gtk_icon_factory_add_default() and
1228 * gtk_icon_factory_add().
1230 * Return value: a new #GtkStatusIcon
1235 gtk_status_icon_new_from_stock (const gchar *stock_id)
1237 return g_object_new (GTK_TYPE_STATUS_ICON,
1243 * gtk_status_icon_new_from_icon_name:
1244 * @icon_name: an icon name
1246 * Creates a status icon displaying an icon from the current icon theme.
1247 * If the current icon theme is changed, the icon will be updated
1250 * Return value: a new #GtkStatusIcon
1255 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
1257 return g_object_new (GTK_TYPE_STATUS_ICON,
1258 "icon-name", icon_name,
1263 * gtk_status_icon_new_from_gicon:
1266 * Creates a status icon displaying a #GIcon. If the icon is a
1267 * themed icon, it will be updated when the theme changes.
1269 * Return value: a new #GtkStatusIcon
1274 gtk_status_icon_new_from_gicon (GIcon *icon)
1276 return g_object_new (GTK_TYPE_STATUS_ICON,
1282 emit_activate_signal (GtkStatusIcon *status_icon)
1284 g_signal_emit (status_icon,
1285 status_icon_signals [ACTIVATE_SIGNAL], 0);
1289 emit_popup_menu_signal (GtkStatusIcon *status_icon,
1291 guint32 activate_time)
1293 g_signal_emit (status_icon,
1294 status_icon_signals [POPUP_MENU_SIGNAL], 0,
1299 #ifdef GDK_WINDOWING_X11
1302 emit_size_changed_signal (GtkStatusIcon *status_icon,
1305 gboolean handled = FALSE;
1307 g_signal_emit (status_icon,
1308 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
1317 #ifdef GDK_WINDOWING_X11
1320 find_icon_size (GtkWidget *widget,
1324 GtkSettings *settings;
1325 GtkIconSize s, size;
1328 screen = gtk_widget_get_screen (widget);
1331 return GTK_ICON_SIZE_MENU;
1333 settings = gtk_settings_get_for_screen (screen);
1336 size = GTK_ICON_SIZE_MENU;
1338 for (s = GTK_ICON_SIZE_MENU; s <= GTK_ICON_SIZE_DIALOG; s++)
1340 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1341 w <= pixel_size && h <= pixel_size)
1343 d = MAX (pixel_size - w, pixel_size - h);
1358 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1360 GtkStatusIconPrivate *priv = status_icon->priv;
1361 #ifdef GDK_WINDOWING_WIN32
1365 switch (priv->storage_type)
1367 case GTK_IMAGE_PIXBUF:
1371 pixbuf = priv->image_data.pixbuf;
1382 width = gdk_pixbuf_get_width (pixbuf);
1383 height = gdk_pixbuf_get_height (pixbuf);
1385 if (width > size || height > size)
1386 scaled = gdk_pixbuf_scale_simple (pixbuf,
1389 GDK_INTERP_BILINEAR);
1391 scaled = g_object_ref (pixbuf);
1393 #ifdef GDK_WINDOWING_X11
1394 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1396 #ifdef GDK_WINDOWING_WIN32
1397 prev_hicon = priv->nid.hIcon;
1398 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1399 priv->nid.uFlags |= NIF_ICON;
1400 if (priv->nid.hWnd != NULL && priv->visible)
1401 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1402 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1404 DestroyIcon (prev_hicon);
1406 #ifdef GDK_WINDOWING_QUARTZ
1408 [priv->status_item setImage:scaled];
1409 QUARTZ_POOL_RELEASE;
1412 g_object_unref (scaled);
1416 #ifdef GDK_WINDOWING_X11
1417 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1419 #ifdef GDK_WINDOWING_WIN32
1420 priv->nid.uFlags &= ~NIF_ICON;
1421 if (priv->nid.hWnd != NULL && priv->visible)
1422 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1423 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1425 #ifdef GDK_WINDOWING_QUARTZ
1426 [priv->status_item setImage:NULL];
1432 case GTK_IMAGE_STOCK:
1434 #ifdef GDK_WINDOWING_X11
1435 GtkIconSize size = find_icon_size (priv->image, priv->size);
1436 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1437 priv->image_data.stock_id,
1440 #ifdef GDK_WINDOWING_WIN32
1443 gtk_widget_render_icon_pixbuf (priv->dummy_widget,
1444 priv->image_data.stock_id,
1445 GTK_ICON_SIZE_SMALL_TOOLBAR);
1447 prev_hicon = priv->nid.hIcon;
1448 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1449 priv->nid.uFlags |= NIF_ICON;
1450 if (priv->nid.hWnd != NULL && priv->visible)
1451 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1452 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1454 DestroyIcon (prev_hicon);
1455 g_object_unref (pixbuf);
1458 #ifdef GDK_WINDOWING_QUARTZ
1462 pixbuf = gtk_widget_render_icon_pixbuf (priv->dummy_widget,
1463 priv->image_data.stock_id,
1464 GTK_ICON_SIZE_SMALL_TOOLBAR);
1466 [priv->status_item setImage:pixbuf];
1467 QUARTZ_POOL_RELEASE;
1468 g_object_unref (pixbuf);
1474 case GTK_IMAGE_ICON_NAME:
1476 #ifdef GDK_WINDOWING_X11
1477 GtkIconSize size = find_icon_size (priv->image, priv->size);
1478 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1479 priv->image_data.icon_name,
1482 #ifdef GDK_WINDOWING_WIN32
1485 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1486 priv->image_data.icon_name,
1490 prev_hicon = priv->nid.hIcon;
1491 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1492 priv->nid.uFlags |= NIF_ICON;
1493 if (priv->nid.hWnd != NULL && priv->visible)
1494 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1495 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1497 DestroyIcon (prev_hicon);
1498 g_object_unref (pixbuf);
1501 #ifdef GDK_WINDOWING_QUARTZ
1505 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1506 priv->image_data.icon_name,
1511 [priv->status_item setImage:pixbuf];
1512 QUARTZ_POOL_RELEASE;
1513 g_object_unref (pixbuf);
1520 case GTK_IMAGE_GICON:
1522 #ifdef GDK_WINDOWING_X11
1523 GtkIconSize size = find_icon_size (priv->image, priv->size);
1524 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1525 priv->image_data.gicon,
1528 #ifdef GDK_WINDOWING_WIN32
1531 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1532 priv->image_data.gicon,
1535 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1537 prev_hicon = priv->nid.hIcon;
1538 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1539 priv->nid.uFlags |= NIF_ICON;
1540 if (priv->nid.hWnd != NULL && priv->visible)
1541 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1542 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1544 DestroyIcon (prev_hicon);
1545 g_object_unref (pixbuf);
1548 #ifdef GDK_WINDOWING_QUARTZ
1551 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1552 priv->image_data.gicon,
1555 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1558 [priv->status_item setImage:pixbuf];
1559 QUARTZ_POOL_RELEASE;
1560 g_object_unref (pixbuf);
1567 case GTK_IMAGE_EMPTY:
1568 #ifdef GDK_WINDOWING_X11
1569 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1571 #ifdef GDK_WINDOWING_WIN32
1572 priv->nid.uFlags &= ~NIF_ICON;
1573 if (priv->nid.hWnd != NULL && priv->visible)
1574 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1575 g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_MODIFY) failed");
1577 #ifdef GDK_WINDOWING_QUARTZ
1580 [priv->status_item setImage:NULL];
1581 QUARTZ_POOL_RELEASE;
1586 g_assert_not_reached ();
1591 #ifdef GDK_WINDOWING_X11
1594 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1595 GtkAllocation *allocation)
1597 GtkStatusIconPrivate *priv = status_icon->priv;
1598 GtkOrientation orientation;
1602 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1604 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1605 size = allocation->height;
1607 size = allocation->width;
1609 gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);
1611 priv->image_width = allocation->width - xpad * 2;
1612 priv->image_height = allocation->height - ypad * 2;
1614 if (priv->size != size)
1618 g_object_notify (G_OBJECT (status_icon), "size");
1620 if (!emit_size_changed_signal (status_icon, size))
1621 gtk_status_icon_update_image (status_icon);
1626 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1627 GdkScreen *old_screen)
1629 GtkStatusIconPrivate *priv = status_icon->priv;
1631 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1633 g_object_notify (G_OBJECT (status_icon), "screen");
1639 #ifdef GDK_WINDOWING_X11
1642 gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
1644 GtkStatusIconPrivate *priv = status_icon->priv;
1645 GtkOrientation orientation;
1648 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1649 padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
1651 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1652 gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
1654 gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
1658 gtk_status_icon_icon_size_changed (GtkStatusIcon *status_icon)
1660 GtkStatusIconPrivate *priv = status_icon->priv;
1663 icon_size = _gtk_tray_icon_get_icon_size (GTK_TRAY_ICON (priv->tray_icon));
1666 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size);
1668 gtk_image_set_pixel_size (GTK_IMAGE (priv->image), -1);
1672 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1674 gtk_status_icon_padding_changed (status_icon);
1675 gtk_status_icon_icon_size_changed (status_icon);
1676 g_object_notify (G_OBJECT (status_icon), "embedded");
1680 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1682 gtk_status_icon_padding_changed (status_icon);
1683 g_object_notify (G_OBJECT (status_icon), "orientation");
1687 gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
1689 GtkStatusIconPrivate *priv = status_icon->priv;
1692 g_object_get (priv->tray_icon, "fg-color", &color, NULL);
1693 gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, color);
1694 gdk_color_free (color);
1698 gtk_status_icon_color_changed (GtkTrayIcon *tray,
1700 GtkStatusIcon *status_icon)
1702 GtkStatusIconPrivate *priv = status_icon->priv;
1706 switch (pspec->name[0])
1726 g_object_get (priv->tray_icon, pspec->name, &color, NULL);
1728 rgba.red = color->red / 65535.;
1729 rgba.green = color->green / 65535.;
1730 rgba.blue = color->blue / 65535.;
1732 gdk_color_free (color);
1734 gtk_widget_override_symbolic_color (priv->image, name, &rgba);
1739 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1742 guint state, keyval;
1744 state = event->state & gtk_accelerator_get_default_mod_mask ();
1745 keyval = event->keyval;
1747 (keyval == GDK_KEY_Return ||
1748 keyval == GDK_KEY_KP_Enter ||
1749 keyval == GDK_KEY_ISO_Enter ||
1750 keyval == GDK_KEY_space ||
1751 keyval == GDK_KEY_KP_Space))
1753 emit_activate_signal (status_icon);
1761 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1763 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1769 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1770 GdkEventButton *event)
1772 gboolean handled = FALSE;
1774 g_signal_emit (status_icon,
1775 status_icon_signals [BUTTON_PRESS_EVENT_SIGNAL], 0,
1780 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1782 emit_activate_signal (status_icon);
1785 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1787 emit_popup_menu_signal (status_icon, event->button, event->time);
1795 gtk_status_icon_button_release (GtkStatusIcon *status_icon,
1796 GdkEventButton *event)
1798 gboolean handled = FALSE;
1799 g_signal_emit (status_icon,
1800 status_icon_signals [BUTTON_RELEASE_EVENT_SIGNAL], 0,
1805 #ifdef GDK_WINDOWING_X11
1807 gtk_status_icon_scroll (GtkStatusIcon *status_icon,
1808 GdkEventScroll *event)
1810 gboolean handled = FALSE;
1811 g_signal_emit (status_icon,
1812 status_icon_signals [SCROLL_EVENT_SIGNAL], 0,
1818 gtk_status_icon_query_tooltip (GtkStatusIcon *status_icon,
1821 gboolean keyboard_tip,
1822 GtkTooltip *tooltip)
1824 gboolean handled = FALSE;
1825 g_signal_emit (status_icon,
1826 status_icon_signals [QUERY_TOOLTIP_SIGNAL], 0,
1827 x, y, keyboard_tip, tooltip, &handled);
1830 #endif /* GDK_WINDOWING_X11 */
1833 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1835 GtkStatusIconPrivate *priv = status_icon->priv;
1837 switch (priv->storage_type)
1839 case GTK_IMAGE_PIXBUF:
1840 if (priv->image_data.pixbuf)
1841 g_object_unref (priv->image_data.pixbuf);
1842 priv->image_data.pixbuf = NULL;
1843 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1846 case GTK_IMAGE_STOCK:
1847 g_free (priv->image_data.stock_id);
1848 priv->image_data.stock_id = NULL;
1850 g_object_notify (G_OBJECT (status_icon), "stock");
1853 case GTK_IMAGE_ICON_NAME:
1854 g_free (priv->image_data.icon_name);
1855 priv->image_data.icon_name = NULL;
1857 g_object_notify (G_OBJECT (status_icon), "icon-name");
1860 case GTK_IMAGE_GICON:
1861 if (priv->image_data.gicon)
1862 g_object_unref (priv->image_data.gicon);
1863 priv->image_data.gicon = NULL;
1865 g_object_notify (G_OBJECT (status_icon), "gicon");
1868 case GTK_IMAGE_EMPTY:
1871 g_assert_not_reached ();
1875 priv->storage_type = GTK_IMAGE_EMPTY;
1876 g_object_notify (G_OBJECT (status_icon), "storage-type");
1880 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1881 GtkImageType storage_type,
1884 GtkStatusIconPrivate *priv = status_icon->priv;
1886 g_object_freeze_notify (G_OBJECT (status_icon));
1888 gtk_status_icon_reset_image_data (status_icon);
1890 priv->storage_type = storage_type;
1891 g_object_notify (G_OBJECT (status_icon), "storage-type");
1893 switch (storage_type)
1895 case GTK_IMAGE_PIXBUF:
1896 priv->image_data.pixbuf = (GdkPixbuf *)data;
1897 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1899 case GTK_IMAGE_STOCK:
1900 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1901 g_object_notify (G_OBJECT (status_icon), "stock");
1903 case GTK_IMAGE_ICON_NAME:
1904 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1905 g_object_notify (G_OBJECT (status_icon), "icon-name");
1907 case GTK_IMAGE_GICON:
1908 priv->image_data.gicon = (GIcon *)data;
1909 g_object_notify (G_OBJECT (status_icon), "gicon");
1912 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1915 g_object_thaw_notify (G_OBJECT (status_icon));
1917 gtk_status_icon_update_image (status_icon);
1921 * gtk_status_icon_set_from_pixbuf:
1922 * @status_icon: a #GtkStatusIcon
1923 * @pixbuf: (allow-none): a #GdkPixbuf or %NULL
1925 * Makes @status_icon display @pixbuf.
1926 * See gtk_status_icon_new_from_pixbuf() for details.
1931 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1934 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1935 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1938 g_object_ref (pixbuf);
1940 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1945 * gtk_status_icon_set_from_file:
1946 * @status_icon: a #GtkStatusIcon
1947 * @filename: (type filename): a filename
1949 * Makes @status_icon display the file @filename.
1950 * See gtk_status_icon_new_from_file() for details.
1955 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1956 const gchar *filename)
1960 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1961 g_return_if_fail (filename != NULL);
1963 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1965 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1968 g_object_unref (pixbuf);
1972 * gtk_status_icon_set_from_stock:
1973 * @status_icon: a #GtkStatusIcon
1974 * @stock_id: a stock icon id
1976 * Makes @status_icon display the stock icon with the id @stock_id.
1977 * See gtk_status_icon_new_from_stock() for details.
1982 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1983 const gchar *stock_id)
1985 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1986 g_return_if_fail (stock_id != NULL);
1988 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1989 (gpointer) stock_id);
1993 * gtk_status_icon_set_from_icon_name:
1994 * @status_icon: a #GtkStatusIcon
1995 * @icon_name: an icon name
1997 * Makes @status_icon display the icon named @icon_name from the
1998 * current icon theme.
1999 * See gtk_status_icon_new_from_icon_name() for details.
2004 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
2005 const gchar *icon_name)
2007 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2008 g_return_if_fail (icon_name != NULL);
2010 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
2011 (gpointer) icon_name);
2015 * gtk_status_icon_set_from_gicon:
2016 * @status_icon: a #GtkStatusIcon
2019 * Makes @status_icon display the #GIcon.
2020 * See gtk_status_icon_new_from_gicon() for details.
2025 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
2028 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2029 g_return_if_fail (icon != NULL);
2032 g_object_ref (icon);
2034 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
2039 * gtk_status_icon_get_storage_type:
2040 * @status_icon: a #GtkStatusIcon
2042 * Gets the type of representation being used by the #GtkStatusIcon
2043 * to store image data. If the #GtkStatusIcon has no image data,
2044 * the return value will be %GTK_IMAGE_EMPTY.
2046 * Return value: the image representation being used
2051 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
2053 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
2055 return status_icon->priv->storage_type;
2058 * gtk_status_icon_get_pixbuf:
2059 * @status_icon: a #GtkStatusIcon
2061 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
2062 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2063 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
2064 * The caller of this function does not own a reference to the
2067 * Return value: (transfer none): the displayed pixbuf,
2068 * or %NULL if the image is empty.
2073 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
2075 GtkStatusIconPrivate *priv;
2077 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2079 priv = status_icon->priv;
2081 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
2082 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2084 if (priv->storage_type == GTK_IMAGE_EMPTY)
2085 priv->image_data.pixbuf = NULL;
2087 return priv->image_data.pixbuf;
2091 * gtk_status_icon_get_stock:
2092 * @status_icon: a #GtkStatusIcon
2094 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
2095 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2096 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
2097 * The returned string is owned by the #GtkStatusIcon and should not
2098 * be freed or modified.
2100 * Return value: stock id of the displayed stock icon,
2101 * or %NULL if the image is empty.
2105 G_CONST_RETURN gchar *
2106 gtk_status_icon_get_stock (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_STOCK ||
2115 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2117 if (priv->storage_type == GTK_IMAGE_EMPTY)
2118 priv->image_data.stock_id = NULL;
2120 return priv->image_data.stock_id;
2124 * gtk_status_icon_get_icon_name:
2125 * @status_icon: a #GtkStatusIcon
2127 * Gets the name of the icon being displayed by the #GtkStatusIcon.
2128 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2129 * %GTK_IMAGE_ICON_NAME (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: name of the displayed icon, or %NULL if the image is empty.
2137 G_CONST_RETURN gchar *
2138 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
2140 GtkStatusIconPrivate *priv;
2142 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2144 priv = status_icon->priv;
2146 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
2147 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2149 if (priv->storage_type == GTK_IMAGE_EMPTY)
2150 priv->image_data.icon_name = NULL;
2152 return priv->image_data.icon_name;
2156 * gtk_status_icon_get_gicon:
2157 * @status_icon: a #GtkStatusIcon
2159 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
2160 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
2161 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
2162 * The caller of this function does not own a reference to the
2165 * If this function fails, @icon is left unchanged;
2167 * Returns: (transfer none): the displayed icon, or %NULL if the image is empty
2172 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
2174 GtkStatusIconPrivate *priv;
2176 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2178 priv = status_icon->priv;
2180 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
2181 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
2183 if (priv->storage_type == GTK_IMAGE_EMPTY)
2184 priv->image_data.gicon = NULL;
2186 return priv->image_data.gicon;
2190 * gtk_status_icon_get_size:
2191 * @status_icon: a #GtkStatusIcon
2193 * Gets the size in pixels that is available for the image.
2194 * Stock icons and named icons adapt their size automatically
2195 * if the size of the notification area changes. For other
2196 * storage types, the size-changed signal can be used to
2197 * react to size changes.
2199 * Note that the returned size is only meaningful while the
2200 * status icon is embedded (see gtk_status_icon_is_embedded()).
2202 * Return value: the size that is available for the image
2207 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
2209 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
2211 return status_icon->priv->size;
2215 * gtk_status_icon_set_screen:
2216 * @status_icon: a #GtkStatusIcon
2217 * @screen: a #GdkScreen
2219 * Sets the #GdkScreen where @status_icon is displayed; if
2220 * the icon is already mapped, it will be unmapped, and
2221 * then remapped on the new screen.
2226 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
2229 g_return_if_fail (GDK_IS_SCREEN (screen));
2231 #ifdef GDK_WINDOWING_X11
2232 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
2237 * gtk_status_icon_get_screen:
2238 * @status_icon: a #GtkStatusIcon
2240 * Returns the #GdkScreen associated with @status_icon.
2242 * Return value: (transfer none): a #GdkScreen.
2247 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
2249 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2251 #ifdef GDK_WINDOWING_X11
2252 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
2254 return gdk_screen_get_default ();
2259 * gtk_status_icon_set_visible:
2260 * @status_icon: a #GtkStatusIcon
2261 * @visible: %TRUE to show the status icon, %FALSE to hide it
2263 * Shows or hides a status icon.
2268 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
2271 GtkStatusIconPrivate *priv;
2273 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2275 priv = status_icon->priv;
2277 visible = visible != FALSE;
2279 if (priv->visible != visible)
2281 priv->visible = visible;
2283 #ifdef GDK_WINDOWING_X11
2285 gtk_widget_show (priv->tray_icon);
2286 else if (gtk_widget_get_realized (priv->tray_icon))
2288 gtk_widget_hide (priv->tray_icon);
2289 gtk_widget_unrealize (priv->tray_icon);
2292 #ifdef GDK_WINDOWING_WIN32
2293 if (priv->nid.hWnd != NULL)
2296 Shell_NotifyIconW (NIM_ADD, &priv->nid);
2298 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
2301 #ifdef GDK_WINDOWING_QUARTZ
2303 [priv->status_item setVisible:visible];
2304 QUARTZ_POOL_RELEASE;
2306 g_object_notify (G_OBJECT (status_icon), "visible");
2311 * gtk_status_icon_get_visible:
2312 * @status_icon: a #GtkStatusIcon
2314 * Returns whether the status icon is visible or not.
2315 * Note that being visible does not guarantee that
2316 * the user can actually see the icon, see also
2317 * gtk_status_icon_is_embedded().
2319 * Return value: %TRUE if the status icon is visible
2324 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
2326 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2328 return status_icon->priv->visible;
2332 * gtk_status_icon_is_embedded:
2333 * @status_icon: a #GtkStatusIcon
2335 * Returns whether the status icon is embedded in a notification
2338 * Return value: %TRUE if the status icon is embedded in
2339 * a notification area.
2344 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2346 #ifdef GDK_WINDOWING_X11
2350 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2352 #ifdef GDK_WINDOWING_X11
2353 plug = GTK_PLUG (status_icon->priv->tray_icon);
2355 if (gtk_plug_get_embedded (plug))
2360 #ifdef GDK_WINDOWING_WIN32
2363 #ifdef GDK_WINDOWING_QUARTZ
2369 * gtk_status_icon_position_menu:
2370 * @menu: the #GtkMenu
2371 * @x: (out): return location for the x position
2372 * @y: (out): return location for the y position
2373 * @push_in: (out): whether the first menu item should be offset
2374 * (pushed in) to be aligned with the menu popup position
2375 * (only useful for GtkOptionMenu).
2376 * @user_data: (type GtkStatusIcon): the status icon to position the menu on
2378 * Menu positioning function to use with gtk_menu_popup()
2379 * to position @menu aligned to the status icon @user_data.
2384 gtk_status_icon_position_menu (GtkMenu *menu,
2390 #ifdef GDK_WINDOWING_X11
2391 GtkAllocation allocation;
2392 GtkStatusIcon *status_icon;
2393 GtkStatusIconPrivate *priv;
2394 GtkTrayIcon *tray_icon;
2397 GtkTextDirection direction;
2398 GtkRequisition menu_req;
2399 GdkRectangle monitor;
2401 gint monitor_num, height, width, xoffset, yoffset;
2403 g_return_if_fail (GTK_IS_MENU (menu));
2404 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2406 status_icon = GTK_STATUS_ICON (user_data);
2407 priv = status_icon->priv;
2408 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2409 widget = priv->tray_icon;
2411 direction = gtk_widget_get_direction (widget);
2413 screen = gtk_widget_get_screen (widget);
2414 gtk_menu_set_screen (menu, screen);
2416 window = gtk_widget_get_window (widget);
2417 monitor_num = gdk_screen_get_monitor_at_window (screen, window);
2418 if (monitor_num < 0)
2420 gtk_menu_set_monitor (menu, monitor_num);
2422 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2424 gdk_window_get_origin (window, x, y);
2426 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2429 gtk_widget_get_allocation (widget, &allocation);
2430 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2433 height = allocation.height;
2434 xoffset = allocation.width;
2439 width = allocation.width;
2442 yoffset = allocation.height;
2445 if (direction == GTK_TEXT_DIR_RTL)
2447 if ((*x - (menu_req.width - width)) >= monitor.x)
2448 *x -= menu_req.width - width;
2449 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2451 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2452 *x -= menu_req.width - width;
2458 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2460 else if ((*x - (menu_req.width - width)) >= monitor.x)
2461 *x -= menu_req.width - width;
2462 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2465 *x -= menu_req.width - width;
2468 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2470 else if ((*y - (menu_req.height - height)) >= monitor.y)
2471 *y -= menu_req.height - height;
2472 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2475 *y -= menu_req.height - height;
2478 #endif /* GDK_WINDOWING_X11 */
2480 #ifdef GDK_WINDOWING_WIN32
2481 GtkStatusIcon *status_icon;
2482 GtkStatusIconPrivate *priv;
2484 g_return_if_fail (GTK_IS_MENU (menu));
2485 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2487 status_icon = GTK_STATUS_ICON (user_data);
2488 priv = status_icon->priv;
2490 *x = priv->last_click_x;
2491 *y = priv->last_click_y;
2497 * gtk_status_icon_get_geometry:
2498 * @status_icon: a #GtkStatusIcon
2499 * @screen: (out) (transfer none) (allow-none): return location for
2500 * the screen, or %NULL if the information is not needed
2501 * @area: (out) (allow-none): return location for the area occupied by
2502 * the status icon, or %NULL
2503 * @orientation: (out) (allow-none): return location for the
2504 * orientation of the panel in which the status icon is embedded,
2505 * or %NULL. A panel at the top or bottom of the screen is
2506 * horizontal, a panel at the left or right is vertical.
2508 * Obtains information about the location of the status icon
2509 * on screen. This information can be used to e.g. position
2510 * popups like notification bubbles.
2512 * See gtk_status_icon_position_menu() for a more convenient
2513 * alternative for positioning menus.
2515 * Note that some platforms do not allow GTK+ to provide
2516 * this information, and even on platforms that do allow it,
2517 * the information is not reliable unless the status icon
2518 * is embedded in a notification area, see
2519 * gtk_status_icon_is_embedded().
2521 * Return value: %TRUE if the location information has
2527 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2530 GtkOrientation *orientation)
2532 #ifdef GDK_WINDOWING_X11
2533 GtkAllocation allocation;
2535 GtkStatusIconPrivate *priv;
2538 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2540 priv = status_icon->priv;
2541 widget = priv->tray_icon;
2544 *screen = gtk_widget_get_screen (widget);
2548 gdk_window_get_origin (gtk_widget_get_window (widget),
2551 gtk_widget_get_allocation (widget, &allocation);
2554 area->width = allocation.width;
2555 area->height = allocation.height;
2559 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2564 #endif /* GDK_WINDOWING_X11 */
2568 * gtk_status_icon_set_has_tooltip:
2569 * @status_icon: a #GtkStatusIcon
2570 * @has_tooltip: whether or not @status_icon has a tooltip
2572 * Sets the has-tooltip property on @status_icon to @has_tooltip.
2573 * See #GtkStatusIcon:has-tooltip for more information.
2578 gtk_status_icon_set_has_tooltip (GtkStatusIcon *status_icon,
2579 gboolean has_tooltip)
2581 GtkStatusIconPrivate *priv;
2583 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2585 priv = status_icon->priv;
2587 #ifdef GDK_WINDOWING_X11
2588 gtk_widget_set_has_tooltip (priv->tray_icon, has_tooltip);
2590 #ifdef GDK_WINDOWING_WIN32
2591 if (!has_tooltip && priv->tooltip_text)
2592 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2594 #ifdef GDK_WINDOWING_QUARTZ
2595 if (!has_tooltip && priv->tooltip_text)
2596 gtk_status_icon_set_tooltip_text (status_icon, NULL);
2601 * gtk_status_icon_get_has_tooltip:
2602 * @status_icon: a #GtkStatusIcon
2604 * Returns the current value of the has-tooltip property.
2605 * See #GtkStatusIcon:has-tooltip for more information.
2607 * Return value: current value of has-tooltip on @status_icon.
2612 gtk_status_icon_get_has_tooltip (GtkStatusIcon *status_icon)
2614 GtkStatusIconPrivate *priv;
2615 gboolean has_tooltip = FALSE;
2617 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2619 priv = status_icon->priv;
2621 #ifdef GDK_WINDOWING_X11
2622 has_tooltip = gtk_widget_get_has_tooltip (priv->tray_icon);
2624 #ifdef GDK_WINDOWING_WIN32
2625 has_tooltip = (priv->tooltip_text != NULL);
2627 #ifdef GDK_WINDOWING_QUARTZ
2628 has_tooltip = (priv->tooltip_text != NULL);
2635 * gtk_status_icon_set_tooltip_text:
2636 * @status_icon: a #GtkStatusIcon
2637 * @text: the contents of the tooltip for @status_icon
2639 * Sets @text as the contents of the tooltip.
2641 * This function will take care of setting #GtkStatusIcon:has-tooltip to
2642 * %TRUE and of the default handler for the #GtkStatusIcon::query-tooltip
2645 * See also the #GtkStatusIcon:tooltip-text property and
2646 * gtk_tooltip_set_text().
2651 gtk_status_icon_set_tooltip_text (GtkStatusIcon *status_icon,
2654 GtkStatusIconPrivate *priv;
2656 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2658 priv = status_icon->priv;
2660 #ifdef GDK_WINDOWING_X11
2662 gtk_widget_set_tooltip_text (priv->tray_icon, text);
2665 #ifdef GDK_WINDOWING_WIN32
2667 priv->nid.uFlags &= ~NIF_TIP;
2670 WCHAR *wcs = g_utf8_to_utf16 (text, -1, NULL, NULL, NULL);
2672 priv->nid.uFlags |= NIF_TIP;
2673 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
2674 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
2677 if (priv->nid.hWnd != NULL && priv->visible)
2678 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
2679 g_warning (G_STRLOC ": Shell_NotifyIconW(NIM_MODIFY) failed");
2681 g_free (priv->tooltip_text);
2682 priv->tooltip_text = g_strdup (text);
2684 #ifdef GDK_WINDOWING_QUARTZ
2686 [priv->status_item setToolTip:text];
2687 QUARTZ_POOL_RELEASE;
2689 g_free (priv->tooltip_text);
2690 priv->tooltip_text = g_strdup (text);
2695 * gtk_status_icon_get_tooltip_text:
2696 * @status_icon: a #GtkStatusIcon
2698 * Gets the contents of the tooltip for @status_icon.
2700 * Return value: the tooltip text, or %NULL. You should free the
2701 * returned string with g_free() when done.
2706 gtk_status_icon_get_tooltip_text (GtkStatusIcon *status_icon)
2708 GtkStatusIconPrivate *priv;
2709 gchar *tooltip_text = NULL;
2711 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2713 priv = status_icon->priv;
2715 #ifdef GDK_WINDOWING_X11
2716 tooltip_text = gtk_widget_get_tooltip_text (priv->tray_icon);
2718 #ifdef GDK_WINDOWING_WIN32
2719 if (priv->tooltip_text)
2720 tooltip_text = g_strdup (priv->tooltip_text);
2722 #ifdef GDK_WINDOWING_QUARTZ
2723 if (priv->tooltip_text)
2724 tooltip_text = g_strdup (priv->tooltip_text);
2727 return tooltip_text;
2731 * gtk_status_icon_set_tooltip_markup:
2732 * @status_icon: a #GtkStatusIcon
2733 * @markup: (allow-none): the contents of the tooltip for @status_icon, or %NULL
2735 * Sets @markup as the contents of the tooltip, which is marked up with
2736 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
2738 * This function will take care of setting #GtkStatusIcon:has-tooltip to %TRUE
2739 * and of the default handler for the #GtkStatusIcon::query-tooltip signal.
2741 * See also the #GtkStatusIcon:tooltip-markup property and
2742 * gtk_tooltip_set_markup().
2747 gtk_status_icon_set_tooltip_markup (GtkStatusIcon *status_icon,
2748 const gchar *markup)
2750 GtkStatusIconPrivate *priv;
2751 #ifndef GDK_WINDOWING_X11
2755 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2757 priv = status_icon->priv;
2759 #ifdef GDK_WINDOWING_X11
2760 gtk_widget_set_tooltip_markup (priv->tray_icon, markup);
2762 #ifdef GDK_WINDOWING_WIN32
2764 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2765 gtk_status_icon_set_tooltip_text (status_icon, text);
2768 #ifdef GDK_WINDOWING_QUARTZ
2770 pango_parse_markup (markup, -1, 0, NULL, &text, NULL, NULL);
2771 gtk_status_icon_set_tooltip_text (status_icon, text);
2777 * gtk_status_icon_get_tooltip_markup:
2778 * @status_icon: a #GtkStatusIcon
2780 * Gets the contents of the tooltip for @status_icon.
2782 * Return value: the tooltip text, or %NULL. You should free the
2783 * returned string with g_free() when done.
2788 gtk_status_icon_get_tooltip_markup (GtkStatusIcon *status_icon)
2790 GtkStatusIconPrivate *priv;
2791 gchar *markup = NULL;
2793 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2795 priv = status_icon->priv;
2797 #ifdef GDK_WINDOWING_X11
2798 markup = gtk_widget_get_tooltip_markup (priv->tray_icon);
2800 #ifdef GDK_WINDOWING_WIN32
2801 if (priv->tooltip_text)
2802 markup = g_markup_escape_text (priv->tooltip_text, -1);
2804 #ifdef GDK_WINDOWING_QUARTZ
2805 if (priv->tooltip_text)
2806 markup = g_markup_escape_text (priv->tooltip_text, -1);
2813 * gtk_status_icon_get_x11_window_id:
2814 * @status_icon: a #GtkStatusIcon
2816 * This function is only useful on the X11/freedesktop.org platform.
2817 * It returns a window ID for the widget in the underlying
2818 * status icon implementation. This is useful for the Galago
2819 * notification service, which can send a window ID in the protocol
2820 * in order for the server to position notification windows
2821 * pointing to a status icon reliably.
2823 * This function is not intended for other use cases which are
2824 * more likely to be met by one of the non-X11 specific methods, such
2825 * as gtk_status_icon_position_menu().
2827 * Return value: An 32 bit unsigned integer identifier for the
2828 * underlying X11 Window
2833 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2835 #ifdef GDK_WINDOWING_X11
2836 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2837 return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (status_icon->priv->tray_icon)));
2844 * gtk_status_icon_set_title:
2845 * @status_icon: a #GtkStatusIcon
2848 * Sets the title of this tray icon.
2849 * This should be a short, human-readable, localized string
2850 * describing the tray icon. It may be used by tools like screen
2851 * readers to render the tray icon.
2856 gtk_status_icon_set_title (GtkStatusIcon *status_icon,
2859 GtkStatusIconPrivate *priv;
2861 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2863 priv = status_icon->priv;
2865 #ifdef GDK_WINDOWING_X11
2866 gtk_window_set_title (GTK_WINDOW (priv->tray_icon), title);
2868 #ifdef GDK_WINDOWING_QUARTZ
2869 g_free (priv->title);
2870 priv->title = g_strdup (title);
2872 #ifdef GDK_WINDOWING_WIN32
2873 g_free (priv->title);
2874 priv->title = g_strdup (title);
2877 g_object_notify (G_OBJECT (status_icon), "title");
2881 * gtk_status_icon_get_title:
2882 * @status_icon: a #GtkStatusIcon
2884 * Gets the title of this tray icon. See gtk_status_icon_set_title().
2886 * Returns: the title of the status icon
2890 G_CONST_RETURN gchar *
2891 gtk_status_icon_get_title (GtkStatusIcon *status_icon)
2893 GtkStatusIconPrivate *priv;
2895 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
2897 priv = status_icon->priv;
2899 #ifdef GDK_WINDOWING_X11
2900 return gtk_window_get_title (GTK_WINDOW (priv->tray_icon));
2902 #ifdef GDK_WINDOWING_QUARTZ
2905 #ifdef GDK_WINDOWING_WIN32
2912 * gtk_status_icon_set_name:
2913 * @status_icon: a #GtkStatusIcon
2916 * Sets the name of this tray icon.
2917 * This should be a string identifying this icon. It is may be
2918 * used for sorting the icons in the tray and will not be shown to
2924 gtk_status_icon_set_name (GtkStatusIcon *status_icon,
2927 GtkStatusIconPrivate *priv;
2929 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2931 priv = status_icon->priv;
2933 #ifdef GDK_WINDOWING_X11
2934 gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);