3 * Copyright (C) 2003 Sun Microsystems, Inc.
4 * Copyright (C) 2005 Hans Breuer <hans@breuer.org>
5 * Copyright (C) 2005 Novell, Inc.
6 * Copyright (C) 2006 Imendio AB
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Mark McLoughlin <mark@skynet.ie>
25 * Hans Breuer <hans@breuer.org>
26 * Tor Lillqvist <tml@novell.com>
27 * Mikael Hallendal <micke@imendio.com>
33 #include "gtkstatusicon.h"
36 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
39 #include "gtktrayicon.h"
41 #include "gtkprivate.h"
42 #include "gtkwidget.h"
44 #ifdef GDK_WINDOWING_X11
45 #include "gdk/x11/gdkx.h"
48 #ifdef GDK_WINDOWING_WIN32
49 #include "gtkicontheme.h"
52 #include "win32/gdkwin32.h"
53 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
56 #ifdef GDK_WINDOWING_QUARTZ
57 #include "gtkicontheme.h"
61 #include "gdkkeysyms.h"
65 #define BLINK_TIMEOUT 500
92 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
94 #ifdef GDK_WINDOWING_QUARTZ
95 #include "gtkstatusicon-quartz.c"
98 struct _GtkStatusIconPrivate
100 #ifdef GDK_WINDOWING_X11
101 GtkWidget *tray_icon;
105 #ifdef GDK_WINDOWING_WIN32
106 GtkWidget *dummy_widget;
108 gint last_click_x, last_click_y;
109 GtkOrientation orientation;
112 #ifdef GDK_WINDOWING_QUARTZ
113 GtkWidget *dummy_widget;
114 GtkQuartzStatusIcon *status_item;
122 GtkImageType storage_type;
132 GdkPixbuf *blank_icon;
133 guint blinking_timeout;
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);
161 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
163 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
165 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
166 GdkEventButton *event);
167 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
168 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
169 static void gtk_status_icon_update_image (GtkStatusIcon *status_icon);
171 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
174 gtk_status_icon_class_init (GtkStatusIconClass *class)
176 GObjectClass *gobject_class = (GObjectClass *) class;
178 gobject_class->constructor = gtk_status_icon_constructor;
179 gobject_class->finalize = gtk_status_icon_finalize;
180 gobject_class->set_property = gtk_status_icon_set_property;
181 gobject_class->get_property = gtk_status_icon_get_property;
183 g_object_class_install_property (gobject_class,
185 g_param_spec_object ("pixbuf",
187 P_("A GdkPixbuf to display"),
189 GTK_PARAM_READWRITE));
191 g_object_class_install_property (gobject_class,
193 g_param_spec_string ("file",
195 P_("Filename to load and display"),
197 GTK_PARAM_WRITABLE));
199 g_object_class_install_property (gobject_class,
201 g_param_spec_string ("stock",
203 P_("Stock ID for a stock image to display"),
205 GTK_PARAM_READWRITE));
207 g_object_class_install_property (gobject_class,
209 g_param_spec_string ("icon-name",
211 P_("The name of the icon from the icon theme"),
213 GTK_PARAM_READWRITE));
216 * GtkStatusIcon:gicon:
218 * The #GIcon displayed in the #GtkStatusIcon. For themed icons,
219 * the image will be updated automatically if the theme changes.
223 g_object_class_install_property (gobject_class,
225 g_param_spec_object ("gicon",
227 P_("The GIcon being displayed"),
229 GTK_PARAM_READWRITE));
231 g_object_class_install_property (gobject_class,
233 g_param_spec_enum ("storage-type",
235 P_("The representation being used for image data"),
238 GTK_PARAM_READABLE));
240 g_object_class_install_property (gobject_class,
242 g_param_spec_int ("size",
244 P_("The size of the icon"),
248 GTK_PARAM_READABLE));
250 g_object_class_install_property (gobject_class,
252 g_param_spec_object ("screen",
254 P_("The screen where this status icon will be displayed"),
256 GTK_PARAM_READWRITE));
258 g_object_class_install_property (gobject_class,
260 g_param_spec_boolean ("blinking",
262 P_("Whether or not the status icon is blinking"),
264 GTK_PARAM_READWRITE));
266 g_object_class_install_property (gobject_class,
268 g_param_spec_boolean ("visible",
270 P_("Whether or not the status icon is visible"),
272 GTK_PARAM_READWRITE));
276 * GtkStatusIcon:embedded:
278 * %TRUE if the statusicon is embedded in a notification area.
282 g_object_class_install_property (gobject_class,
284 g_param_spec_boolean ("embedded",
286 P_("Whether or not the status icon is embedded"),
288 GTK_PARAM_READABLE));
291 * GtkStatusIcon:orientation:
293 * The orientation of the tray in which the statusicon
298 g_object_class_install_property (gobject_class,
300 g_param_spec_enum ("orientation",
302 P_("The orientation of the tray"),
303 GTK_TYPE_ORIENTATION,
304 GTK_ORIENTATION_HORIZONTAL,
305 GTK_PARAM_READABLE));
309 * GtkStatusIcon::activate:
310 * @status_icon: the object which received the signal
312 * Gets emitted when the user activates the status icon.
313 * If and how status icons can activated is platform-dependent.
315 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
316 * be used by applications and should be wrapped by language bindings.
320 status_icon_signals [ACTIVATE_SIGNAL] =
321 g_signal_new (I_("activate"),
322 G_TYPE_FROM_CLASS (gobject_class),
323 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
324 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
327 g_cclosure_marshal_VOID__VOID,
332 * GtkStatusIcon::popup-menu:
333 * @status_icon: the object which received the signal
334 * @button: the button that was pressed, or 0 if the
335 * signal is not emitted in response to a button press event
336 * @activate_time: the timestamp of the event that
337 * triggered the signal emission
339 * Gets emitted when the user brings up the context menu
340 * of the status icon. Whether status icons can have context
341 * menus and how these are activated is platform-dependent.
343 * The @button and @activate_time parameters should be
344 * passed as the last to arguments to gtk_menu_popup().
346 * Unlike most G_SIGNAL_ACTION signals, this signal is meant to
347 * be used by applications and should be wrapped by language bindings.
351 status_icon_signals [POPUP_MENU_SIGNAL] =
352 g_signal_new (I_("popup-menu"),
353 G_TYPE_FROM_CLASS (gobject_class),
354 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
355 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
358 _gtk_marshal_VOID__UINT_UINT,
365 * GtkStatusIcon::size-changed:
366 * @status_icon: the object which received the signal
367 * @size: the new size
369 * Gets emitted when the size available for the image
370 * changes, e.g. because the notification area got resized.
372 * Return value: %TRUE if the icon was updated for the new
373 * size. Otherwise, GTK+ will scale the icon as necessary.
377 status_icon_signals [SIZE_CHANGED_SIGNAL] =
378 g_signal_new (I_("size-changed"),
379 G_TYPE_FROM_CLASS (gobject_class),
381 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
382 g_signal_accumulator_true_handled,
384 _gtk_marshal_BOOLEAN__INT,
389 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
392 #ifdef GDK_WINDOWING_WIN32
395 build_button_event (GtkStatusIconPrivate *priv,
400 GdkRectangle monitor0;
402 /* We know that gdk/win32 puts the primary monitor at index 0 */
403 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
404 e->window = g_object_ref (gdk_get_default_root_window ());
405 e->send_event = TRUE;
406 e->time = GetTickCount ();
408 priv->last_click_x = e->x = pos.x + monitor0.x;
409 priv->last_click_y = e->y = pos.y + monitor0.y;
413 e->device = gdk_display_get_default ()->core_pointer;
420 GtkStatusIcon *status_icon;
421 GdkEventButton *event;
422 } ButtonCallbackData;
425 button_callback (gpointer data)
427 ButtonCallbackData *bc = (ButtonCallbackData *) data;
429 gtk_status_icon_button_press (bc->status_icon, bc->event);
431 gdk_event_free ((GdkEvent *) bc->event);
437 static UINT taskbar_created_msg = 0;
438 static GSList *status_icons = NULL;
440 static LRESULT CALLBACK
446 if (message == taskbar_created_msg)
450 for (rover = status_icons; rover != NULL; rover = rover->next)
452 GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
453 GtkStatusIconPrivate *priv = status_icon->priv;
455 priv->nid.hWnd = hwnd;
456 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
457 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
458 priv->nid.uFlags = NIF_MESSAGE;
460 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
462 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
463 priv->nid.hWnd = NULL;
467 gtk_status_icon_update_image (status_icon);
472 if (message == WM_GTK_TRAY_NOTIFICATION)
474 ButtonCallbackData *bc;
480 bc = g_new (ButtonCallbackData, 1);
481 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
482 bc->status_icon = GTK_STATUS_ICON (wparam);
483 build_button_event (bc->status_icon->priv, bc->event, (lparam == WM_LBUTTONDOWN) ? 1 : 3);
484 g_idle_add (button_callback, bc);
493 return DefWindowProc (hwnd, message, wparam, lparam);
498 create_tray_observer (void)
501 static HWND hwnd = NULL;
503 HINSTANCE hmodule = GetModuleHandle (NULL);
508 taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
510 memset (&wclass, 0, sizeof(WNDCLASS));
511 wclass.lpszClassName = "gtkstatusicon-observer";
512 wclass.lpfnWndProc = wndproc;
513 wclass.hInstance = hmodule;
515 klass = RegisterClass (&wclass);
519 hwnd = CreateWindow (MAKEINTRESOURCE (klass),
521 0, 0, 1, 1, NULL, NULL,
525 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
535 gtk_status_icon_init (GtkStatusIcon *status_icon)
537 GtkStatusIconPrivate *priv;
539 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
540 GtkStatusIconPrivate);
541 status_icon->priv = priv;
543 priv->storage_type = GTK_IMAGE_EMPTY;
544 priv->visible = TRUE;
546 #ifdef GDK_WINDOWING_X11
548 priv->image_width = 0;
549 priv->image_height = 0;
551 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
553 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
554 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
556 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
557 G_CALLBACK (gtk_status_icon_key_press), status_icon);
558 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
559 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
560 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
561 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
562 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
563 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
564 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
565 G_CALLBACK (gtk_status_icon_button_press), status_icon);
566 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
567 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
568 priv->image = gtk_image_new ();
569 GTK_WIDGET_SET_FLAGS (priv->image, GTK_CAN_FOCUS);
570 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
571 gtk_widget_show (priv->image);
573 g_signal_connect_swapped (priv->image, "size-allocate",
574 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
578 #ifdef GDK_WINDOWING_WIN32
580 /* Get position and orientation of Windows taskbar. */
584 abd.cbSize = sizeof (abd);
585 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
586 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
587 priv->orientation = GTK_ORIENTATION_VERTICAL;
589 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
592 priv->last_click_x = priv->last_click_y = 0;
594 /* Are the system tray icons always 16 pixels square? */
596 priv->image_width = 16;
597 priv->image_height = 16;
599 priv->dummy_widget = gtk_label_new ("");
601 memset (&priv->nid, 0, sizeof (priv->nid));
603 priv->nid.hWnd = create_tray_observer ();
604 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
605 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
606 priv->nid.uFlags = NIF_MESSAGE;
608 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
610 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
611 priv->nid.hWnd = NULL;
614 status_icons = g_slist_append (status_icons, status_icon);
618 #ifdef GDK_WINDOWING_QUARTZ
619 priv->dummy_widget = gtk_label_new ("");
623 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
625 priv->image_width = priv->image_height = [priv->status_item getHeight];
626 priv->size = priv->image_height;
634 gtk_status_icon_constructor (GType type,
635 guint n_construct_properties,
636 GObjectConstructParam *construct_params)
639 #ifdef GDK_WINDOWING_X11
640 GtkStatusIcon *status_icon;
641 GtkStatusIconPrivate *priv;
644 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
645 n_construct_properties,
648 #ifdef GDK_WINDOWING_X11
649 status_icon = GTK_STATUS_ICON (object);
650 priv = status_icon->priv;
653 gtk_widget_show (priv->tray_icon);
660 gtk_status_icon_finalize (GObject *object)
662 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
663 GtkStatusIconPrivate *priv = status_icon->priv;
665 gtk_status_icon_disable_blinking (status_icon);
667 gtk_status_icon_reset_image_data (status_icon);
669 if (priv->blank_icon)
670 g_object_unref (priv->blank_icon);
671 priv->blank_icon = NULL;
673 #ifdef GDK_WINDOWING_X11
674 gtk_widget_destroy (priv->tray_icon);
677 #ifdef GDK_WINDOWING_WIN32
678 if (priv->nid.hWnd != NULL && priv->visible)
679 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
681 DestroyIcon (priv->nid.hIcon);
683 gtk_widget_destroy (priv->dummy_widget);
685 status_icons = g_slist_remove (status_icons, status_icon);
688 #ifdef GDK_WINDOWING_QUARTZ
690 [priv->status_item release];
694 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
698 gtk_status_icon_set_property (GObject *object,
703 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
708 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
711 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
714 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
717 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
720 gtk_status_icon_set_from_gicon (status_icon, g_value_get_object (value));
723 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
726 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
729 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
732 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
738 gtk_status_icon_get_property (GObject *object,
743 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
744 GtkStatusIconPrivate *priv = status_icon->priv;
746 /* The "getter" functions whine if you try to get the wrong
747 * storage type. This function is instead robust against that,
748 * so that GUI builders don't have to jump through hoops
755 if (priv->storage_type != GTK_IMAGE_PIXBUF)
756 g_value_set_object (value, NULL);
758 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
761 if (priv->storage_type != GTK_IMAGE_STOCK)
762 g_value_set_string (value, NULL);
764 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
767 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
768 g_value_set_string (value, NULL);
770 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
773 if (priv->storage_type != GTK_IMAGE_GICON)
774 g_value_set_object (value, NULL);
776 g_value_set_object (value, gtk_status_icon_get_gicon (status_icon));
778 case PROP_STORAGE_TYPE:
779 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
782 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
785 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
788 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
791 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
794 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
796 case PROP_ORIENTATION:
797 #ifdef GDK_WINDOWING_X11
798 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
800 #ifdef GDK_WINDOWING_WIN32
801 g_value_set_enum (value, status_icon->priv->orientation);
805 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
811 * gtk_status_icon_new:
813 * Creates an empty status icon object.
815 * Return value: a new #GtkStatusIcon
820 gtk_status_icon_new (void)
822 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
826 * gtk_status_icon_new_from_pixbuf:
827 * @pixbuf: a #GdkPixbuf
829 * Creates a status icon displaying @pixbuf.
831 * The image will be scaled down to fit in the available
832 * space in the notification area, if necessary.
834 * Return value: a new #GtkStatusIcon
839 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
841 return g_object_new (GTK_TYPE_STATUS_ICON,
847 * gtk_status_icon_new_from_file:
848 * @filename: a filename
850 * Creates a status icon displaying the file @filename.
852 * The image will be scaled down to fit in the available
853 * space in the notification area, if necessary.
855 * Return value: a new #GtkStatusIcon
860 gtk_status_icon_new_from_file (const gchar *filename)
862 return g_object_new (GTK_TYPE_STATUS_ICON,
868 * gtk_status_icon_new_from_stock:
869 * @stock_id: a stock icon id
871 * Creates a status icon displaying a stock icon. Sample stock icon
872 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
873 * own stock icon names, see gtk_icon_factory_add_default() and
874 * gtk_icon_factory_add().
876 * Return value: a new #GtkStatusIcon
881 gtk_status_icon_new_from_stock (const gchar *stock_id)
883 return g_object_new (GTK_TYPE_STATUS_ICON,
889 * gtk_status_icon_new_from_icon_name:
890 * @icon_name: an icon name
892 * Creates a status icon displaying an icon from the current icon theme.
893 * If the current icon theme is changed, the icon will be updated
896 * Return value: a new #GtkStatusIcon
901 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
903 return g_object_new (GTK_TYPE_STATUS_ICON,
904 "icon-name", icon_name,
909 * gtk_status_icon_new_from_gicon:
912 * Creates a status icon displaying a #GIcon. If the icon is a
913 * themed icon, it will be updated when the theme changes.
915 * Return value: a new #GtkStatusIcon
920 gtk_status_icon_new_from_gicon (GIcon *icon)
922 return g_object_new (GTK_TYPE_STATUS_ICON,
928 emit_activate_signal (GtkStatusIcon *status_icon)
930 g_signal_emit (status_icon,
931 status_icon_signals [ACTIVATE_SIGNAL], 0);
935 emit_popup_menu_signal (GtkStatusIcon *status_icon,
937 guint32 activate_time)
939 g_signal_emit (status_icon,
940 status_icon_signals [POPUP_MENU_SIGNAL], 0,
945 #ifdef GDK_WINDOWING_X11
948 emit_size_changed_signal (GtkStatusIcon *status_icon,
951 gboolean handled = FALSE;
953 g_signal_emit (status_icon,
954 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
964 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
966 GtkStatusIconPrivate *priv = status_icon->priv;
968 if (priv->blank_icon)
972 width = gdk_pixbuf_get_width (priv->blank_icon);
973 height = gdk_pixbuf_get_height (priv->blank_icon);
976 if (width == priv->image_width && height == priv->image_height)
977 return priv->blank_icon;
980 g_object_unref (priv->blank_icon);
981 priv->blank_icon = NULL;
985 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
988 if (priv->blank_icon)
989 gdk_pixbuf_fill (priv->blank_icon, 0);
991 return priv->blank_icon;
994 #ifdef GDK_WINDOWING_X11
997 find_icon_size (GtkWidget *widget,
1001 GtkSettings *settings;
1002 GtkIconSize s, size;
1005 screen = gtk_widget_get_screen (widget);
1008 return GTK_ICON_SIZE_MENU;
1010 settings = gtk_settings_get_for_screen (screen);
1013 size = GTK_ICON_SIZE_MENU;
1015 for (s = GTK_ICON_SIZE_MENU; s < GTK_ICON_SIZE_DIALOG; s++)
1017 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
1018 w <= pixel_size && h <= pixel_size)
1020 d = MAX (pixel_size - w, pixel_size - h);
1035 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
1037 GtkStatusIconPrivate *priv = status_icon->priv;
1038 #ifdef GDK_WINDOWING_WIN32
1042 if (priv->blink_off)
1044 #ifdef GDK_WINDOWING_X11
1045 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
1046 gtk_status_icon_blank_icon (status_icon));
1048 #ifdef GDK_WINDOWING_WIN32
1049 prev_hicon = priv->nid.hIcon;
1050 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
1051 priv->nid.uFlags |= NIF_ICON;
1052 if (priv->nid.hWnd != NULL && priv->visible)
1053 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1054 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1056 DestroyIcon (prev_hicon);
1058 #ifdef GDK_WINDOWING_QUARTZ
1060 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
1061 QUARTZ_POOL_RELEASE;
1066 switch (priv->storage_type)
1068 case GTK_IMAGE_PIXBUF:
1072 pixbuf = priv->image_data.pixbuf;
1083 width = gdk_pixbuf_get_width (pixbuf);
1084 height = gdk_pixbuf_get_height (pixbuf);
1086 if (width > size || height > size)
1087 scaled = gdk_pixbuf_scale_simple (pixbuf,
1090 GDK_INTERP_BILINEAR);
1092 scaled = g_object_ref (pixbuf);
1094 #ifdef GDK_WINDOWING_X11
1095 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1097 #ifdef GDK_WINDOWING_WIN32
1098 prev_hicon = priv->nid.hIcon;
1099 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1100 priv->nid.uFlags |= NIF_ICON;
1101 if (priv->nid.hWnd != NULL && priv->visible)
1102 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1103 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1105 DestroyIcon (prev_hicon);
1107 #ifdef GDK_WINDOWING_QUARTZ
1109 [priv->status_item setImage:scaled];
1110 QUARTZ_POOL_RELEASE;
1113 g_object_unref (scaled);
1117 #ifdef GDK_WINDOWING_X11
1118 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1120 #ifdef GDK_WINDOWING_WIN32
1121 priv->nid.uFlags &= ~NIF_ICON;
1122 if (priv->nid.hWnd != NULL && priv->visible)
1123 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1124 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1126 #ifdef GDK_WINDOWING_QUARTZ
1127 [priv->status_item setImage:NULL];
1133 case GTK_IMAGE_STOCK:
1135 #ifdef GDK_WINDOWING_X11
1136 GtkIconSize size = find_icon_size (priv->image, priv->size);
1137 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1138 priv->image_data.stock_id,
1141 #ifdef GDK_WINDOWING_WIN32
1144 gtk_widget_render_icon (priv->dummy_widget,
1145 priv->image_data.stock_id,
1146 GTK_ICON_SIZE_SMALL_TOOLBAR,
1149 prev_hicon = priv->nid.hIcon;
1150 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1151 priv->nid.uFlags |= NIF_ICON;
1152 if (priv->nid.hWnd != NULL && priv->visible)
1153 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1154 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1156 DestroyIcon (prev_hicon);
1157 g_object_unref (pixbuf);
1160 #ifdef GDK_WINDOWING_QUARTZ
1164 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1165 priv->image_data.stock_id,
1166 GTK_ICON_SIZE_SMALL_TOOLBAR,
1169 [priv->status_item setImage:pixbuf];
1170 QUARTZ_POOL_RELEASE;
1171 g_object_unref (pixbuf);
1177 case GTK_IMAGE_ICON_NAME:
1179 #ifdef GDK_WINDOWING_X11
1180 GtkIconSize size = find_icon_size (priv->image, priv->size);
1181 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1182 priv->image_data.icon_name,
1185 #ifdef GDK_WINDOWING_WIN32
1188 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1189 priv->image_data.icon_name,
1193 prev_hicon = priv->nid.hIcon;
1194 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1195 priv->nid.uFlags |= NIF_ICON;
1196 if (priv->nid.hWnd != NULL && priv->visible)
1197 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1198 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1200 DestroyIcon (prev_hicon);
1201 g_object_unref (pixbuf);
1204 #ifdef GDK_WINDOWING_QUARTZ
1208 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1209 priv->image_data.icon_name,
1214 [priv->status_item setImage:pixbuf];
1215 QUARTZ_POOL_RELEASE;
1216 g_object_unref (pixbuf);
1223 case GTK_IMAGE_GICON:
1225 #ifdef GDK_WINDOWING_X11
1226 GtkIconSize size = find_icon_size (priv->image, priv->size);
1227 gtk_image_set_from_gicon (GTK_IMAGE (priv->image),
1228 priv->image_data.gicon,
1231 #ifdef GDK_WINDOWING_WIN32
1234 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1235 priv->image_data.gicon,
1238 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1240 prev_hicon = priv->nid.hIcon;
1241 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1242 priv->nid.uFlags |= NIF_ICON;
1243 if (priv->nid.hWnd != NULL && priv->visible)
1244 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1245 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1247 DestroyIcon (prev_hicon);
1248 g_object_unref (pixbuf);
1251 #ifdef GDK_WINDOWING_QUARTZ
1254 gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
1255 priv->image_data.gicon,
1258 GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
1261 [priv->status_item setImage:pixbuf];
1262 QUARTZ_POOL_RELEASE;
1263 g_object_unref (pixbuf);
1270 case GTK_IMAGE_EMPTY:
1271 #ifdef GDK_WINDOWING_X11
1272 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1274 #ifdef GDK_WINDOWING_WIN32
1275 priv->nid.uFlags &= ~NIF_ICON;
1276 if (priv->nid.hWnd != NULL && priv->visible)
1277 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1278 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1280 #ifdef GDK_WINDOWING_QUARTZ
1283 [priv->status_item setImage:NULL];
1284 QUARTZ_POOL_RELEASE;
1289 g_assert_not_reached ();
1294 #ifdef GDK_WINDOWING_X11
1297 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1298 GtkAllocation *allocation)
1300 GtkStatusIconPrivate *priv = status_icon->priv;
1301 GtkOrientation orientation;
1304 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1306 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1307 size = allocation->height;
1309 size = allocation->width;
1311 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1312 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1314 if (priv->size != size)
1318 g_object_notify (G_OBJECT (status_icon), "size");
1320 if (!emit_size_changed_signal (status_icon, size))
1321 gtk_status_icon_update_image (status_icon);
1326 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1327 GdkScreen *old_screen)
1329 GtkStatusIconPrivate *priv = status_icon->priv;
1331 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1333 g_object_notify (G_OBJECT (status_icon), "screen");
1339 #ifdef GDK_WINDOWING_X11
1342 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1344 g_object_notify (G_OBJECT (status_icon), "embedded");
1348 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1350 g_object_notify (G_OBJECT (status_icon), "orientation");
1354 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1357 guint state, keyval;
1359 state = event->state & gtk_accelerator_get_default_mod_mask ();
1360 keyval = event->keyval;
1362 (keyval == GDK_Return ||
1363 keyval == GDK_KP_Enter ||
1364 keyval == GDK_ISO_Enter ||
1365 keyval == GDK_space ||
1366 keyval == GDK_KP_Space))
1368 emit_activate_signal (status_icon);
1376 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1378 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1384 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1385 GdkEventButton *event)
1387 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1389 emit_activate_signal (status_icon);
1392 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1394 emit_popup_menu_signal (status_icon, event->button, event->time);
1402 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1404 GtkStatusIconPrivate *priv = status_icon->priv;
1406 switch (priv->storage_type)
1408 case GTK_IMAGE_PIXBUF:
1409 if (priv->image_data.pixbuf)
1410 g_object_unref (priv->image_data.pixbuf);
1411 priv->image_data.pixbuf = NULL;
1412 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1415 case GTK_IMAGE_STOCK:
1416 g_free (priv->image_data.stock_id);
1417 priv->image_data.stock_id = NULL;
1419 g_object_notify (G_OBJECT (status_icon), "stock");
1422 case GTK_IMAGE_ICON_NAME:
1423 g_free (priv->image_data.icon_name);
1424 priv->image_data.icon_name = NULL;
1426 g_object_notify (G_OBJECT (status_icon), "icon-name");
1429 case GTK_IMAGE_GICON:
1430 g_free (priv->image_data.gicon);
1431 priv->image_data.gicon = NULL;
1433 g_object_notify (G_OBJECT (status_icon), "gicon");
1436 case GTK_IMAGE_EMPTY:
1439 g_assert_not_reached ();
1443 priv->storage_type = GTK_IMAGE_EMPTY;
1444 g_object_notify (G_OBJECT (status_icon), "storage-type");
1448 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1449 GtkImageType storage_type,
1452 GtkStatusIconPrivate *priv = status_icon->priv;
1454 g_object_freeze_notify (G_OBJECT (status_icon));
1456 gtk_status_icon_reset_image_data (status_icon);
1458 priv->storage_type = storage_type;
1459 g_object_notify (G_OBJECT (status_icon), "storage-type");
1461 switch (storage_type)
1463 case GTK_IMAGE_PIXBUF:
1464 priv->image_data.pixbuf = (GdkPixbuf *)data;
1465 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1467 case GTK_IMAGE_STOCK:
1468 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1469 g_object_notify (G_OBJECT (status_icon), "stock");
1471 case GTK_IMAGE_ICON_NAME:
1472 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1473 g_object_notify (G_OBJECT (status_icon), "icon-name");
1475 case GTK_IMAGE_GICON:
1476 priv->image_data.gicon = (GIcon *)data;
1477 g_object_notify (G_OBJECT (status_icon), "gicon");
1480 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1483 g_object_thaw_notify (G_OBJECT (status_icon));
1485 gtk_status_icon_update_image (status_icon);
1489 * gtk_status_icon_set_from_pixbuf:
1490 * @status_icon: a #GtkStatusIcon
1491 * @pixbuf: a #GdkPixbuf or %NULL
1493 * Makes @status_icon display @pixbuf.
1494 * See gtk_status_icon_new_from_pixbuf() for details.
1499 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1502 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1503 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1506 g_object_ref (pixbuf);
1508 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1513 * gtk_status_icon_set_from_file:
1514 * @status_icon: a #GtkStatusIcon
1515 * @filename: a filename
1517 * Makes @status_icon display the file @filename.
1518 * See gtk_status_icon_new_from_file() for details.
1523 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1524 const gchar *filename)
1528 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1529 g_return_if_fail (filename != NULL);
1531 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1533 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1536 g_object_unref (pixbuf);
1540 * gtk_status_icon_set_from_stock:
1541 * @status_icon: a #GtkStatusIcon
1542 * @stock_id: a stock icon id
1544 * Makes @status_icon display the stock icon with the id @stock_id.
1545 * See gtk_status_icon_new_from_stock() for details.
1550 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1551 const gchar *stock_id)
1553 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1554 g_return_if_fail (stock_id != NULL);
1556 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1557 (gpointer) stock_id);
1561 * gtk_status_icon_set_from_icon_name:
1562 * @status_icon: a #GtkStatusIcon
1563 * @icon_name: an icon name
1565 * Makes @status_icon display the icon named @icon_name from the
1566 * current icon theme.
1567 * See gtk_status_icon_new_from_icon_name() for details.
1572 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1573 const gchar *icon_name)
1575 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1576 g_return_if_fail (icon_name != NULL);
1578 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1579 (gpointer) icon_name);
1583 * gtk_status_icon_set_from_gicon:
1584 * @status_icon: a #GtkStatusIcon
1587 * Makes @status_icon display the #GIcon.
1588 * See gtk_status_icon_new_from_gicon() for details.
1593 gtk_status_icon_set_from_gicon (GtkStatusIcon *status_icon,
1596 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1597 g_return_if_fail (icon != NULL);
1599 gtk_status_icon_set_image (status_icon, GTK_IMAGE_GICON,
1604 * gtk_status_icon_get_storage_type:
1605 * @status_icon: a #GtkStatusIcon
1607 * Gets the type of representation being used by the #GtkStatusIcon
1608 * to store image data. If the #GtkStatusIcon has no image data,
1609 * the return value will be %GTK_IMAGE_EMPTY.
1611 * Return value: the image representation being used
1616 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1618 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1620 return status_icon->priv->storage_type;
1623 * gtk_status_icon_get_pixbuf:
1624 * @status_icon: a #GtkStatusIcon
1626 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1627 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1628 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1629 * The caller of this function does not own a reference to the
1632 * Return value: the displayed pixbuf, or %NULL if the image is empty.
1637 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1639 GtkStatusIconPrivate *priv;
1641 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1643 priv = status_icon->priv;
1645 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
1646 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1648 if (priv->storage_type == GTK_IMAGE_EMPTY)
1649 priv->image_data.pixbuf = NULL;
1651 return priv->image_data.pixbuf;
1655 * gtk_status_icon_get_stock:
1656 * @status_icon: a #GtkStatusIcon
1658 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1659 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1660 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1661 * The returned string is owned by the #GtkStatusIcon and should not
1662 * be freed or modified.
1664 * Return value: stock id of the displayed stock icon,
1665 * or %NULL if the image is empty.
1669 G_CONST_RETURN gchar *
1670 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
1672 GtkStatusIconPrivate *priv;
1674 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1676 priv = status_icon->priv;
1678 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
1679 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1681 if (priv->storage_type == GTK_IMAGE_EMPTY)
1682 priv->image_data.stock_id = NULL;
1684 return priv->image_data.stock_id;
1688 * gtk_status_icon_get_icon_name:
1689 * @status_icon: a #GtkStatusIcon
1691 * Gets the name of the icon being displayed by the #GtkStatusIcon.
1692 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1693 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
1694 * The returned string is owned by the #GtkStatusIcon and should not
1695 * be freed or modified.
1697 * Return value: name of the displayed icon, or %NULL if the image is empty.
1701 G_CONST_RETURN gchar *
1702 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
1704 GtkStatusIconPrivate *priv;
1706 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1708 priv = status_icon->priv;
1710 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
1711 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1713 if (priv->storage_type == GTK_IMAGE_EMPTY)
1714 priv->image_data.icon_name = NULL;
1716 return priv->image_data.icon_name;
1720 * gtk_status_icon_get_gicon:
1721 * @status_icon: a #GtkStatusIcon
1723 * Retrieves the #GIcon being displayed by the #GtkStatusIcon.
1724 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1725 * %GTK_IMAGE_GICON (see gtk_status_icon_get_storage_type()).
1726 * The caller of this function does not own a reference to the
1729 * If this function fails, @icon is left unchanged;
1731 * Returns: the displayed icon, or %NULL if the image is empty
1736 gtk_status_icon_get_gicon (GtkStatusIcon *status_icon)
1738 GtkStatusIconPrivate *priv;
1740 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1742 priv = status_icon->priv;
1744 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_GICON ||
1745 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1747 if (priv->storage_type == GTK_IMAGE_EMPTY)
1748 priv->image_data.gicon = NULL;
1750 return priv->image_data.gicon;
1754 * gtk_status_icon_get_size:
1755 * @status_icon: a #GtkStatusIcon
1757 * Gets the size in pixels that is available for the image.
1758 * Stock icons and named icons adapt their size automatically
1759 * if the size of the notification area changes. For other
1760 * storage types, the size-changed signal can be used to
1761 * react to size changes.
1763 * Note that the returned size is only meaningful while the
1764 * status icon is embedded (see gtk_status_icon_is_embedded()).
1766 * Return value: the size that is available for the image
1771 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
1773 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
1775 return status_icon->priv->size;
1779 * gtk_status_icon_set_screen:
1780 * @status_icon: a #GtkStatusIcon
1781 * @screen: a #GdkScreen
1783 * Sets the #GdkScreen where @status_icon is displayed; if
1784 * the icon is already mapped, it will be unmapped, and
1785 * then remapped on the new screen.
1790 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
1793 g_return_if_fail (GDK_IS_SCREEN (screen));
1795 #ifdef GDK_WINDOWING_X11
1796 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
1801 * gtk_status_icon_get_screen:
1802 * @status_icon: a #GtkStatusIcon
1804 * Returns the #GdkScreen associated with @status_icon.
1806 * Return value: a #GdkScreen.
1811 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
1813 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1815 #ifdef GDK_WINDOWING_X11
1816 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
1818 return gdk_screen_get_default ();
1823 * gtk_status_icon_set_tooltip:
1824 * @status_icon: a #GtkStatusIcon
1825 * @tooltip_text: the tooltip text, or %NULL
1827 * Sets the tooltip of the status icon.
1832 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
1833 const gchar *tooltip_text)
1835 GtkStatusIconPrivate *priv;
1837 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1839 priv = status_icon->priv;
1841 #ifdef GDK_WINDOWING_X11
1843 gtk_widget_set_tooltip_text (priv->tray_icon, tooltip_text);
1846 #ifdef GDK_WINDOWING_WIN32
1847 if (tooltip_text == NULL)
1848 priv->nid.uFlags &= ~NIF_TIP;
1851 WCHAR *wcs = g_utf8_to_utf16 (tooltip_text, -1, NULL, NULL, NULL);
1853 priv->nid.uFlags |= NIF_TIP;
1854 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
1855 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
1858 if (priv->nid.hWnd != NULL && priv->visible)
1859 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1860 g_warning ("%s:%d:Shell_NotifyIconW(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1862 #ifdef GDK_WINDOWING_QUARTZ
1864 [priv->status_item setToolTip:tooltip_text];
1865 QUARTZ_POOL_RELEASE;
1870 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
1872 GtkStatusIconPrivate *priv = status_icon->priv;
1874 priv->blink_off = !priv->blink_off;
1876 gtk_status_icon_update_image (status_icon);
1882 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
1884 GtkStatusIconPrivate *priv = status_icon->priv;
1886 if (!priv->blinking_timeout)
1888 gtk_status_icon_blinker (status_icon);
1890 priv->blinking_timeout =
1891 gdk_threads_add_timeout (BLINK_TIMEOUT,
1892 (GSourceFunc) gtk_status_icon_blinker,
1898 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
1900 GtkStatusIconPrivate *priv = status_icon->priv;
1902 if (priv->blinking_timeout)
1904 g_source_remove (priv->blinking_timeout);
1905 priv->blinking_timeout = 0;
1906 priv->blink_off = FALSE;
1908 gtk_status_icon_update_image (status_icon);
1913 * gtk_status_icon_set_visible:
1914 * @status_icon: a #GtkStatusIcon
1915 * @visible: %TRUE to show the status icon, %FALSE to hide it
1917 * Shows or hides a status icon.
1922 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
1925 GtkStatusIconPrivate *priv;
1927 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1929 priv = status_icon->priv;
1931 visible = visible != FALSE;
1933 if (priv->visible != visible)
1935 priv->visible = visible;
1937 #ifdef GDK_WINDOWING_X11
1939 gtk_widget_show (priv->tray_icon);
1940 else if (GTK_WIDGET_REALIZED (priv->tray_icon))
1942 gtk_widget_hide (priv->tray_icon);
1943 gtk_widget_unrealize (priv->tray_icon);
1946 #ifdef GDK_WINDOWING_WIN32
1947 if (priv->nid.hWnd != NULL)
1950 Shell_NotifyIconW (NIM_ADD, &priv->nid);
1952 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1955 #ifdef GDK_WINDOWING_QUARTZ
1957 [priv->status_item setVisible:visible];
1958 QUARTZ_POOL_RELEASE;
1960 g_object_notify (G_OBJECT (status_icon), "visible");
1965 * gtk_status_icon_get_visible:
1966 * @status_icon: a #GtkStatusIcon
1968 * Returns whether the status icon is visible or not.
1969 * Note that being visible does not guarantee that
1970 * the user can actually see the icon, see also
1971 * gtk_status_icon_is_embedded().
1973 * Return value: %TRUE if the status icon is visible
1978 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
1980 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1982 return status_icon->priv->visible;
1986 * gtk_status_icon_set_blinking:
1987 * @status_icon: a #GtkStatusIcon
1988 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
1990 * Makes the status icon start or stop blinking.
1991 * Note that blinking user interface elements may be problematic
1992 * for some users, and thus may be turned off, in which case
1993 * this setting has no effect.
1998 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
2001 GtkStatusIconPrivate *priv;
2003 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
2005 priv = status_icon->priv;
2007 blinking = blinking != FALSE;
2009 if (priv->blinking != blinking)
2011 priv->blinking = blinking;
2014 gtk_status_icon_enable_blinking (status_icon);
2016 gtk_status_icon_disable_blinking (status_icon);
2018 g_object_notify (G_OBJECT (status_icon), "blinking");
2023 * gtk_status_icon_get_blinking:
2024 * @status_icon: a #GtkStatusIcon
2026 * Returns whether the icon is blinking, see
2027 * gtk_status_icon_set_blinking().
2029 * Return value: %TRUE if the icon is blinking
2034 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
2036 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2038 return status_icon->priv->blinking;
2042 * gtk_status_icon_is_embedded:
2043 * @status_icon: a #GtkStatusIcon
2045 * Returns whether the status icon is embedded in a notification
2048 * Return value: %TRUE if the status icon is embedded in
2049 * a notification area.
2054 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
2056 #ifdef GDK_WINDOWING_X11
2060 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2062 #ifdef GDK_WINDOWING_X11
2063 plug = GTK_PLUG (status_icon->priv->tray_icon);
2065 if (plug->socket_window)
2070 #ifdef GDK_WINDOWING_WIN32
2073 #ifdef GDK_WINDOWING_QUARTZ
2079 * gtk_status_icon_position_menu:
2080 * @menu: the #GtkMenu
2081 * @x: return location for the x position
2082 * @y: return location for the y position
2083 * @push_in: whether the first menu item should be offset (pushed in) to be
2084 * aligned with the menu popup position (only useful for GtkOptionMenu).
2085 * @user_data: the status icon to position the menu on
2087 * Menu positioning function to use with gtk_menu_popup()
2088 * to position @menu aligned to the status icon @user_data.
2093 gtk_status_icon_position_menu (GtkMenu *menu,
2099 #ifdef GDK_WINDOWING_X11
2100 GtkStatusIcon *status_icon;
2101 GtkStatusIconPrivate *priv;
2102 GtkTrayIcon *tray_icon;
2105 GtkTextDirection direction;
2106 GtkRequisition menu_req;
2107 GdkRectangle monitor;
2108 gint monitor_num, height, width, xoffset, yoffset;
2110 g_return_if_fail (GTK_IS_MENU (menu));
2111 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2113 status_icon = GTK_STATUS_ICON (user_data);
2114 priv = status_icon->priv;
2115 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
2116 widget = priv->tray_icon;
2118 direction = gtk_widget_get_direction (widget);
2120 screen = gtk_widget_get_screen (widget);
2121 gtk_menu_set_screen (menu, screen);
2123 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
2124 if (monitor_num < 0)
2126 gtk_menu_set_monitor (menu, monitor_num);
2128 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2130 gdk_window_get_origin (widget->window, x, y);
2132 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2134 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
2137 height = widget->allocation.height;
2138 xoffset = widget->allocation.width;
2143 width = widget->allocation.width;
2146 yoffset = widget->allocation.height;
2149 if (direction == GTK_TEXT_DIR_RTL)
2151 if ((*x - (menu_req.width - width)) >= monitor.x)
2152 *x -= menu_req.width - width;
2153 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2155 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
2156 *x -= menu_req.width - width;
2162 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
2164 else if ((*x - (menu_req.width - width)) >= monitor.x)
2165 *x -= menu_req.width - width;
2166 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
2169 *x -= menu_req.width - width;
2172 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
2174 else if ((*y - (menu_req.height - height)) >= monitor.y)
2175 *y -= menu_req.height - height;
2176 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
2179 *y -= menu_req.height - height;
2182 #endif /* GDK_WINDOWING_X11 */
2184 #ifdef GDK_WINDOWING_WIN32
2185 GtkStatusIcon *status_icon;
2186 GtkStatusIconPrivate *priv;
2188 g_return_if_fail (GTK_IS_MENU (menu));
2189 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
2191 status_icon = GTK_STATUS_ICON (user_data);
2192 priv = status_icon->priv;
2194 *x = priv->last_click_x;
2195 *y = priv->last_click_y;
2201 * gtk_status_icon_get_geometry:
2202 * @status_icon: a #GtkStatusIcon
2203 * @screen: return location for the screen, or %NULL if the
2204 * information is not needed
2205 * @area: return location for the area occupied by the status
2207 * @orientation: return location for the orientation of the panel
2208 * in which the status icon is embedded, or %NULL. A panel
2209 * at the top or bottom of the screen is horizontal, a panel
2210 * at the left or right is vertical.
2212 * Obtains information about the location of the status icon
2213 * on screen. This information can be used to e.g. position
2214 * popups like notification bubbles.
2216 * See gtk_status_icon_position_menu() for a more convenient
2217 * alternative for positioning menus.
2219 * Note that some platforms do not allow GTK+ to provide
2220 * this information, and even on platforms that do allow it,
2221 * the information is not reliable unless the status icon
2222 * is embedded in a notification area, see
2223 * gtk_status_icon_is_embedded().
2225 * Return value: %TRUE if the location information has
2231 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2234 GtkOrientation *orientation)
2236 #ifdef GDK_WINDOWING_X11
2238 GtkStatusIconPrivate *priv;
2241 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2243 priv = status_icon->priv;
2244 widget = priv->tray_icon;
2247 *screen = gtk_widget_get_screen (widget);
2251 gdk_window_get_origin (widget->window, &x, &y);
2254 area->width = widget->allocation.width;
2255 area->height = widget->allocation.height;
2259 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2264 #endif /* GDK_WINDOWING_X11 */
2268 * gtk_status_icon_get_x11_window_id:
2269 * @status_icon: a #GtkStatusIcon
2271 * This function is only useful on the X11/freedesktop.org platform.
2272 * It returns a window ID for the widget in the underlying
2273 * status icon implementation. This is useful for the Galago
2274 * notification service, which can send a window ID in the protocol
2275 * in order for the server to position notification windows
2276 * pointing to a status icon reliably.
2278 * This function is not intended for other use cases which are
2279 * more likely to be met by one of the non-X11 specific methods, such
2280 * as gtk_status_icon_position_menu().
2282 * Return value: An 32 bit unsigned integer identifier for the
2283 * underlying X11 Window
2288 gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
2290 #ifdef GDK_WINDOWING_X11
2291 gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
2292 return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
2298 #define __GTK_STATUS_ICON_C__
2299 #include "gtkaliasdef.c"