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"
37 #include "gtkmarshalers.h"
38 #include "gtktooltips.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"
59 #define BLINK_TIMEOUT 500
85 static guint status_icon_signals [LAST_SIGNAL] = { 0 };
87 #ifdef GDK_WINDOWING_QUARTZ
88 #include "gtkstatusicon-quartz.c"
91 struct _GtkStatusIconPrivate
93 #ifdef GDK_WINDOWING_X11
96 GtkTooltips *tooltips;
99 #ifdef GDK_WINDOWING_WIN32
100 GtkWidget *dummy_widget;
102 gint last_click_x, last_click_y;
103 GtkOrientation orientation;
106 #ifdef GDK_WINDOWING_QUARTZ
107 GtkWidget *dummy_widget;
108 GtkQuartzStatusIcon *status_item;
116 GtkImageType storage_type;
125 GdkPixbuf *blank_icon;
126 guint blinking_timeout;
133 static GObject* gtk_status_icon_constructor (GType type,
134 guint n_construct_properties,
135 GObjectConstructParam *construct_params);
136 static void gtk_status_icon_finalize (GObject *object);
137 static void gtk_status_icon_set_property (GObject *object,
141 static void gtk_status_icon_get_property (GObject *object,
146 #ifdef GDK_WINDOWING_X11
147 static void gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
148 GtkAllocation *allocation);
149 static void gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
150 GdkScreen *old_screen);
151 static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
152 static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
155 static gboolean gtk_status_icon_button_press (GtkStatusIcon *status_icon,
156 GdkEventButton *event);
157 static void gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon);
158 static void gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon);
161 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
164 gtk_status_icon_class_init (GtkStatusIconClass *class)
166 GObjectClass *gobject_class = (GObjectClass *) class;
168 gobject_class->constructor = gtk_status_icon_constructor;
169 gobject_class->finalize = gtk_status_icon_finalize;
170 gobject_class->set_property = gtk_status_icon_set_property;
171 gobject_class->get_property = gtk_status_icon_get_property;
173 g_object_class_install_property (gobject_class,
175 g_param_spec_object ("pixbuf",
177 P_("A GdkPixbuf to display"),
179 GTK_PARAM_READWRITE));
181 g_object_class_install_property (gobject_class,
183 g_param_spec_string ("file",
185 P_("Filename to load and display"),
187 GTK_PARAM_WRITABLE));
189 g_object_class_install_property (gobject_class,
191 g_param_spec_string ("stock",
193 P_("Stock ID for a stock image to display"),
195 GTK_PARAM_READWRITE));
197 g_object_class_install_property (gobject_class,
199 g_param_spec_string ("icon-name",
201 P_("The name of the icon from the icon theme"),
203 GTK_PARAM_READWRITE));
205 g_object_class_install_property (gobject_class,
207 g_param_spec_enum ("storage-type",
209 P_("The representation being used for image data"),
212 GTK_PARAM_READABLE));
214 g_object_class_install_property (gobject_class,
216 g_param_spec_int ("size",
218 P_("The size of the icon"),
222 GTK_PARAM_READABLE));
224 g_object_class_install_property (gobject_class,
226 g_param_spec_object ("screen",
228 P_("The screen where this status icon will be displayed"),
230 GTK_PARAM_READWRITE));
232 g_object_class_install_property (gobject_class,
234 g_param_spec_boolean ("blinking",
236 P_("Whether or not the status icon is blinking"),
238 GTK_PARAM_READWRITE));
240 g_object_class_install_property (gobject_class,
242 g_param_spec_boolean ("visible",
244 P_("Whether or not the status icon is visible"),
246 GTK_PARAM_READWRITE));
250 * GtkStatusIcon:embedded:
252 * %TRUE if the statusicon is embedded in a notification area.
256 g_object_class_install_property (gobject_class,
258 g_param_spec_boolean ("embedded",
260 P_("Whether or not the status icon is embedded"),
262 GTK_PARAM_READABLE));
265 * GtkStatusIcon:orientation:
267 * The orientation of the tray in which the statusicon
272 g_object_class_install_property (gobject_class,
274 g_param_spec_enum ("orientation",
276 P_("The orientation of the tray"),
277 GTK_TYPE_ORIENTATION,
278 GTK_ORIENTATION_HORIZONTAL,
279 GTK_PARAM_READABLE));
283 * GtkStatusIcon::activate:
284 * @status_icon: the object which received the signal
286 * Gets emitted when the user activates the status icon.
287 * If and how status icons can activated is platform-dependent.
291 status_icon_signals [ACTIVATE_SIGNAL] =
292 g_signal_new (I_("activate"),
293 G_TYPE_FROM_CLASS (gobject_class),
294 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
295 G_STRUCT_OFFSET (GtkStatusIconClass, activate),
298 g_cclosure_marshal_VOID__VOID,
303 * GtkStatusIcon::popup-menu:
304 * @status_icon: the object which received the signal
305 * @button: the button that was pressed, or 0 if the
306 * signal is not emitted in response to a button press event
307 * @activate_time: the timestamp of the event that
308 * triggered the signal emission
310 * Gets emitted when the user brings up the context menu
311 * of the status icon. Whether status icons can have context
312 * menus and how these are activated is platform-dependent.
314 * The @button and @activate_timeout parameters should be
315 * passed as the last to arguments to gtk_menu_popup().
319 status_icon_signals [POPUP_MENU_SIGNAL] =
320 g_signal_new (I_("popup_menu"),
321 G_TYPE_FROM_CLASS (gobject_class),
322 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
323 G_STRUCT_OFFSET (GtkStatusIconClass, popup_menu),
326 _gtk_marshal_VOID__UINT_UINT,
333 * GtkStatusIcon::size-changed:
334 * @status_icon: the object which received the signal
335 * @size: the new size
337 * Gets emitted when the size available for the image
338 * changes, e.g. because the notification area got resized.
340 * Return value: %TRUE if the icon was updated for the new
341 * size. Otherwise, GTK+ will scale the icon as necessary.
345 status_icon_signals [SIZE_CHANGED_SIGNAL] =
346 g_signal_new (I_("size_changed"),
347 G_TYPE_FROM_CLASS (gobject_class),
349 G_STRUCT_OFFSET (GtkStatusIconClass, size_changed),
350 g_signal_accumulator_true_handled,
352 _gtk_marshal_BOOLEAN__INT,
357 g_type_class_add_private (class, sizeof (GtkStatusIconPrivate));
360 #ifdef GDK_WINDOWING_WIN32
363 build_button_event (GtkStatusIconPrivate *priv,
369 GdkRectangle monitor0;
371 /* We know that gdk/win32 puts the primary monitor at index 0 */
372 gdk_screen_get_monitor_geometry (gdk_screen_get_default (), 0, &monitor0);
374 e->window = gdk_get_default_root_window ();
375 e->send_event = TRUE;
376 e->time = GetTickCount ();
378 priv->last_click_x = e->x = pos.x + monitor0.x;
379 priv->last_click_y = e->y = pos.y + monitor0.y;
383 e->device = gdk_display_get_default ()->core_pointer;
388 static LRESULT CALLBACK
394 if (message == WM_GTK_TRAY_NOTIFICATION)
397 GtkStatusIcon *status_icon = GTK_STATUS_ICON (wparam);
403 build_button_event (status_icon->priv, &e, GDK_BUTTON_PRESS,
404 (lparam == WM_LBUTTONDOWN) ? 1 : 3);
405 gtk_status_icon_button_press (status_icon, &e);
414 return DefWindowProc (hwnd, message, wparam, lparam);
419 create_tray_observer (void)
422 static HWND hwnd = NULL;
424 HINSTANCE hmodule = GetModuleHandle (NULL);
429 memset (&wclass, 0, sizeof(WNDCLASS));
430 wclass.lpszClassName = "gtkstatusicon-observer";
431 wclass.lpfnWndProc = wndproc;
432 wclass.hInstance = hmodule;
434 klass = RegisterClass (&wclass);
438 hwnd = CreateWindow (MAKEINTRESOURCE(klass),
440 0, 0, 1, 1, NULL, NULL,
444 UnregisterClass (MAKEINTRESOURCE(klass), hmodule);
454 gtk_status_icon_init (GtkStatusIcon *status_icon)
456 GtkStatusIconPrivate *priv;
458 priv = G_TYPE_INSTANCE_GET_PRIVATE (status_icon, GTK_TYPE_STATUS_ICON,
459 GtkStatusIconPrivate);
460 status_icon->priv = priv;
462 priv->storage_type = GTK_IMAGE_EMPTY;
463 priv->visible = TRUE;
465 #ifdef GDK_WINDOWING_X11
467 priv->image_width = 0;
468 priv->image_height = 0;
470 priv->tray_icon = GTK_WIDGET (_gtk_tray_icon_new (NULL));
472 gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
473 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
475 g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
476 G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
477 g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
478 G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
479 g_signal_connect_swapped (priv->tray_icon, "button-press-event",
480 G_CALLBACK (gtk_status_icon_button_press), status_icon);
481 g_signal_connect_swapped (priv->tray_icon, "screen-changed",
482 G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
483 priv->image = gtk_image_new ();
484 gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
485 gtk_widget_show (priv->image);
487 g_signal_connect_swapped (priv->image, "size-allocate",
488 G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
490 status_icon->priv->tooltips = gtk_tooltips_new ();
491 g_object_ref_sink (priv->tooltips);
494 #ifdef GDK_WINDOWING_WIN32
496 /* Get position and orientation of Windows taskbar. */
500 abd.cbSize = sizeof (abd);
501 SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
502 if (abd.rc.bottom - abd.rc.top > abd.rc.right - abd.rc.left)
503 priv->orientation = GTK_ORIENTATION_VERTICAL;
505 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
508 priv->last_click_x = priv->last_click_y = 0;
510 /* Are the system tray icons always 16 pixels square? */
512 priv->image_width = 16;
513 priv->image_height = 16;
515 priv->dummy_widget = gtk_label_new ("");
517 memset (&priv->nid, 0, sizeof (priv->nid));
519 priv->nid.hWnd = create_tray_observer ();
520 priv->nid.uID = GPOINTER_TO_UINT (status_icon);
521 priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
522 priv->nid.uFlags = NIF_MESSAGE;
524 if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
526 g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
527 priv->nid.hWnd = NULL;
531 #ifdef GDK_WINDOWING_QUARTZ
532 priv->dummy_widget = gtk_label_new ("");
536 priv->status_item = [[GtkQuartzStatusIcon alloc] initWithStatusIcon:status_icon];
538 priv->image_width = priv->image_height = [priv->status_item getHeight];
539 priv->size = priv->image_height;
547 gtk_status_icon_constructor (GType type,
548 guint n_construct_properties,
549 GObjectConstructParam *construct_params)
552 GtkStatusIcon *status_icon;
553 GtkStatusIconPrivate *priv;
555 object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
556 n_construct_properties,
559 #ifdef GDK_WINDOWING_X11
560 status_icon = GTK_STATUS_ICON (object);
561 priv = status_icon->priv;
564 gtk_widget_show (priv->tray_icon);
571 gtk_status_icon_finalize (GObject *object)
573 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
574 GtkStatusIconPrivate *priv = status_icon->priv;
576 gtk_status_icon_disable_blinking (status_icon);
578 gtk_status_icon_reset_image_data (status_icon);
580 if (priv->blank_icon)
581 g_object_unref (priv->blank_icon);
582 priv->blank_icon = NULL;
584 #ifdef GDK_WINDOWING_X11
586 g_object_unref (priv->tooltips);
587 priv->tooltips = NULL;
589 gtk_widget_destroy (priv->tray_icon);
592 #ifdef GDK_WINDOWING_WIN32
593 if (priv->nid.hWnd != NULL && priv->visible)
594 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
596 DestroyIcon (priv->nid.hIcon);
598 gtk_widget_destroy (priv->dummy_widget);
601 #ifdef GDK_WINDOWING_QUARTZ
603 [priv->status_item release];
607 G_OBJECT_CLASS (gtk_status_icon_parent_class)->finalize (object);
611 gtk_status_icon_set_property (GObject *object,
616 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
621 gtk_status_icon_set_from_pixbuf (status_icon, g_value_get_object (value));
624 gtk_status_icon_set_from_file (status_icon, g_value_get_string (value));
627 gtk_status_icon_set_from_stock (status_icon, g_value_get_string (value));
630 gtk_status_icon_set_from_icon_name (status_icon, g_value_get_string (value));
633 gtk_status_icon_set_screen (status_icon, g_value_get_object (value));
636 gtk_status_icon_set_blinking (status_icon, g_value_get_boolean (value));
639 gtk_status_icon_set_visible (status_icon, g_value_get_boolean (value));
642 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
648 gtk_status_icon_get_property (GObject *object,
653 GtkStatusIcon *status_icon = GTK_STATUS_ICON (object);
654 GtkStatusIconPrivate *priv = status_icon->priv;
656 /* The "getter" functions whine if you try to get the wrong
657 * storage type. This function is instead robust against that,
658 * so that GUI builders don't have to jump through hoops
665 if (priv->storage_type != GTK_IMAGE_PIXBUF)
666 g_value_set_object (value, NULL);
668 g_value_set_object (value, gtk_status_icon_get_pixbuf (status_icon));
671 if (priv->storage_type != GTK_IMAGE_STOCK)
672 g_value_set_string (value, NULL);
674 g_value_set_string (value, gtk_status_icon_get_stock (status_icon));
677 if (priv->storage_type != GTK_IMAGE_ICON_NAME)
678 g_value_set_string (value, NULL);
680 g_value_set_string (value, gtk_status_icon_get_icon_name (status_icon));
682 case PROP_STORAGE_TYPE:
683 g_value_set_enum (value, gtk_status_icon_get_storage_type (status_icon));
686 g_value_set_int (value, gtk_status_icon_get_size (status_icon));
689 g_value_set_object (value, gtk_status_icon_get_screen (status_icon));
692 g_value_set_boolean (value, gtk_status_icon_get_blinking (status_icon));
695 g_value_set_boolean (value, gtk_status_icon_get_visible (status_icon));
698 g_value_set_boolean (value, gtk_status_icon_is_embedded (status_icon));
700 case PROP_ORIENTATION:
701 #ifdef GDK_WINDOWING_X11
702 g_value_set_enum (value, _gtk_tray_icon_get_orientation (status_icon->priv->tray_icon));
704 #ifdef GDK_WINDOWING_WIN32
705 g_value_set_enum (value, status_icon->priv->orientation);
709 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
715 * gtk_status_icon_new:
717 * Creates an empty status icon object.
719 * Return value: a new #GtkStatusIcon
724 gtk_status_icon_new (void)
726 return g_object_new (GTK_TYPE_STATUS_ICON, NULL);
730 * gtk_status_icon_new_from_pixbuf:
731 * @pixbuf: a #GdkPixbuf
733 * Creates a status icon displaying @pixbuf.
735 * The image will be scaled down to fit in the available
736 * space in the notification area, if necessary.
738 * Return value: a new #GtkStatusIcon
743 gtk_status_icon_new_from_pixbuf (GdkPixbuf *pixbuf)
745 return g_object_new (GTK_TYPE_STATUS_ICON,
751 * gtk_status_icon_new_from_file:
752 * @filename: a filename
754 * Creates a status icon displaying the file @filename.
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_file (const gchar *filename)
766 return g_object_new (GTK_TYPE_STATUS_ICON,
772 * gtk_status_icon_new_from_stock:
773 * @stock_id: a stock icon id
775 * Creates a status icon displaying a stock icon. Sample stock icon
776 * names are #GTK_STOCK_OPEN, #GTK_STOCK_QUIT. You can register your
777 * own stock icon names, see gtk_icon_factory_add_default() and
778 * gtk_icon_factory_add().
780 * Return value: a new #GtkStatusIcon
785 gtk_status_icon_new_from_stock (const gchar *stock_id)
787 return g_object_new (GTK_TYPE_STATUS_ICON,
793 * gtk_status_icon_new_from_icon_name:
794 * @icon_name: an icon name
796 * Creates a status icon displaying an icon from the current icon theme.
797 * If the current icon theme is changed, the icon will be updated
800 * Return value: a new #GtkStatusIcon
805 gtk_status_icon_new_from_icon_name (const gchar *icon_name)
807 return g_object_new (GTK_TYPE_STATUS_ICON,
808 "icon-name", icon_name,
813 emit_activate_signal (GtkStatusIcon *status_icon)
815 g_signal_emit (status_icon,
816 status_icon_signals [ACTIVATE_SIGNAL], 0);
820 emit_popup_menu_signal (GtkStatusIcon *status_icon,
822 guint32 activate_time)
824 g_signal_emit (status_icon,
825 status_icon_signals [POPUP_MENU_SIGNAL], 0,
830 #ifdef GDK_WINDOWING_X11
833 emit_size_changed_signal (GtkStatusIcon *status_icon,
836 gboolean handled = FALSE;
838 g_signal_emit (status_icon,
839 status_icon_signals [SIZE_CHANGED_SIGNAL], 0,
849 gtk_status_icon_blank_icon (GtkStatusIcon *status_icon)
851 GtkStatusIconPrivate *priv = status_icon->priv;
853 if (priv->blank_icon)
857 width = gdk_pixbuf_get_width (priv->blank_icon);
858 height = gdk_pixbuf_get_height (priv->blank_icon);
861 if (width == priv->image_width && height == priv->image_height)
862 return priv->blank_icon;
865 g_object_unref (priv->blank_icon);
866 priv->blank_icon = NULL;
870 priv->blank_icon = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
873 if (priv->blank_icon)
874 gdk_pixbuf_fill (priv->blank_icon, 0);
876 return priv->blank_icon;
879 #ifdef GDK_WINDOWING_X11
882 find_icon_size (GtkWidget *widget,
886 GtkSettings *settings;
890 screen = gtk_widget_get_screen (widget);
893 return GTK_ICON_SIZE_MENU;
895 settings = gtk_settings_get_for_screen (screen);
898 size = GTK_ICON_SIZE_MENU;
900 for (s = GTK_ICON_SIZE_MENU; s < GTK_ICON_SIZE_DIALOG; s++)
902 if (gtk_icon_size_lookup_for_settings (settings, s, &w, &h) &&
903 w <= pixel_size && h <= pixel_size)
905 d = MAX (pixel_size - w, pixel_size - h);
920 gtk_status_icon_update_image (GtkStatusIcon *status_icon)
922 GtkStatusIconPrivate *priv = status_icon->priv;
923 #ifdef GDK_WINDOWING_WIN32
929 #ifdef GDK_WINDOWING_X11
930 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image),
931 gtk_status_icon_blank_icon (status_icon));
933 #ifdef GDK_WINDOWING_WIN32
934 prev_hicon = priv->nid.hIcon;
935 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
936 priv->nid.uFlags |= NIF_ICON;
937 if (priv->nid.hWnd != NULL && priv->visible)
938 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
939 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
941 DestroyIcon (prev_hicon);
943 #ifdef GDK_WINDOWING_QUARTZ
945 [priv->status_item setImage:gtk_status_icon_blank_icon (status_icon)];
951 switch (priv->storage_type)
953 case GTK_IMAGE_PIXBUF:
957 pixbuf = priv->image_data.pixbuf;
968 width = gdk_pixbuf_get_width (pixbuf);
969 height = gdk_pixbuf_get_height (pixbuf);
971 if (width > size || height > size)
972 scaled = gdk_pixbuf_scale_simple (pixbuf,
975 GDK_INTERP_BILINEAR);
977 scaled = g_object_ref (pixbuf);
979 #ifdef GDK_WINDOWING_X11
980 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
982 #ifdef GDK_WINDOWING_WIN32
983 prev_hicon = priv->nid.hIcon;
984 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
985 priv->nid.uFlags |= NIF_ICON;
986 if (priv->nid.hWnd != NULL && priv->visible)
987 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
988 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
990 DestroyIcon (prev_hicon);
992 #ifdef GDK_WINDOWING_QUARTZ
994 [priv->status_item setImage:scaled];
998 g_object_unref (scaled);
1002 #ifdef GDK_WINDOWING_X11
1003 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1005 #ifdef GDK_WINDOWING_WIN32
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 #ifdef GDK_WINDOWING_QUARTZ
1012 [priv->status_item setImage:NULL];
1018 case GTK_IMAGE_STOCK:
1020 #ifdef GDK_WINDOWING_X11
1021 GtkIconSize size = find_icon_size (priv->image, priv->size);
1022 gtk_image_set_from_stock (GTK_IMAGE (priv->image),
1023 priv->image_data.stock_id,
1026 #ifdef GDK_WINDOWING_WIN32
1029 gtk_widget_render_icon (priv->dummy_widget,
1030 priv->image_data.stock_id,
1031 GTK_ICON_SIZE_SMALL_TOOLBAR,
1034 prev_hicon = priv->nid.hIcon;
1035 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1036 priv->nid.uFlags |= NIF_ICON;
1037 if (priv->nid.hWnd != NULL && priv->visible)
1038 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1039 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1041 DestroyIcon (prev_hicon);
1042 g_object_unref (pixbuf);
1045 #ifdef GDK_WINDOWING_QUARTZ
1049 pixbuf = gtk_widget_render_icon (priv->dummy_widget,
1050 priv->image_data.stock_id,
1051 GTK_ICON_SIZE_SMALL_TOOLBAR,
1054 [priv->status_item setImage:pixbuf];
1055 QUARTZ_POOL_RELEASE;
1056 g_object_unref (pixbuf);
1062 case GTK_IMAGE_ICON_NAME:
1064 #ifdef GDK_WINDOWING_X11
1065 GtkIconSize size = find_icon_size (priv->image, priv->size);
1066 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
1067 priv->image_data.icon_name,
1070 #ifdef GDK_WINDOWING_WIN32
1073 gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1074 priv->image_data.icon_name,
1078 prev_hicon = priv->nid.hIcon;
1079 priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
1080 priv->nid.uFlags |= NIF_ICON;
1081 if (priv->nid.hWnd != NULL && priv->visible)
1082 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1083 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1085 DestroyIcon (prev_hicon);
1086 g_object_unref (pixbuf);
1089 #ifdef GDK_WINDOWING_QUARTZ
1093 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
1094 priv->image_data.icon_name,
1099 [priv->status_item setImage:pixbuf];
1100 QUARTZ_POOL_RELEASE;
1101 g_object_unref (pixbuf);
1108 case GTK_IMAGE_EMPTY:
1109 #ifdef GDK_WINDOWING_X11
1110 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), NULL);
1112 #ifdef GDK_WINDOWING_WIN32
1113 priv->nid.uFlags &= ~NIF_ICON;
1114 if (priv->nid.hWnd != NULL && priv->visible)
1115 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1116 g_warning ("%s:%d:Shell_NotifyIcon(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1118 #ifdef GDK_WINDOWING_QUARTZ
1121 [priv->status_item setImage:NULL];
1122 QUARTZ_POOL_RELEASE;
1127 g_assert_not_reached ();
1132 #ifdef GDK_WINDOWING_X11
1135 gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
1136 GtkAllocation *allocation)
1138 GtkStatusIconPrivate *priv = status_icon->priv;
1139 GtkOrientation orientation;
1142 orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
1144 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1145 size = allocation->height;
1147 size = allocation->width;
1149 priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
1150 priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
1152 if (priv->size != size)
1156 g_object_notify (G_OBJECT (status_icon), "size");
1158 if (!emit_size_changed_signal (status_icon, size))
1159 gtk_status_icon_update_image (status_icon);
1164 gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
1165 GdkScreen *old_screen)
1167 GtkStatusIconPrivate *priv = status_icon->priv;
1169 if (gtk_widget_get_screen (priv->tray_icon) != old_screen)
1171 g_object_notify (G_OBJECT (status_icon), "screen");
1177 #ifdef GDK_WINDOWING_X11
1180 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
1182 g_object_notify (G_OBJECT (status_icon), "embedded");
1186 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
1188 g_object_notify (G_OBJECT (status_icon), "orientation");
1194 gtk_status_icon_button_press (GtkStatusIcon *status_icon,
1195 GdkEventButton *event)
1197 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1199 emit_activate_signal (status_icon);
1202 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1204 emit_popup_menu_signal (status_icon, event->button, event->time);
1212 gtk_status_icon_reset_image_data (GtkStatusIcon *status_icon)
1214 GtkStatusIconPrivate *priv = status_icon->priv;
1216 switch (priv->storage_type)
1218 case GTK_IMAGE_PIXBUF:
1219 if (priv->image_data.pixbuf)
1220 g_object_unref (priv->image_data.pixbuf);
1221 priv->image_data.pixbuf = NULL;
1222 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1225 case GTK_IMAGE_STOCK:
1226 g_free (priv->image_data.stock_id);
1227 priv->image_data.stock_id = NULL;
1229 g_object_notify (G_OBJECT (status_icon), "stock");
1232 case GTK_IMAGE_ICON_NAME:
1233 g_free (priv->image_data.icon_name);
1234 priv->image_data.icon_name = NULL;
1236 g_object_notify (G_OBJECT (status_icon), "icon-name");
1239 case GTK_IMAGE_EMPTY:
1242 g_assert_not_reached ();
1246 priv->storage_type = GTK_IMAGE_EMPTY;
1247 g_object_notify (G_OBJECT (status_icon), "storage-type");
1251 gtk_status_icon_set_image (GtkStatusIcon *status_icon,
1252 GtkImageType storage_type,
1255 GtkStatusIconPrivate *priv = status_icon->priv;
1257 g_object_freeze_notify (G_OBJECT (status_icon));
1259 gtk_status_icon_reset_image_data (status_icon);
1261 priv->storage_type = storage_type;
1262 g_object_notify (G_OBJECT (status_icon), "storage-type");
1264 switch (storage_type)
1266 case GTK_IMAGE_PIXBUF:
1267 priv->image_data.pixbuf = (GdkPixbuf *)data;
1268 g_object_notify (G_OBJECT (status_icon), "pixbuf");
1270 case GTK_IMAGE_STOCK:
1271 priv->image_data.stock_id = g_strdup ((const gchar *)data);
1272 g_object_notify (G_OBJECT (status_icon), "stock");
1274 case GTK_IMAGE_ICON_NAME:
1275 priv->image_data.icon_name = g_strdup ((const gchar *)data);
1276 g_object_notify (G_OBJECT (status_icon), "icon-name");
1279 g_warning ("Image type %u not handled by GtkStatusIcon", storage_type);
1282 g_object_thaw_notify (G_OBJECT (status_icon));
1284 gtk_status_icon_update_image (status_icon);
1288 * gtk_status_icon_set_from_pixbuf:
1289 * @status_icon: a #GtkStatusIcon
1290 * @pixbuf: a #GdkPixbuf or %NULL
1292 * Makes @status_icon display @pixbuf.
1293 * See gtk_status_icon_new_from_pixbuf() for details.
1298 gtk_status_icon_set_from_pixbuf (GtkStatusIcon *status_icon,
1301 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1302 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1305 g_object_ref (pixbuf);
1307 gtk_status_icon_set_image (status_icon, GTK_IMAGE_PIXBUF,
1312 * gtk_status_icon_set_from_file:
1313 * @status_icon: a #GtkStatusIcon
1314 * @filename: a filename
1316 * Makes @status_icon display the file @filename.
1317 * See gtk_status_icon_new_from_file() for details.
1322 gtk_status_icon_set_from_file (GtkStatusIcon *status_icon,
1323 const gchar *filename)
1327 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1328 g_return_if_fail (filename != NULL);
1330 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1332 gtk_status_icon_set_from_pixbuf (status_icon, pixbuf);
1335 g_object_unref (pixbuf);
1339 * gtk_status_icon_set_from_stock:
1340 * @status_icon: a #GtkStatusIcon
1341 * @stock_id: a stock icon id
1343 * Makes @status_icon display the stock icon with the id @stock_id.
1344 * See gtk_status_icon_new_from_stock() for details.
1349 gtk_status_icon_set_from_stock (GtkStatusIcon *status_icon,
1350 const gchar *stock_id)
1352 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1353 g_return_if_fail (stock_id != NULL);
1355 gtk_status_icon_set_image (status_icon, GTK_IMAGE_STOCK,
1356 (gpointer) stock_id);
1360 * gtk_status_icon_set_from_icon_name:
1361 * @status_icon: a #GtkStatusIcon
1362 * @icon_name: an icon name
1364 * Makes @status_icon display the icon named @icon_name from the
1365 * current icon theme.
1366 * See gtk_status_icon_new_from_icon_name() for details.
1371 gtk_status_icon_set_from_icon_name (GtkStatusIcon *status_icon,
1372 const gchar *icon_name)
1374 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1375 g_return_if_fail (icon_name != NULL);
1377 gtk_status_icon_set_image (status_icon, GTK_IMAGE_ICON_NAME,
1378 (gpointer) icon_name);
1382 * gtk_status_icon_get_storage_type:
1383 * @status_icon: a #GtkStatusIcon
1385 * Gets the type of representation being used by the #GtkStatusIcon
1386 * to store image data. If the #GtkStatusIcon has no image data,
1387 * the return value will be %GTK_IMAGE_EMPTY.
1389 * Return value: the image representation being used
1394 gtk_status_icon_get_storage_type (GtkStatusIcon *status_icon)
1396 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), GTK_IMAGE_EMPTY);
1398 return status_icon->priv->storage_type;
1401 * gtk_status_icon_get_pixbuf:
1402 * @status_icon: a #GtkStatusIcon
1404 * Gets the #GdkPixbuf being displayed by the #GtkStatusIcon.
1405 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1406 * %GTK_IMAGE_PIXBUF (see gtk_status_icon_get_storage_type()).
1407 * The caller of this function does not own a reference to the
1410 * Return value: the displayed pixbuf, or %NULL if the image is empty.
1415 gtk_status_icon_get_pixbuf (GtkStatusIcon *status_icon)
1417 GtkStatusIconPrivate *priv;
1419 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1421 priv = status_icon->priv;
1423 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_PIXBUF ||
1424 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1426 if (priv->storage_type == GTK_IMAGE_EMPTY)
1427 priv->image_data.pixbuf = NULL;
1429 return priv->image_data.pixbuf;
1433 * gtk_status_icon_get_stock:
1434 * @status_icon: a #GtkStatusIcon
1436 * Gets the id of the stock icon being displayed by the #GtkStatusIcon.
1437 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1438 * %GTK_IMAGE_STOCK (see gtk_status_icon_get_storage_type()).
1439 * The returned string is owned by the #GtkStatusIcon and should not
1440 * be freed or modified.
1442 * Return value: stock id of the displayed stock icon,
1443 * or %NULL if the image is empty.
1447 G_CONST_RETURN gchar *
1448 gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
1450 GtkStatusIconPrivate *priv;
1452 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1454 priv = status_icon->priv;
1456 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_STOCK ||
1457 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1459 if (priv->storage_type == GTK_IMAGE_EMPTY)
1460 priv->image_data.stock_id = NULL;
1462 return priv->image_data.stock_id;
1466 * gtk_status_icon_get_icon_name:
1467 * @status_icon: a #GtkStatusIcon
1469 * Gets the name of the icon being displayed by the #GtkStatusIcon.
1470 * The storage type of the status icon must be %GTK_IMAGE_EMPTY or
1471 * %GTK_IMAGE_ICON_NAME (see gtk_status_icon_get_storage_type()).
1472 * The returned string is owned by the #GtkStatusIcon and should not
1473 * be freed or modified.
1475 * Return value: name of the displayed icon, or %NULL if the image is empty.
1479 G_CONST_RETURN gchar *
1480 gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
1482 GtkStatusIconPrivate *priv;
1484 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1486 priv = status_icon->priv;
1488 g_return_val_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME ||
1489 priv->storage_type == GTK_IMAGE_EMPTY, NULL);
1491 if (priv->storage_type == GTK_IMAGE_EMPTY)
1492 priv->image_data.icon_name = NULL;
1494 return priv->image_data.icon_name;
1498 * gtk_status_icon_get_size:
1499 * @status_icon: a #GtkStatusIcon
1501 * Gets the size in pixels that is available for the image.
1502 * Stock icons and named icons adapt their size automatically
1503 * if the size of the notification area changes. For other
1504 * storage types, the size-changed signal can be used to
1505 * react to size changes.
1507 * Return value: the size that is available for the image
1512 gtk_status_icon_get_size (GtkStatusIcon *status_icon)
1514 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), 0);
1516 return status_icon->priv->size;
1520 * gtk_status_icon_set_screen:
1521 * @status_icon: a #GtkStatusIcon
1522 * @screen: a #GdkScreen
1524 * Sets the #GdkScreen where @status_icon is displayed; if
1525 * the icon is already mapped, it will be unmapped, and
1526 * then remapped on the new screen.
1531 gtk_status_icon_set_screen (GtkStatusIcon *status_icon,
1534 g_return_if_fail (GDK_IS_SCREEN (screen));
1536 #ifdef GDK_WINDOWING_X11
1537 gtk_window_set_screen (GTK_WINDOW (status_icon->priv->tray_icon), screen);
1542 * gtk_status_icon_get_screen:
1543 * @window: a #GtkStatusIcon.
1545 * Returns the #GdkScreen associated with @status_icon.
1547 * Return value: a #GdkScreen.
1552 gtk_status_icon_get_screen (GtkStatusIcon *status_icon)
1554 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), NULL);
1556 #ifdef GDK_WINDOWING_X11
1557 return gtk_window_get_screen (GTK_WINDOW (status_icon->priv->tray_icon));
1559 return gdk_screen_get_default ();
1564 * gtk_status_icon_set_tooltip:
1565 * @status_icon: a #GtkStatusIcon
1566 * @tooltip_text: the tooltip text, or %NULL
1568 * Sets the tooltip of the status icon.
1573 gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
1574 const gchar *tooltip_text)
1576 GtkStatusIconPrivate *priv;
1578 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1580 priv = status_icon->priv;
1582 #ifdef GDK_WINDOWING_X11
1583 gtk_tooltips_set_tip (priv->tooltips, priv->tray_icon,
1584 tooltip_text, NULL);
1586 #ifdef GDK_WINDOWING_WIN32
1587 if (tooltip_text == NULL)
1588 priv->nid.uFlags &= ~NIF_TIP;
1591 WCHAR *wcs = g_utf8_to_utf16 (tooltip_text, -1, NULL, NULL, NULL);
1593 priv->nid.uFlags |= NIF_TIP;
1594 wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
1595 priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
1598 if (priv->nid.hWnd != NULL && priv->visible)
1599 if (!Shell_NotifyIconW (NIM_MODIFY, &priv->nid))
1600 g_warning ("%s:%d:Shell_NotifyIconW(NIM_MODIFY) failed", __FILE__, __LINE__-1);
1602 #ifdef GDK_WINDOWING_QUARTZ
1604 [priv->status_item setToolTip:tooltip_text];
1605 QUARTZ_POOL_RELEASE;
1610 gtk_status_icon_blinker (GtkStatusIcon *status_icon)
1612 GtkStatusIconPrivate *priv = status_icon->priv;
1614 priv->blink_off = !priv->blink_off;
1616 gtk_status_icon_update_image (status_icon);
1622 gtk_status_icon_enable_blinking (GtkStatusIcon *status_icon)
1624 GtkStatusIconPrivate *priv = status_icon->priv;
1626 if (!priv->blinking_timeout)
1628 gtk_status_icon_blinker (status_icon);
1630 priv->blinking_timeout =
1631 gdk_threads_add_timeout (BLINK_TIMEOUT,
1632 (GSourceFunc) gtk_status_icon_blinker,
1638 gtk_status_icon_disable_blinking (GtkStatusIcon *status_icon)
1640 GtkStatusIconPrivate *priv = status_icon->priv;
1642 if (priv->blinking_timeout)
1644 g_source_remove (priv->blinking_timeout);
1645 priv->blinking_timeout = 0;
1646 priv->blink_off = FALSE;
1648 gtk_status_icon_update_image (status_icon);
1653 * gtk_status_icon_set_visible:
1654 * @status_icon: a #GtkStatusIcon
1655 * @visible: %TRUE to show the status icon, %FALSE to hide it
1657 * Shows or hides a status icon.
1662 gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
1665 GtkStatusIconPrivate *priv;
1667 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1669 priv = status_icon->priv;
1671 visible = visible != FALSE;
1673 if (priv->visible != visible)
1675 priv->visible = visible;
1677 #ifdef GDK_WINDOWING_X11
1679 gtk_widget_show (priv->tray_icon);
1680 else if (GTK_WIDGET_REALIZED (priv->tray_icon)) {
1681 gtk_widget_hide (priv->tray_icon);
1682 gtk_widget_unrealize (priv->tray_icon);
1685 #ifdef GDK_WINDOWING_WIN32
1686 if (priv->nid.hWnd != NULL)
1689 Shell_NotifyIconW (NIM_ADD, &priv->nid);
1691 Shell_NotifyIconW (NIM_DELETE, &priv->nid);
1694 #ifdef GDK_WINDOWING_QUARTZ
1696 [priv->status_item setVisible:visible];
1697 QUARTZ_POOL_RELEASE;
1699 g_object_notify (G_OBJECT (status_icon), "visible");
1704 * gtk_status_icon_get_visible:
1705 * @status_icon: a #GtkStatusIcon
1707 * Returns whether the status icon is visible or not.
1708 * Note that being visible does not guarantee that
1709 * the user can actually see the icon, see also
1710 * gtk_status_icon_is_embedded().
1712 * Return value: %TRUE if the status icon is visible
1717 gtk_status_icon_get_visible (GtkStatusIcon *status_icon)
1719 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1721 return status_icon->priv->visible;
1725 * gtk_status_icon_set_blinking:
1726 * @status_icon: a #GtkStatusIcon
1727 * @blinking: %TRUE to turn blinking on, %FALSE to turn it off
1729 * Makes the status icon start or stop blinking.
1730 * Note that blinking user interface elements may be problematic
1731 * for some users, and thus may be turned off, in which case
1732 * this setting has no effect.
1737 gtk_status_icon_set_blinking (GtkStatusIcon *status_icon,
1740 GtkStatusIconPrivate *priv;
1742 g_return_if_fail (GTK_IS_STATUS_ICON (status_icon));
1744 priv = status_icon->priv;
1746 blinking = blinking != FALSE;
1748 if (priv->blinking != blinking)
1750 priv->blinking = blinking;
1753 gtk_status_icon_enable_blinking (status_icon);
1755 gtk_status_icon_disable_blinking (status_icon);
1757 g_object_notify (G_OBJECT (status_icon), "blinking");
1762 * gtk_status_icon_get_blinking:
1763 * @status_icon: a #GtkStatusIcon
1765 * Returns whether the icon is blinking, see
1766 * gtk_status_icon_set_blinking().
1768 * Return value: %TRUE if the icon is blinking
1773 gtk_status_icon_get_blinking (GtkStatusIcon *status_icon)
1775 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1777 return status_icon->priv->blinking;
1781 * gtk_status_icon_is_embedded:
1782 * @status_icon: a #GtkStatusIcon
1784 * Returns whether the status icon is embedded in a notification
1787 * Return value: %TRUE if the status icon is embedded in
1788 * a notification area.
1793 gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
1795 #ifdef GDK_WINDOWING_X11
1799 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1801 #ifdef GDK_WINDOWING_X11
1802 plug = GTK_PLUG (status_icon->priv->tray_icon);
1804 if (plug->socket_window)
1809 #ifdef GDK_WINDOWING_WIN32
1812 #ifdef GDK_WINDOWING_QUARTZ
1818 * gtk_status_icon_position_menu:
1819 * @menu: the #GtkMenu
1820 * @x: return location for the x position
1821 * @y: return location for the y position
1822 * @push_in: return location for whether the menu should be pushed in
1823 * to be completely inside the screen instead of just clamped to the
1824 * size to the screen.
1825 * @user_data: the status icon to position the menu on
1827 * Menu positioning function to use with gtk_menu_popup()
1828 * to position @menu aligned to the status icon @user_data.
1833 gtk_status_icon_position_menu (GtkMenu *menu,
1839 #ifdef GDK_WINDOWING_X11
1840 GtkStatusIcon *status_icon;
1841 GtkStatusIconPrivate *priv;
1842 GtkTrayIcon *tray_icon;
1845 GtkTextDirection direction;
1846 GtkRequisition menu_req;
1847 GdkRectangle monitor;
1848 gint monitor_num, height, width, xoffset, yoffset;
1850 g_return_if_fail (GTK_IS_MENU (menu));
1851 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
1853 status_icon = GTK_STATUS_ICON (user_data);
1854 priv = status_icon->priv;
1855 tray_icon = GTK_TRAY_ICON (priv->tray_icon);
1856 widget = priv->tray_icon;
1858 direction = gtk_widget_get_direction (widget);
1860 screen = gtk_widget_get_screen (widget);
1861 gtk_menu_set_screen (menu, screen);
1863 monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
1864 if (monitor_num < 0)
1866 gtk_menu_set_monitor (menu, monitor_num);
1868 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1870 gdk_window_get_origin (widget->window, x, y);
1872 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
1874 if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
1877 height = widget->allocation.height;
1878 xoffset = widget->allocation.width;
1883 width = widget->allocation.width;
1886 yoffset = widget->allocation.height;
1889 if (direction == GTK_TEXT_DIR_RTL)
1891 if ((*x - (menu_req.width - width)) >= monitor.x)
1892 *x -= menu_req.width - width;
1893 else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
1895 else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
1896 *x -= menu_req.width - width;
1902 if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
1904 else if ((*x - (menu_req.width - width)) >= monitor.x)
1905 *x -= menu_req.width - width;
1906 else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
1909 *x -= menu_req.width - width;
1912 if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
1914 else if ((*y - (menu_req.height - height)) >= monitor.y)
1915 *y -= menu_req.height - height;
1916 else if (monitor.y + monitor.height - (*y + yoffset) > *y)
1919 *y -= menu_req.height - height;
1922 #endif /* GDK_WINDOWING_X11 */
1924 #ifdef GDK_WINDOWING_WIN32
1925 GtkStatusIcon *status_icon;
1926 GtkStatusIconPrivate *priv;
1928 g_return_if_fail (GTK_IS_MENU (menu));
1929 g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
1931 status_icon = GTK_STATUS_ICON (user_data);
1932 priv = status_icon->priv;
1934 *x = priv->last_click_x;
1935 *y = priv->last_click_y;
1941 * gtk_status_icon_get_geometry:
1942 * @status_icon: a #GtkStatusIcon
1943 * @screen: return location for the screen, or %NULL if the
1944 * information is not needed
1945 * @area: return location for the area occupied by the status
1947 * @orientation: return location for the orientation of the panel
1948 * in which the status icon is embedded, or %NULL. A panel
1949 * at the top or bottom of the screen is horizontal, a panel
1950 * at the left or right is vertical.
1952 * Obtains information about the location of the status icon
1953 * on screen. This information can be used to e.g. position
1954 * popups like notification bubbles.
1956 * See gtk_status_icon_position_menu() for a more convenient
1957 * alternative for positioning menus.
1959 * Note that some platforms do not allow GTK+ to provide
1960 * this information, and even on platforms that do allow it,
1961 * the information is not reliable unless the status icon
1962 * is embedded in a notification area, see
1963 * gtk_status_icon_is_embedded().
1965 * Return value: %TRUE if the location information has
1971 gtk_status_icon_get_geometry (GtkStatusIcon *status_icon,
1974 GtkOrientation *orientation)
1976 #ifdef GDK_WINDOWING_X11
1978 GtkStatusIconPrivate *priv;
1981 g_return_val_if_fail (GTK_IS_STATUS_ICON (status_icon), FALSE);
1983 priv = status_icon->priv;
1984 widget = priv->tray_icon;
1987 *screen = gtk_widget_get_screen (widget);
1991 gdk_window_get_origin (widget->window, &x, &y);
1994 area->width = widget->allocation.width;
1995 area->height = widget->allocation.height;
1999 *orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (widget));
2004 #endif /* GDK_WINDOWING_X11 */
2008 #define __GTK_STATUS_ICON_C__
2009 #include "gtkaliasdef.c"