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_WIN32
45 #include "gtkicontheme.h"
48 #include "win32/gdkwin32.h"
49 #define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
52 #ifdef GDK_WINDOWING_QUARTZ
53 #include "gtkicontheme.h"
57 #include "gdkkeysyms.h"
61 #define BLINK_TIMEOUT 500
87 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
89 #ifdef GDK_WINDOWING_QUARTZ
90 #include "gtkstatusicon-quartz.c"
93 struct _GtkStatusIconPrivate
95 #ifdef GDK_WINDOWING_X11
100 #ifdef GDK_WINDOWING_WIN32
101 GtkWidget *dummy_widget;
103 gint last_click_x, last_click_y;
104 GtkOrientation orientation;
107 #ifdef GDK_WINDOWING_QUARTZ
108 GtkWidget *dummy_widget;
109 GtkQuartzStatusIcon *status_item;
117 GtkImageType storage_type;
126 GdkPixbuf *blank_icon;
127 guint blinking_timeout;
134 static GObject* gtk_status_icon_constructor (GType type,
135 guint n_construct_properties,
136 GObjectConstructParam *construct_params);
137 static void gtk_status_icon_finalize (GObject *object);
138 static void gtk_status_icon_set_property (GObject *object,
142 static void gtk_status_icon_get_property (GObject *object,
147 #ifdef GDK_WINDOWING_X11
148 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
149 GtkAllocation *allocation);
150 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
151 GdkScreen *old_screen);
152 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
153 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
156 static gboolean gtk_status_icon_key_press (GtkStatusIcon *status_icon,
158 static void gtk_status_icon_popup_menu (GtkStatusIcon *status_icon);
159 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
160 GdkEventButton *event);
161 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
162 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
165 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
168 gtk_status_icon_class_init (GtkStatusIconClass *class)
170 GObjectClass *gobject_class = (GObjectClass *) class;
172 gobject_class->constructor = gtk_status_icon_constructor;
173 gobject_class->finalize = gtk_status_icon_finalize;
174 gobject_class->set_property = gtk_status_icon_set_property;
175 gobject_class->get_property = gtk_status_icon_get_property;
177 g_object_class_install_property (gobject_class,
179 g_param_spec_object ("pixbuf",
181 P_("A GdkPixbuf to display"),
183 GTK_PARAM_READWRITE));
185 g_object_class_install_property (gobject_class,
187 g_param_spec_string ("file",
189 P_("Filename to load and display"),
191 GTK_PARAM_WRITABLE));
193 g_object_class_install_property (gobject_class,
195 g_param_spec_string ("stock",
197 P_("Stock ID for a stock image to display"),
199 GTK_PARAM_READWRITE));
201 g_object_class_install_property (gobject_class,
203 g_param_spec_string ("icon-name",
205 P_("The name of the icon from the icon theme"),
207 GTK_PARAM_READWRITE));
209 g_object_class_install_property (gobject_class,
211 g_param_spec_enum ("storage-type",
213 P_("The representation being used for image data"),
216 GTK_PARAM_READABLE));
218 g_object_class_install_property (gobject_class,
220 g_param_spec_int ("size",
222 P_("The size of the icon"),
226 GTK_PARAM_READABLE));
228 g_object_class_install_property (gobject_class,
230 g_param_spec_object ("screen",
232 P_("The screen where this status icon will be displayed"),
234 GTK_PARAM_READWRITE));
236 g_object_class_install_property (gobject_class,
238 g_param_spec_boolean ("blinking",
240 P_("Whether or not the status icon is blinking"),
242 GTK_PARAM_READWRITE));
244 g_object_class_install_property (gobject_class,
246 g_param_spec_boolean ("visible",
248 P_("Whether or not the status icon is visible"),
250 GTK_PARAM_READWRITE));
254 * GtkStatusIcon:embedded:
256 * %TRUE if the statusicon is embedded in a notification area.
260 g_object_class_install_property (gobject_class,
262 g_param_spec_boolean ("embedded",
264 P_("Whether or not the status icon is embedded"),
266 GTK_PARAM_READABLE));
269 * GtkStatusIcon:orientation:
271 * The orientation of the tray in which the statusicon
276 g_object_class_install_property (gobject_class,
278 g_param_spec_enum ("orientation",
280 P_("The orientation of the tray"),
281 GTK_TYPE_ORIENTATION,
282 GTK_ORIENTATION_HORIZONTAL,
283 GTK_PARAM_READABLE));
287 * GtkStatusIcon::activate:
288 * @status_icon: the object which received the signal
290 * Gets emitted when the user activates the status icon.
291 * If and how status icons can activated is platform-dependent.
295 status_icon_signals [ACTIVATE_SIGNAL] =
296 g_signal_new (I_("activate"),
297 G_TYPE_FROM_CLASS (gobject_class),
298 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
299 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
302 g_cclosure_marshal_VOID__VOID,
307 * GtkStatusIcon::popup-menu:
308 * @status_icon: the object which received the signal
309 * @button: the button that was pressed, or 0 if the
310 * signal is not emitted in response to a button press event
311 * @activate_time: the timestamp of the event that
312 * triggered the signal emission
314 * Gets emitted when the user brings up the context menu
315 * of the status icon. Whether status icons can have context
316 * menus and how these are activated is platform-dependent.
318 * The @button and @activate_timeout parameters should be
319 * passed as the last to arguments to gtk_menu_popup().
323 status_icon_signals [POPUP_MENU_SIGNAL] =
324 g_signal_new (I_("popup_menu"),
325 G_TYPE_FROM_CLASS (gobject_class),
326 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
327 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
330 _gtk_marshal_VOID__UINT_UINT,
337 * GtkStatusIcon::size-changed:
338 * @status_icon: the object which received the signal
339 * @size: the new size
341 * Gets emitted when the size available for the image
342 * changes, e.g. because the notification area got resized.
344 * Return value: %TRUE if the icon was updated for the new
345 * size. Otherwise, GTK+ will scale the icon as necessary.
349 status_icon_signals [SIZE_CHANGED_SIGNAL] =
350 g_signal_new (I_("size_changed"),
351 G_TYPE_FROM_CLASS (gobject_class),
353 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
354 g_signal_accumulator_true_handled,
356 _gtk_marshal_BOOLEAN__INT,
361 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
364 #ifdef GDK_WINDOWING_WIN32
367 build_button_event (GtkStatusIconPrivate *priv,
372 GdkRectangle monitor0;
374 /* We know that gdk/win32 puts the primary monitor at index 0 */
375 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
376 e->window = g_object_ref (gdk_get_default_root_window ());
377 e->send_event = TRUE;
378 e->time = GetTickCount ();
380 priv->last_click_x = e->x = pos.x + monitor0.x;
381 priv->last_click_y = e->y = pos.y + monitor0.y;
385 e->device = gdk_display_get_default ()->core_pointer;
392 GtkStatusIcon *status_icon;
393 GdkEventButton *event;
394 } ButtonCallbackData;
397 button_callback (gpointer data)
399 ButtonCallbackData *bc = (ButtonCallbackData *) data;
401 gtk_status_icon_button_press (bc->status_icon, bc->event);
403 gdk_event_free ((GdkEvent *) bc->event);
409 static LRESULT CALLBACK
415 if (message == WM_GTK_TRAY_NOTIFICATION)
417 ButtonCallbackData *bc;
423 bc = g_new (ButtonCallbackData, 1);
424 bc->event = (GdkEventButton *) gdk_event_new (GDK_BUTTON_PRESS);
425 bc->status_icon = GTK_STATUS_ICON (wparam);
426 build_button_event (bc->status_icon->priv, bc->event, (lparam == WM_LBUTTONDOWN) ? 1 : 3);
427 g_idle_add (button_callback, bc);
436 return DefWindowProc (hwnd, message, wparam, lparam);
441 create_tray_observer (void)
444 static HWND hwnd = NULL;
446 HINSTANCE hmodule = GetModuleHandle (NULL);
451 memset (&wclass, 0, sizeof(WNDCLASS));
452 wclass.lpszClassName = "gtkstatusicon-observer";
453 wclass.lpfnWndProc = wndproc;
454 wclass.hInstance = hmodule;
456 klass = RegisterClass (&wclass);
460 hwnd = CreateWindow (MAKEINTRESOURCE(klass),
462 0, 0, 1, 1, NULL, NULL,
466 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
476 gtk_status_icon_init (GtkStatusIcon *status_icon)
478 GtkStatusIconPrivate *priv;
480 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
481 GtkStatusIconPrivate);
482 status_icon->priv = priv;
484 priv->storage_type = GTK_IMAGE_EMPTY;
485 priv->visible = TRUE;
487 #ifdef GDK_WINDOWING_X11
489 priv->image_width = 0;
490 priv->image_height = 0;
492 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
494 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
495 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
497 g_signal_connect_swapped (priv->tray_icon, "key-press-event",
498 G_CALLBACK (gtk_status_icon_key_press), status_icon);
499 g_signal_connect_swapped (priv->tray_icon, "popup-menu",
500 G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
501 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
502 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
503 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
504 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
505 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
506 G_CALLBACK (gtk_status_icon_button_press), status_icon);
507 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
508 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
509 priv->image = gtk_image_new ();
510 GTK_WIDGET_SET_FLAGS (priv->image, GTK_CAN_FOCUS);
511 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
512 gtk_widget_show (priv->image);
514 g_signal_connect_swapped (priv->image, "size-allocate",
515 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
519 #ifdef GDK_WINDOWING_WIN32
521 /* Get position and orientation of Windows taskbar. */
525 abd.cbSize = sizeof (abd);
526 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
527 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
528 priv->orientation = GTK_ORIENTATION_VERTICAL;
530 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
533 priv->last_click_x = priv->last_click_y = 0;
535 /* Are the system tray icons always 16 pixels square? */
537 priv->image_width = 16;
538 priv->image_height = 16;
540 priv->dummy_widget = gtk_label_new ("");
542 memset (&priv->nid, 0, sizeof (priv->nid));
544 priv->nid.hWnd = create_tray_observer ();
545 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
546 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
547 priv->nid.uFlags = NIF_MESSAGE;
549 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
551 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
552 priv->nid.hWnd = NULL;
556 #ifdef GDK_WINDOWING_QUARTZ
557 priv->dummy_widget = gtk_label_new ("");
561 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
563 priv->image_width = priv->image_height = [priv->status_item getHeight];
564 priv->size = priv->image_height;
572 gtk_status_icon_constructor (GType type,
573 guint n_construct_properties,
574 GObjectConstructParam *construct_params)
577 GtkStatusIcon *status_icon;
578 GtkStatusIconPrivate *priv;
580 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
581 n_construct_properties,
584 #ifdef GDK_WINDOWING_X11
585 status_icon = GTK_STATUS_ICON (object);
586 priv = status_icon->priv;
589 gtk_widget_show (priv->tray_icon);
596 gtk_status_icon_finalize (GObject *object)
598 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
599 GtkStatusIconPrivate *priv = status_icon->priv;
601 gtk_status_icon_disable_blinking (status_icon);
603 gtk_status_icon_reset_image_data (status_icon);
605 if (priv->blank_icon)
606 g_object_unref (priv->blank_icon);
607 priv->blank_icon = NULL;
609 #ifdef GDK_WINDOWING_X11
610 gtk_widget_destroy (priv->tray_icon);
613 #ifdef GDK_WINDOWING_WIN32
614 if (priv->nid.hWnd != NULL && priv->visible)
615 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
617 DestroyIcon (priv->nid.hIcon);
619 gtk_widget_destroy (priv->dummy_widget);
622 #ifdef GDK_WINDOWING_QUARTZ
624 [priv->status_item release];
628 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
632 gtk_status_icon_set_property (GObject *object,
637 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
642 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
645 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
648 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
651 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
654 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
657 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
660 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
663 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
669 gtk_status_icon_get_property (GObject *object,
674 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
675 GtkStatusIconPrivate *priv = status_icon->priv;
677 /* The "getter" functions whine if you try to get the wrong
678 * storage type. This function is instead robust against that,
679 * so that GUI builders don't have to jump through hoops
686 if (priv->storage_type != GTK_IMAGE_PIXBUF)
687 g_value_set_object (value, NULL);
689 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
692 if (priv->storage_type != GTK_IMAGE_STOCK)
693 g_value_set_string (value, NULL);
695 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
698 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
699 g_value_set_string (value, NULL);
701 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
703 case PROP_STORAGE_TYPE:
704 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
707 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
710 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
713 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
716 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
719 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
721 case PROP_ORIENTATION:
722 #ifdef GDK_WINDOWING_X11
723 g_value_set_enum (value, _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (status_icon->priv->tray_icon)));
725 #ifdef GDK_WINDOWING_WIN32
726 g_value_set_enum (value, status_icon->priv->orientation);
730 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
736 * gtk_status_icon_new:
738 * Creates an empty status icon object.
740 * Return value: a new #GtkStatusIcon
745 gtk_status_icon_new (void)
747 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
751 * gtk_status_icon_new_from_pixbuf:
752 * @pixbuf: a #GdkPixbuf
754 * Creates a status icon displaying @pixbuf.
756 * The image will be scaled down to fit in the available
757 * space in the notification area, if necessary.
759 * Return value: a new #GtkStatusIcon
764 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
766 return g_object_new (GTK_TYPE_STATUS_ICON,
772 * gtk_status_icon_new_from_file:
773 * @filename: a filename
775 * Creates a status icon displaying the file @filename.
777 * The image will be scaled down to fit in the available
778 * space in the notification area, if necessary.
780 * Return value: a new #GtkStatusIcon
785 gtk_status_icon_new_from_file (const gchar *filename)
787 return g_object_new (GTK_TYPE_STATUS_ICON,
793 * gtk_status_icon_new_from_stock:
794 * @stock_id: a stock icon id
796 * Creates a status icon displaying a stock icon. Sample stock icon
797 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
798 * own stock icon names, see gtk_icon_factory_add_default() and
799 * gtk_icon_factory_add().
801 * Return value: a new #GtkStatusIcon
806 gtk_status_icon_new_from_stock (const gchar *stock_id)
808 return g_object_new (GTK_TYPE_STATUS_ICON,
814 * gtk_status_icon_new_from_icon_name:
815 * @icon_name: an icon name
817 * Creates a status icon displaying an icon from the current icon theme.
818 * If the current icon theme is changed, the icon will be updated
821 * Return value: a new #GtkStatusIcon
826 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
828 return g_object_new (GTK_TYPE_STATUS_ICON,
829 "icon-name", icon_name,
834 emit_activate_signal (GtkStatusIcon *status_icon)
836 g_signal_emit (status_icon,
837 status_icon_signals [ACTIVATE_SIGNAL], 0);
841 emit_popup_menu_signal (GtkStatusIcon *status_icon,
843 guint32 activate_time)
845 g_signal_emit (status_icon,
846 status_icon_signals [POPUP_MENU_SIGNAL], 0,
851 #ifdef GDK_WINDOWING_X11
854 emit_size_changed_signal (GtkStatusIcon *status_icon,
857 gboolean handled = FALSE;
859 g_signal_emit (status_icon,
860 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
870 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
872 GtkStatusIconPrivate *priv = status_icon->priv;
874 if (priv->blank_icon)
878 width = gdk_pixbuf_get_width (priv->blank_icon);
879 height = gdk_pixbuf_get_height (priv->blank_icon);
882 if (width == priv->image_width && height == priv->image_height)
883 return priv->blank_icon;
886 g_object_unref (priv->blank_icon);
887 priv->blank_icon = NULL;
891 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
894 if (priv->blank_icon)
895 gdk_pixbuf_fill (priv->blank_icon, 0);
897 return priv->blank_icon;
900 #ifdef GDK_WINDOWING_X11
903 find_icon_size (GtkWidget *widget,
907 GtkSettings *settings;
911 screen = gtk_widget_get_screen (widget);
914 return GTK_ICON_SIZE_MENU;
916 settings = gtk_settings_get_for_screen (screen);
919 size = GTK_ICON_SIZE_MENU;
921 for (s = GTK_ICON_SIZE_MENU; s < GTK_ICON_SIZE_DIALOG; s++)
923 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
924 w <= pixel_size && h <= pixel_size)
926 d = MAX (pixel_size - w, pixel_size - h);
941 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
943 GtkStatusIconPrivate *priv = status_icon->priv;
944 #ifdef GDK_WINDOWING_WIN32
950 #ifdef GDK_WINDOWING_X11
951 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
952 gtk_status_icon_blank_icon (status_icon));
954 #ifdef GDK_WINDOWING_WIN32
955 prev_hicon = priv->nid.hIcon;
956 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
957 priv->nid.uFlags |= NIF_ICON;
958 if (priv->nid.hWnd != NULL && priv->visible)
959 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
960 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
962 DestroyIcon (prev_hicon);
964 #ifdef GDK_WINDOWING_QUARTZ
966 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
972 switch (priv->storage_type)
974 case GTK_IMAGE_PIXBUF:
978 pixbuf = priv->image_data.pixbuf;
989 width = gdk_pixbuf_get_width (pixbuf);
990 height = gdk_pixbuf_get_height (pixbuf);
992 if (width > size || height > size)
993 scaled = gdk_pixbuf_scale_simple (pixbuf,
996 GDK_INTERP_BILINEAR);
998 scaled = g_object_ref (pixbuf);
1000 #ifdef GDK_WINDOWING_X11
1001 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
1003 #ifdef GDK_WINDOWING_WIN32
1004 prev_hicon = priv->nid.hIcon;
1005 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
1006 priv->nid.uFlags |= NIF_ICON;
1007 if (priv->nid.hWnd != NULL && priv->visible)
1008 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1009 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1011 DestroyIcon (prev_hicon);
1013 #ifdef GDK_WINDOWING_QUARTZ
1015 [priv->status_item setImage:scaled];
1016 QUARTZ_POOL_RELEASE;
1019 g_object_unref (scaled);
1023 #ifdef GDK_WINDOWING_X11
1024 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1026 #ifdef GDK_WINDOWING_WIN32
1027 priv->nid.uFlags &= ~NIF_ICON;
1028 if (priv->nid.hWnd != NULL && priv->visible)
1029 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1030 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1032 #ifdef GDK_WINDOWING_QUARTZ
1033 [priv->status_item setImage:NULL];
1039 case GTK_IMAGE_STOCK:
1041 #ifdef GDK_WINDOWING_X11
1042 GtkIconSize size = find_icon_size (priv->image, priv->size);
1043 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1044 priv->image_data.stock_id,
1047 #ifdef GDK_WINDOWING_WIN32
1050 gtk_widget_render_icon (priv->dummy_widget,
1051 priv->image_data.stock_id,
1052 GTK_ICON_SIZE_SMALL_TOOLBAR,
1055 prev_hicon = priv->nid.hIcon;
1056 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1057 priv->nid.uFlags |= NIF_ICON;
1058 if (priv->nid.hWnd != NULL && priv->visible)
1059 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1060 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1062 DestroyIcon (prev_hicon);
1063 g_object_unref (pixbuf);
1066 #ifdef GDK_WINDOWING_QUARTZ
1070 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1071 priv->image_data.stock_id,
1072 GTK_ICON_SIZE_SMALL_TOOLBAR,
1075 [priv->status_item setImage:pixbuf];
1076 QUARTZ_POOL_RELEASE;
1077 g_object_unref (pixbuf);
1083 case GTK_IMAGE_ICON_NAME:
1085 #ifdef GDK_WINDOWING_X11
1086 GtkIconSize size = find_icon_size (priv->image, priv->size);
1087 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1088 priv->image_data.icon_name,
1091 #ifdef GDK_WINDOWING_WIN32
1094 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1095 priv->image_data.icon_name,
1099 prev_hicon = priv->nid.hIcon;
1100 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1101 priv->nid.uFlags |= NIF_ICON;
1102 if (priv->nid.hWnd != NULL && priv->visible)
1103 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1104 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1106 DestroyIcon (prev_hicon);
1107 g_object_unref (pixbuf);
1110 #ifdef GDK_WINDOWING_QUARTZ
1114 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1115 priv->image_data.icon_name,
1120 [priv->status_item setImage:pixbuf];
1121 QUARTZ_POOL_RELEASE;
1122 g_object_unref (pixbuf);
1129 case GTK_IMAGE_EMPTY:
1130 #ifdef GDK_WINDOWING_X11
1131 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1133 #ifdef GDK_WINDOWING_WIN32
1134 priv->nid.uFlags &= ~NIF_ICON;
1135 if (priv->nid.hWnd != NULL && priv->visible)
1136 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1137 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1139 #ifdef GDK_WINDOWING_QUARTZ
1142 [priv->status_item setImage:NULL];
1143 QUARTZ_POOL_RELEASE;
1148 g_assert_not_reached ();
1153 #ifdef GDK_WINDOWING_X11
1156 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1157 GtkAllocation *allocation)
1159 GtkStatusIconPrivate *priv = status_icon->priv;
1160 GtkOrientation orientation;
1163 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1165 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1166 size = allocation->height;
1168 size = allocation->width;
1170 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1171 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1173 if (priv->size != size)
1177 g_object_notify (G_OBJECT (status_icon), "size");
1179 if (!emit_size_changed_signal (status_icon, size))
1180 gtk_status_icon_update_image (status_icon);
1185 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1186 GdkScreen *old_screen)
1188 GtkStatusIconPrivate *priv = status_icon->priv;
1190 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1192 g_object_notify (G_OBJECT (status_icon), "screen");
1198 #ifdef GDK_WINDOWING_X11
1201 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1203 g_object_notify (G_OBJECT (status_icon), "embedded");
1207 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1209 g_object_notify (G_OBJECT (status_icon), "orientation");
1215 gtk_status_icon_key_press (GtkStatusIcon *status_icon,
1218 guint state, keyval;
1220 state = event->state & gtk_accelerator_get_default_mod_mask ();
1221 keyval = event->keyval;
1223 (keyval == GDK_Return ||
1224 keyval == GDK_KP_Enter ||
1225 keyval == GDK_ISO_Enter ||
1226 keyval == GDK_space ||
1227 keyval == GDK_KP_Space))
1229 emit_activate_signal (status_icon);
1237 gtk_status_icon_popup_menu (GtkStatusIcon *status_icon)
1239 emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
1243 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1244 GdkEventButton *event)
1246 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1248 emit_activate_signal (status_icon);
1251 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1253 emit_popup_menu_signal (status_icon, event->button, event->time);
1261 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1263 GtkStatusIconPrivate *priv = status_icon->priv;
1265 switch (priv->storage_type)
1267 case GTK_IMAGE_PIXBUF:
1268 if (priv->image_data.pixbuf)
1269 g_object_unref (priv->image_data.pixbuf);
1270 priv->image_data.pixbuf = NULL;
1271 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1274 case GTK_IMAGE_STOCK:
1275 g_free (priv->image_data.stock_id);
1276 priv->image_data.stock_id = NULL;
1278 g_object_notify (G_OBJECT (status_icon), "stock");
1281 case GTK_IMAGE_ICON_NAME:
1282 g_free (priv->image_data.icon_name);
1283 priv->image_data.icon_name = NULL;
1285 g_object_notify (G_OBJECT (status_icon), "icon-name");
1288 case GTK_IMAGE_EMPTY:
1291 g_assert_not_reached ();
1295 priv->storage_type = GTK_IMAGE_EMPTY;
1296 g_object_notify (G_OBJECT (status_icon), "storage-type");
1300 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1301 GtkImageType storage_type,
1304 GtkStatusIconPrivate *priv = status_icon->priv;
1306 g_object_freeze_notify (G_OBJECT (status_icon));
1308 gtk_status_icon_reset_image_data (status_icon);
1310 priv->storage_type = storage_type;
1311 g_object_notify (G_OBJECT (status_icon), "storage-type");
1313 switch (storage_type)
1315 case GTK_IMAGE_PIXBUF:
1316 priv->image_data.pixbuf = (GdkPixbuf *)data;
1317 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1319 case GTK_IMAGE_STOCK:
1320 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1321 g_object_notify (G_OBJECT (status_icon), "stock");
1323 case GTK_IMAGE_ICON_NAME:
1324 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1325 g_object_notify (G_OBJECT (status_icon), "icon-name");
1328 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1331 g_object_thaw_notify (G_OBJECT (status_icon));
1333 gtk_status_icon_update_image (status_icon);
1337 * gtk_status_icon_set_from_pixbuf:
1338 * @status_icon: a #GtkStatusIcon
1339 * @pixbuf: a #GdkPixbuf or %NULL
1341 * Makes @status_icon display @pixbuf.
1342 * See gtk_status_icon_new_from_pixbuf() for details.
1347 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1350 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1351 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1354 g_object_ref (pixbuf);
1356 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1361 * gtk_status_icon_set_from_file:
1362 * @status_icon: a #GtkStatusIcon
1363 * @filename: a filename
1365 * Makes @status_icon display the file @filename.
1366 * See gtk_status_icon_new_from_file() for details.
1371 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1372 const gchar *filename)
1376 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1377 g_return_if_fail (filename != NULL);
1379 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1381 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1384 g_object_unref (pixbuf);
1388 * gtk_status_icon_set_from_stock:
1389 * @status_icon: a #GtkStatusIcon
1390 * @stock_id: a stock icon id
1392 * Makes @status_icon display the stock icon with the id @stock_id.
1393 * See gtk_status_icon_new_from_stock() for details.
1398 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1399 const gchar *stock_id)
1401 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1402 g_return_if_fail (stock_id != NULL);
1404 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1405 (gpointer) stock_id);
1409 * gtk_status_icon_set_from_icon_name:
1410 * @status_icon: a #GtkStatusIcon
1411 * @icon_name: an icon name
1413 * Makes @status_icon display the icon named @icon_name from the
1414 * current icon theme.
1415 * See gtk_status_icon_new_from_icon_name() for details.
1420 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1421 const gchar *icon_name)
1423 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1424 g_return_if_fail (icon_name != NULL);
1426 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1427 (gpointer) icon_name);
1431 * gtk_status_icon_get_storage_type:
1432 * @status_icon: a #GtkStatusIcon
1434 * Gets the type of representation being used by the #GtkStatusIcon
1435 * to store image data. If the #GtkStatusIcon has no image data,
1436 * the return value will be %GTK_IMAGE_EMPTY.
1438 * Return value: the image representation being used
1443 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1445 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1447 return status_icon->priv->storage_type;
1450 * gtk_status_icon_get_pixbuf:
1451 * @status_icon: a #GtkStatusIcon
1453 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1454 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1455 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1456 * The caller of this function does not own a reference to the
1459 * Return value: the displayed pixbuf, or %NULL if the image is empty.
1464 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1466 GtkStatusIconPrivate *priv;
1468 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1470 priv = status_icon->priv;
1472 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
1473 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1475 if (priv->storage_type == GTK_IMAGE_EMPTY)
1476 priv->image_data.pixbuf = NULL;
1478 return priv->image_data.pixbuf;
1482 * gtk_status_icon_get_stock:
1483 * @status_icon: a #GtkStatusIcon
1485 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1486 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1487 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1488 * The returned string is owned by the #GtkStatusIcon and should not
1489 * be freed or modified.
1491 * Return value: stock id of the displayed stock icon,
1492 * or %NULL if the image is empty.
1496 G_CONST_RETURN gchar *
1497 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
1499 GtkStatusIconPrivate *priv;
1501 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1503 priv = status_icon->priv;
1505 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
1506 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1508 if (priv->storage_type == GTK_IMAGE_EMPTY)
1509 priv->image_data.stock_id = NULL;
1511 return priv->image_data.stock_id;
1515 * gtk_status_icon_get_icon_name:
1516 * @status_icon: a #GtkStatusIcon
1518 * Gets the name of the icon being displayed by the #GtkStatusIcon.
1519 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1520 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
1521 * The returned string is owned by the #GtkStatusIcon and should not
1522 * be freed or modified.
1524 * Return value: name of the displayed icon, or %NULL if the image is empty.
1528 G_CONST_RETURN gchar *
1529 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
1531 GtkStatusIconPrivate *priv;
1533 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1535 priv = status_icon->priv;
1537 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
1538 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1540 if (priv->storage_type == GTK_IMAGE_EMPTY)
1541 priv->image_data.icon_name = NULL;
1543 return priv->image_data.icon_name;
1547 * gtk_status_icon_get_size:
1548 * @status_icon: a #GtkStatusIcon
1550 * Gets the size in pixels that is available for the image.
1551 * Stock icons and named icons adapt their size automatically
1552 * if the size of the notification area changes. For other
1553 * storage types, the size-changed signal can be used to
1554 * react to size changes.
1556 * Note that the returned size is only meaningful while the
1557 * status icon is embedded (see gtk_status_icon_is_embedded()).
1559 * Return value: the size that is available for the image
1564 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
1566 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
1568 return status_icon->priv->size;
1572 * gtk_status_icon_set_screen:
1573 * @status_icon: a #GtkStatusIcon
1574 * @screen: a #GdkScreen
1576 * Sets the #GdkScreen where @status_icon is displayed; if
1577 * the icon is already mapped, it will be unmapped, and
1578 * then remapped on the new screen.
1583 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
1586 g_return_if_fail (GDK_IS_SCREEN (screen));
1588 #ifdef GDK_WINDOWING_X11
1589 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
1594 * gtk_status_icon_get_screen:
1595 * @status_icon: a #GtkStatusIcon
1597 * Returns the #GdkScreen associated with @status_icon.
1599 * Return value: a #GdkScreen.
1604 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
1606 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1608 #ifdef GDK_WINDOWING_X11
1609 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
1611 return gdk_screen_get_default ();
1616 * gtk_status_icon_set_tooltip:
1617 * @status_icon: a #GtkStatusIcon
1618 * @tooltip_text: the tooltip text, or %NULL
1620 * Sets the tooltip of the status icon.
1625 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
1626 const gchar *tooltip_text)
1628 GtkStatusIconPrivate *priv;
1630 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1632 priv = status_icon->priv;
1634 #ifdef GDK_WINDOWING_X11
1636 gtk_widget_set_tooltip_text (priv->tray_icon, tooltip_text);
1639 #ifdef GDK_WINDOWING_WIN32
1640 if (tooltip_text == NULL)
1641 priv->nid.uFlags &= ~NIF_TIP;
1644 WCHAR *wcs = g_utf8_to_utf16 (tooltip_text, -1, NULL, NULL, NULL);
1646 priv->nid.uFlags |= NIF_TIP;
1647 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
1648 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
1651 if (priv->nid.hWnd != NULL && priv->visible)
1652 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1653 g_warning ("%s:%d:Shell_NotifyIconW(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1655 #ifdef GDK_WINDOWING_QUARTZ
1657 [priv->status_item setToolTip:tooltip_text];
1658 QUARTZ_POOL_RELEASE;
1663 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
1665 GtkStatusIconPrivate *priv = status_icon->priv;
1667 priv->blink_off = !priv->blink_off;
1669 gtk_status_icon_update_image (status_icon);
1675 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
1677 GtkStatusIconPrivate *priv = status_icon->priv;
1679 if (!priv->blinking_timeout)
1681 gtk_status_icon_blinker (status_icon);
1683 priv->blinking_timeout =
1684 gdk_threads_add_timeout (BLINK_TIMEOUT,
1685 (GSourceFunc) gtk_status_icon_blinker,
1691 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
1693 GtkStatusIconPrivate *priv = status_icon->priv;
1695 if (priv->blinking_timeout)
1697 g_source_remove (priv->blinking_timeout);
1698 priv->blinking_timeout = 0;
1699 priv->blink_off = FALSE;
1701 gtk_status_icon_update_image (status_icon);
1706 * gtk_status_icon_set_visible:
1707 * @status_icon: a #GtkStatusIcon
1708 * @visible: %TRUE to show the status icon, %FALSE to hide it
1710 * Shows or hides a status icon.
1715 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
1718 GtkStatusIconPrivate *priv;
1720 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1722 priv = status_icon->priv;
1724 visible = visible != FALSE;
1726 if (priv->visible != visible)
1728 priv->visible = visible;
1730 #ifdef GDK_WINDOWING_X11
1732 gtk_widget_show (priv->tray_icon);
1733 else if (GTK_WIDGET_REALIZED (priv->tray_icon))
1735 gtk_widget_hide (priv->tray_icon);
1736 gtk_widget_unrealize (priv->tray_icon);
1739 #ifdef GDK_WINDOWING_WIN32
1740 if (priv->nid.hWnd != NULL)
1743 Shell_NotifyIconW (NIM_ADD, &priv->nid);
1745 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1748 #ifdef GDK_WINDOWING_QUARTZ
1750 [priv->status_item setVisible:visible];
1751 QUARTZ_POOL_RELEASE;
1753 g_object_notify (G_OBJECT (status_icon), "visible");
1758 * gtk_status_icon_get_visible:
1759 * @status_icon: a #GtkStatusIcon
1761 * Returns whether the status icon is visible or not.
1762 * Note that being visible does not guarantee that
1763 * the user can actually see the icon, see also
1764 * gtk_status_icon_is_embedded().
1766 * Return value: %TRUE if the status icon is visible
1771 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
1773 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1775 return status_icon->priv->visible;
1779 * gtk_status_icon_set_blinking:
1780 * @status_icon: a #GtkStatusIcon
1781 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
1783 * Makes the status icon start or stop blinking.
1784 * Note that blinking user interface elements may be problematic
1785 * for some users, and thus may be turned off, in which case
1786 * this setting has no effect.
1791 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
1794 GtkStatusIconPrivate *priv;
1796 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1798 priv = status_icon->priv;
1800 blinking = blinking != FALSE;
1802 if (priv->blinking != blinking)
1804 priv->blinking = blinking;
1807 gtk_status_icon_enable_blinking (status_icon);
1809 gtk_status_icon_disable_blinking (status_icon);
1811 g_object_notify (G_OBJECT (status_icon), "blinking");
1816 * gtk_status_icon_get_blinking:
1817 * @status_icon: a #GtkStatusIcon
1819 * Returns whether the icon is blinking, see
1820 * gtk_status_icon_set_blinking().
1822 * Return value: %TRUE if the icon is blinking
1827 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
1829 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1831 return status_icon->priv->blinking;
1835 * gtk_status_icon_is_embedded:
1836 * @status_icon: a #GtkStatusIcon
1838 * Returns whether the status icon is embedded in a notification
1841 * Return value: %TRUE if the status icon is embedded in
1842 * a notification area.
1847 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
1849 #ifdef GDK_WINDOWING_X11
1853 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1855 #ifdef GDK_WINDOWING_X11
1856 plug = GTK_PLUG (status_icon->priv->tray_icon);
1858 if (plug->socket_window)
1863 #ifdef GDK_WINDOWING_WIN32
1866 #ifdef GDK_WINDOWING_QUARTZ
1872 * gtk_status_icon_position_menu:
1873 * @menu: the #GtkMenu
1874 * @x: return location for the x position
1875 * @y: return location for the y position
1876 * @push_in: whether the first menu item should be offset (pushed in) to be
1877 * aligned with the menu popup position (only useful for GtkOptionMenu).
1878 * @user_data: the status icon to position the menu on
1880 * Menu positioning function to use with gtk_menu_popup()
1881 * to position @menu aligned to the status icon @user_data.
1886 gtk_status_icon_position_menu (GtkMenu *menu,
1892 #ifdef GDK_WINDOWING_X11
1893 GtkStatusIcon *status_icon;
1894 GtkStatusIconPrivate *priv;
1895 GtkTrayIcon *tray_icon;
1898 GtkTextDirection direction;
1899 GtkRequisition menu_req;
1900 GdkRectangle monitor;
1901 gint monitor_num, height, width, xoffset, yoffset;
1903 g_return_if_fail (GTK_IS_MENU (menu));
1904 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
1906 status_icon = GTK_STATUS_ICON (user_data);
1907 priv = status_icon->priv;
1908 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
1909 widget = priv->tray_icon;
1911 direction = gtk_widget_get_direction (widget);
1913 screen = gtk_widget_get_screen (widget);
1914 gtk_menu_set_screen (menu, screen);
1916 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
1917 if (monitor_num < 0)
1919 gtk_menu_set_monitor (menu, monitor_num);
1921 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1923 gdk_window_get_origin (widget->window, x, y);
1925 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
1927 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
1930 height = widget->allocation.height;
1931 xoffset = widget->allocation.width;
1936 width = widget->allocation.width;
1939 yoffset = widget->allocation.height;
1942 if (direction == GTK_TEXT_DIR_RTL)
1944 if ((*x - (menu_req.width - width)) >= monitor.x)
1945 *x -= menu_req.width - width;
1946 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
1948 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
1949 *x -= menu_req.width - width;
1955 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
1957 else if ((*x - (menu_req.width - width)) >= monitor.x)
1958 *x -= menu_req.width - width;
1959 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
1962 *x -= menu_req.width - width;
1965 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
1967 else if ((*y - (menu_req.height - height)) >= monitor.y)
1968 *y -= menu_req.height - height;
1969 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
1972 *y -= menu_req.height - height;
1975 #endif /* GDK_WINDOWING_X11 */
1977 #ifdef GDK_WINDOWING_WIN32
1978 GtkStatusIcon *status_icon;
1979 GtkStatusIconPrivate *priv;
1981 g_return_if_fail (GTK_IS_MENU (menu));
1982 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
1984 status_icon = GTK_STATUS_ICON (user_data);
1985 priv = status_icon->priv;
1987 *x = priv->last_click_x;
1988 *y = priv->last_click_y;
1994 * gtk_status_icon_get_geometry:
1995 * @status_icon: a #GtkStatusIcon
1996 * @screen: return location for the screen, or %NULL if the
1997 * information is not needed
1998 * @area: return location for the area occupied by the status
2000 * @orientation: return location for the orientation of the panel
2001 * in which the status icon is embedded, or %NULL. A panel
2002 * at the top or bottom of the screen is horizontal, a panel
2003 * at the left or right is vertical.
2005 * Obtains information about the location of the status icon
2006 * on screen. This information can be used to e.g. position
2007 * popups like notification bubbles.
2009 * See gtk_status_icon_position_menu() for a more convenient
2010 * alternative for positioning menus.
2012 * Note that some platforms do not allow GTK+ to provide
2013 * this information, and even on platforms that do allow it,
2014 * the information is not reliable unless the status icon
2015 * is embedded in a notification area, see
2016 * gtk_status_icon_is_embedded().
2018 * Return value: %TRUE if the location information has
2024 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
2027 GtkOrientation *orientation)
2029 #ifdef GDK_WINDOWING_X11
2031 GtkStatusIconPrivate *priv;
2034 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
2036 priv = status_icon->priv;
2037 widget = priv->tray_icon;
2040 *screen = gtk_widget_get_screen (widget);
2044 gdk_window_get_origin (widget->window, &x, &y);
2047 area->width = widget->allocation.width;
2048 area->height = widget->allocation.height;
2052 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2057 #endif /* GDK_WINDOWING_X11 */
2061 #define __GTK_STATUS_ICON_C__
2062 #include "gtkaliasdef.c"