#include "config.h"
-#include "gtkstatusicon.h"
-
#include <string.h>
+#include "gtkstatusicon.h"
+
#include "gtkintl.h"
#include "gtkiconfactory.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtksizerequest.h"
-#include "gtktrayicon.h"
-
#include "gtkprivate.h"
#include "gtkwidget.h"
#include "gtktooltip.h"
+#include "gtkicontheme.h"
+#include "gtklabel.h"
+#include "gtktypebuiltins.h"
#ifdef GDK_WINDOWING_X11
#include "gdk/x11/gdkx.h"
+#include "gtktrayicon.h"
#endif
#ifdef GDK_WINDOWING_WIN32
-#include "gtkicontheme.h"
-#include "gtklabel.h"
-
-#include "win32/gdkwin32.h"
+#include "gdk/win32/gdkwin32.h"
#define WM_GTK_TRAY_NOTIFICATION (WM_USER+1)
#endif
-#ifdef GDK_WINDOWING_QUARTZ
-#include "gtkicontheme.h"
-#include "gtklabel.h"
-#endif
-#include "gdkkeysyms.h"
+/**
+ * SECTION:gtkstatusicon
+ * @Short_description: Display an icon in the system tray
+ * @Title: GtkStatusIcon
+ *
+ * The "system tray" or notification area is normally used for transient icons
+ * that indicate some special state. For example, a system tray icon might
+ * appear to tell the user that they have new mail, or have an incoming instant
+ * message, or something along those lines. The basic idea is that creating an
+ * icon in the notification area is less annoying than popping up a dialog.
+ *
+ * A #GtkStatusIcon object can be used to display an icon in a "system tray".
+ * The icon can have a tooltip, and the user can interact with it by
+ * activating it or popping up a context menu. Critical information should
+ * not solely be displayed in a #GtkStatusIcon, since it may not be
+ * visible (e.g. when the user doesn't have a notification area on his panel).
+ * This can be checked with gtk_status_icon_is_embedded().
+ *
+ * On X11, the implementation follows the freedesktop.org "System Tray"
+ * <ulink url="http://www.freedesktop.org/wiki/Specifications/systemtray-spec">specification</ulink>.
+ * Implementations of the "tray" side of this specification can
+ * be found e.g. in the GNOME 2 and KDE panel applications.
+ *
+ * Note that a GtkStatusIcon is <emphasis>not</emphasis> a widget, but just
+ * a #GObject. Making it a widget would be impractical, since the system tray
+ * on Win32 doesn't allow to embed arbitrary widgets.
+ */
+
#define BLINK_TIMEOUT 500
#ifdef GDK_WINDOWING_WIN32
GtkWidget *dummy_widget;
NOTIFYICONDATAW nid;
+ gint taskbar_top;
gint last_click_x, last_click_y;
GtkOrientation orientation;
gchar *tooltip_text;
static void gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
static void gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
static void gtk_status_icon_padding_changed (GtkStatusIcon *status_icon);
+static void gtk_status_icon_icon_size_changed(GtkStatusIcon *status_icon);
static void gtk_status_icon_fg_changed (GtkStatusIcon *status_icon);
static void gtk_status_icon_color_changed (GtkTrayIcon *tray,
GParamSpec *pspec,
/**
* GtkStatusIcon::button-press-event:
* @status_icon: the object which received the signal
- * @event: the #GdkEventButton which triggered this signal
+ * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
+ * this signal
*
* The ::button-press-event signal will be emitted when a button
* (typically from a mouse) is pressed.
/**
* GtkStatusIcon::button-release-event:
* @status_icon: the object which received the signal
- * @event: the #GdkEventButton which triggered this signal
+ * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
+ * this signal
*
* The ::button-release-event signal will be emitted when a button
* (typically from a mouse) is released.
/**
* GtkStatusIcon::scroll-event:
* @status_icon: the object which received the signal.
- * @event: the #GdkEventScroll which triggered this signal
+ * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
+ * this signal
*
* The ::scroll-event signal is emitted when a button in the 4 to 7
* range is pressed. Wheel mice are usually configured to generate
e->axes = NULL;
e->state = 0;
e->button = button;
- e->device = gdk_display_get_default ()->core_pointer;
+ //FIXME: e->device = gdk_display_get_default ()->core_pointer;
e->x_root = e->x;
e->y_root = e->y;
}
G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
g_signal_connect_swapped (priv->tray_icon, "notify::padding",
G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
+ g_signal_connect_swapped (priv->tray_icon, "notify::icon-size",
+ G_CALLBACK (gtk_status_icon_icon_size_changed), status_icon);
g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
g_signal_connect (priv->tray_icon, "notify::error-color",
gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
gtk_widget_show (priv->image);
+ /* Force-initialize the symbolic colors */
+ g_object_notify (G_OBJECT (priv->tray_icon), "fg-color");
+ g_object_notify (G_OBJECT (priv->tray_icon), "error-color");
+ g_object_notify (G_OBJECT (priv->tray_icon), "warning-color");
+ g_object_notify (G_OBJECT (priv->tray_icon), "success-color");
+
g_signal_connect_swapped (priv->image, "size-allocate",
G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
priv->orientation = GTK_ORIENTATION_VERTICAL;
else
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+
+ priv->taskbar_top = abd.rc.top;
}
priv->last_click_x = priv->last_click_y = 0;
priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
priv->nid.uFlags = NIF_MESSAGE;
+ /* To help win7 identify the icon create it with an application "unique" tip */
+ if (g_get_prgname ())
+ {
+ WCHAR *wcs = g_utf8_to_utf16 (g_get_prgname (), -1, NULL, NULL, NULL);
+
+ priv->nid.uFlags |= NIF_TIP;
+ wcsncpy (priv->nid.szTip, wcs, G_N_ELEMENTS (priv->nid.szTip) - 1);
+ priv->nid.szTip[G_N_ELEMENTS (priv->nid.szTip) - 1] = 0;
+ g_free (wcs);
+ }
+
if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
{
g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
gtk_status_icon_orientation_changed, status_icon);
g_signal_handlers_disconnect_by_func (priv->tray_icon,
gtk_status_icon_padding_changed, status_icon);
+ g_signal_handlers_disconnect_by_func (priv->tray_icon,
+ gtk_status_icon_icon_size_changed, status_icon);
g_signal_handlers_disconnect_by_func (priv->tray_icon,
gtk_status_icon_fg_changed, status_icon);
g_signal_handlers_disconnect_by_func (priv->tray_icon,
/**
* gtk_status_icon_new_from_file:
- * @filename: a filename
+ * @filename: (type filename): a filename
*
* Creates a status icon displaying the file @filename.
*
#ifdef GDK_WINDOWING_WIN32
{
GdkPixbuf *pixbuf =
- gtk_widget_render_icon (priv->dummy_widget,
- priv->image_data.stock_id,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- NULL);
+ gtk_widget_render_icon_pixbuf (priv->dummy_widget,
+ priv->image_data.stock_id,
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
prev_hicon = priv->nid.hIcon;
priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
{
GdkPixbuf *pixbuf;
- pixbuf = gtk_widget_render_icon (priv->dummy_widget,
- priv->image_data.stock_id,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (priv->dummy_widget,
+ priv->image_data.stock_id,
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
QUARTZ_POOL_ALLOC;
[priv->status_item setImage:pixbuf];
QUARTZ_POOL_RELEASE;
padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
+ {
+ gtk_widget_set_margin_left (priv->image, padding);
+ gtk_widget_set_margin_right (priv->image, padding);
+ }
else
- gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
+ {
+ gtk_widget_set_margin_bottom (priv->image, padding);
+ gtk_widget_set_margin_top (priv->image, padding);
+ }
+}
+
+static void
+gtk_status_icon_icon_size_changed (GtkStatusIcon *status_icon)
+{
+ GtkStatusIconPrivate *priv = status_icon->priv;
+ gint icon_size;
+
+ icon_size = _gtk_tray_icon_get_icon_size (GTK_TRAY_ICON (priv->tray_icon));
+
+ if (icon_size != 0)
+ gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size);
+ else
+ gtk_image_set_pixel_size (GTK_IMAGE (priv->image), -1);
}
static void
gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
{
gtk_status_icon_padding_changed (status_icon);
+ gtk_status_icon_icon_size_changed (status_icon);
g_object_notify (G_OBJECT (status_icon), "embedded");
}
gtk_status_icon_fg_changed (GtkStatusIcon *status_icon)
{
GtkStatusIconPrivate *priv = status_icon->priv;
- GdkColor color;
+ GdkRGBA *rgba;
- g_object_get (priv->tray_icon, "fg-color", &color, NULL);
- gtk_widget_modify_fg (priv->image, GTK_STATE_NORMAL, &color);
+ g_object_get (priv->tray_icon, "fg-color", &rgba, NULL);
+
+ gtk_widget_override_color (priv->image, GTK_STATE_FLAG_NORMAL, rgba);
+
+ gdk_rgba_free (rgba);
}
static void
{
GtkStatusIconPrivate *priv = status_icon->priv;
const gchar *name;
- GdkColor color;
switch (pspec->name[0])
{
if (name)
{
- g_object_get (priv->tray_icon, pspec->name, &color, NULL);
- gtk_widget_modify_symbolic_color (priv->image, name, &color);
+ GdkRGBA rgba;
+
+ g_object_get (priv->tray_icon, pspec->name, &rgba, NULL);
+
+ rgba.alpha = 1;
+
+ gtk_widget_override_symbolic_color (priv->image, name, &rgba);
}
}
if (handled)
return TRUE;
- if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
- emit_activate_signal (status_icon);
+ emit_popup_menu_signal (status_icon, event->button, event->time);
return TRUE;
}
- else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+ else if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
{
- emit_popup_menu_signal (status_icon, event->button, event->time);
+ emit_activate_signal (status_icon);
return TRUE;
}
/**
* gtk_status_icon_set_from_file:
* @status_icon: a #GtkStatusIcon
- * @filename: a filename
+ * @filename: (type filename): a filename
*
* Makes @status_icon display the file @filename.
* See gtk_status_icon_new_from_file() for details.
*
* Since: 2.10
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_status_icon_get_stock (GtkStatusIcon *status_icon)
{
GtkStatusIconPrivate *priv;
*
* Since: 2.10
**/
-G_CONST_RETURN gchar *
+const gchar *
gtk_status_icon_get_icon_name (GtkStatusIcon *status_icon)
{
GtkStatusIconPrivate *priv;
/**
* gtk_status_icon_position_menu:
* @menu: the #GtkMenu
- * @x: return location for the x position
- * @y: return location for the y position
- * @push_in: whether the first menu item should be offset (pushed in) to be
- * aligned with the menu popup position (only useful for GtkOptionMenu).
- * @user_data: the status icon to position the menu on
+ * @x: (out): return location for the x position
+ * @y: (out): return location for the y position
+ * @push_in: (out): whether the first menu item should be offset
+ * (pushed in) to be aligned with the menu popup position
+ * (only useful for GtkOptionMenu).
+ * @user_data: (type GtkStatusIcon): the status icon to position the menu on
*
* Menu positioning function to use with gtk_menu_popup()
* to position @menu aligned to the status icon @user_data.
#ifdef GDK_WINDOWING_WIN32
GtkStatusIcon *status_icon;
GtkStatusIconPrivate *priv;
+ GtkRequisition menu_req;
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
status_icon = GTK_STATUS_ICON (user_data);
priv = status_icon->priv;
+ gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
+
*x = priv->last_click_x;
- *y = priv->last_click_y;
+ *y = priv->taskbar_top - menu_req.height;
+
*push_in = TRUE;
#endif
}
/**
* gtk_status_icon_get_geometry:
* @status_icon: a #GtkStatusIcon
- * @screen: (out) (transfer none) (allow-none): return location for the screen, or %NULL if the
- * information is not needed
- * @area: (out) (allow-none): return location for the area occupied by the status
- * icon, or %NULL
- * @orientation: (out) (allow-none): return location for the orientation of the panel
- * in which the status icon is embedded, or %NULL. A panel
- * at the top or bottom of the screen is horizontal, a panel
- * at the left or right is vertical.
+ * @screen: (out) (transfer none) (allow-none): return location for
+ * the screen, or %NULL if the information is not needed
+ * @area: (out) (allow-none): return location for the area occupied by
+ * the status icon, or %NULL
+ * @orientation: (out) (allow-none): return location for the
+ * orientation of the panel in which the status icon is embedded,
+ * or %NULL. A panel at the top or bottom of the screen is
+ * horizontal, a panel at the left or right is vertical.
*
* Obtains information about the location of the status icon
* on screen. This information can be used to e.g. position
*
* Since: 2.18
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_status_icon_get_title (GtkStatusIcon *status_icon)
{
GtkStatusIconPrivate *priv;
priv = status_icon->priv;
#ifdef GDK_WINDOWING_X11
- gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
+ if (gtk_widget_get_realized (priv->tray_icon))
+ {
+ /* gtk_window_set_wmclass() only operates on non-realized windows,
+ * so temporarily unrealize the tray here
+ */
+ gtk_widget_hide (priv->tray_icon);
+ gtk_widget_unrealize (priv->tray_icon);
+ gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
+ gtk_widget_show (priv->tray_icon);
+ }
+ else
+ gtk_window_set_wmclass (GTK_WINDOW (priv->tray_icon), name, name);
#endif
-
- g_object_notify (G_OBJECT (status_icon), "name");
}