]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkstatusicon.c
Bug 131920 – gtkNotebook sends incorrect switch_page value
[~andy/gtk] / gtk / gtkstatusicon.c
index 5355183f915c55a78ebb57f657d887f0a76821f2..4e8a008dd3b140c66dd018d008adf7bf697a9206 100755 (executable)
 
 #include "gtkintl.h"
 #include "gtkiconfactory.h"
+#include "gtkmain.h"
 #include "gtkmarshalers.h"
-#include "gtktooltips.h"
 #include "gtktrayicon.h"
 
 #include "gtkprivate.h"
 #include "gtkwidget.h"
 
+#ifdef GDK_WINDOWING_X11
+#include "gdk/x11/gdkx.h"
+#endif
+
 #ifdef GDK_WINDOWING_WIN32
 #include "gtkicontheme.h"
 #include "gtklabel.h"
@@ -54,6 +58,8 @@
 #include "gtklabel.h"
 #endif 
 
+#include "gdkkeysyms.h"
+
 #include "gtkalias.h"
 
 #define BLINK_TIMEOUT 500
@@ -93,7 +99,6 @@ struct _GtkStatusIconPrivate
 #ifdef GDK_WINDOWING_X11
   GtkWidget    *tray_icon;
   GtkWidget    *image;
-  GtkTooltips  *tooltips;
 #endif
 
 #ifdef GDK_WINDOWING_WIN32
@@ -151,12 +156,15 @@ static void     gtk_status_icon_screen_changed   (GtkStatusIcon  *status_icon,
 static void     gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
 static void     gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
 
+static gboolean gtk_status_icon_key_press        (GtkStatusIcon  *status_icon,
+                                                 GdkEventKey    *event);
+static void     gtk_status_icon_popup_menu       (GtkStatusIcon  *status_icon);
 #endif
 static gboolean gtk_status_icon_button_press     (GtkStatusIcon  *status_icon,
                                                  GdkEventButton *event);
 static void     gtk_status_icon_disable_blinking (GtkStatusIcon  *status_icon);
 static void     gtk_status_icon_reset_image_data (GtkStatusIcon  *status_icon);
-                                          
+static void     gtk_status_icon_update_image    (GtkStatusIcon *status_icon);
 
 G_DEFINE_TYPE (GtkStatusIcon, gtk_status_icon, G_TYPE_OBJECT)
 
@@ -402,12 +410,41 @@ button_callback (gpointer data)
   return FALSE;
 }
 
+static UINT taskbar_created_msg = 0;
+static GSList *status_icons = NULL;
+
 static LRESULT CALLBACK
 wndproc (HWND   hwnd,
         UINT   message,
         WPARAM wparam,
         LPARAM lparam)
 {
+  if (message == taskbar_created_msg)
+    {
+      GSList *rover;
+
+      for (rover = status_icons; rover != NULL; rover = rover->next)
+       {
+         GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
+         GtkStatusIconPrivate *priv = status_icon->priv;
+
+         priv->nid.hWnd = hwnd;
+         priv->nid.uID = GPOINTER_TO_UINT (status_icon);
+         priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
+         priv->nid.uFlags = NIF_MESSAGE;
+
+         if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
+           {
+             g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
+             priv->nid.hWnd = NULL;
+             continue;
+           }
+
+         gtk_status_icon_update_image (status_icon);
+       }
+      return 0;
+    }
+
   if (message == WM_GTK_TRAY_NOTIFICATION)
     {
       ButtonCallbackData *bc;
@@ -444,6 +481,8 @@ create_tray_observer (void)
   if (hwnd)
     return hwnd;
 
+  taskbar_created_msg = RegisterWindowMessage("TaskbarCreated");
+
   memset (&wclass, 0, sizeof(WNDCLASS));
   wclass.lpszClassName = "gtkstatusicon-observer";
   wclass.lpfnWndProc   = wndproc;
@@ -453,7 +492,7 @@ create_tray_observer (void)
   if (!klass)
     return NULL;
 
-  hwnd = CreateWindow (MAKEINTRESOURCE(klass),
+  hwnd = CreateWindow (MAKEINTRESOURCE (klass),
                        NULL, WS_POPUP,
                        0, 0, 1, 1, NULL, NULL,
                        hmodule, NULL);
@@ -490,6 +529,10 @@ gtk_status_icon_init (GtkStatusIcon *status_icon)
   gtk_widget_add_events (GTK_WIDGET (priv->tray_icon),
                         GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
 
+  g_signal_connect_swapped (priv->tray_icon, "key-press-event",
+                           G_CALLBACK (gtk_status_icon_key_press), status_icon);
+  g_signal_connect_swapped (priv->tray_icon, "popup-menu",
+                           G_CALLBACK (gtk_status_icon_popup_menu), status_icon);
   g_signal_connect_swapped (priv->tray_icon, "notify::embedded",
                            G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
   g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
@@ -499,14 +542,13 @@ gtk_status_icon_init (GtkStatusIcon *status_icon)
   g_signal_connect_swapped (priv->tray_icon, "screen-changed",
                            G_CALLBACK (gtk_status_icon_screen_changed), status_icon);
   priv->image = gtk_image_new ();
+  GTK_WIDGET_SET_FLAGS (priv->image, GTK_CAN_FOCUS);
   gtk_container_add (GTK_CONTAINER (priv->tray_icon), priv->image);
   gtk_widget_show (priv->image);
 
   g_signal_connect_swapped (priv->image, "size-allocate",
                            G_CALLBACK (gtk_status_icon_size_allocate), status_icon);
 
-  status_icon->priv->tooltips = gtk_tooltips_new ();
-  g_object_ref_sink (priv->tooltips);
 #endif
 
 #ifdef GDK_WINDOWING_WIN32
@@ -544,6 +586,9 @@ gtk_status_icon_init (GtkStatusIcon *status_icon)
       g_warning ("%s:%d:Shell_NotifyIcon(NIM_ADD) failed", __FILE__, __LINE__-2);
       priv->nid.hWnd = NULL;
     }
+
+  status_icons = g_slist_append (status_icons, status_icon);
+
 #endif
        
 #ifdef GDK_WINDOWING_QUARTZ
@@ -567,9 +612,11 @@ gtk_status_icon_constructor (GType                  type,
                              GObjectConstructParam *construct_params)
 {
   GObject *object;
+#ifdef GDK_WINDOWING_X11
   GtkStatusIcon *status_icon;
   GtkStatusIconPrivate *priv;
-  
+#endif
+
   object = G_OBJECT_CLASS (gtk_status_icon_parent_class)->constructor (type,
                                                                        n_construct_properties,
                                                                        construct_params);
@@ -600,10 +647,6 @@ gtk_status_icon_finalize (GObject *object)
   priv->blank_icon = NULL;
 
 #ifdef GDK_WINDOWING_X11
-  if (priv->tooltips)
-    g_object_unref (priv->tooltips);
-  priv->tooltips = NULL;
-
   gtk_widget_destroy (priv->tray_icon);
 #endif
 
@@ -614,6 +657,8 @@ gtk_status_icon_finalize (GObject *object)
     DestroyIcon (priv->nid.hIcon);
 
   gtk_widget_destroy (priv->dummy_widget);
+
+  status_icons = g_slist_remove (status_icons, status_icon);
 #endif
        
 #ifdef GDK_WINDOWING_QUARTZ
@@ -1206,6 +1251,34 @@ gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
   g_object_notify (G_OBJECT (status_icon), "orientation");
 }
 
+static gboolean
+gtk_status_icon_key_press (GtkStatusIcon  *status_icon,
+                          GdkEventKey    *event)
+{
+  guint state, keyval;
+
+  state = event->state & gtk_accelerator_get_default_mod_mask ();
+  keyval = event->keyval;
+  if (state == 0 &&
+      (keyval == GDK_Return ||
+       keyval == GDK_KP_Enter ||
+       keyval == GDK_ISO_Enter ||
+       keyval == GDK_space ||
+       keyval == GDK_KP_Space))
+    {
+      emit_activate_signal (status_icon);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+gtk_status_icon_popup_menu (GtkStatusIcon  *status_icon)
+{
+  emit_popup_menu_signal (status_icon, 0, gtk_get_current_event_time ());
+}
+
 #endif
 
 static gboolean
@@ -1601,8 +1674,9 @@ gtk_status_icon_set_tooltip (GtkStatusIcon *status_icon,
   priv = status_icon->priv;
 
 #ifdef GDK_WINDOWING_X11
-  gtk_tooltips_set_tip (priv->tooltips, priv->tray_icon,
-                       tooltip_text, NULL);
+
+  gtk_widget_set_tooltip_text (priv->tray_icon, tooltip_text);
+
 #endif
 #ifdef GDK_WINDOWING_WIN32
   if (tooltip_text == NULL)
@@ -1698,10 +1772,11 @@ gtk_status_icon_set_visible (GtkStatusIcon *status_icon,
 #ifdef GDK_WINDOWING_X11
       if (visible)
        gtk_widget_show (priv->tray_icon);
-      else if (GTK_WIDGET_REALIZED (priv->tray_icon)) {
-       gtk_widget_hide (priv->tray_icon);
-       gtk_widget_unrealize (priv->tray_icon);
-      }
+      else if (GTK_WIDGET_REALIZED (priv->tray_icon)) 
+        {
+         gtk_widget_hide (priv->tray_icon);
+         gtk_widget_unrealize (priv->tray_icon);
+        }
 #endif
 #ifdef GDK_WINDOWING_WIN32
       if (priv->nid.hWnd != NULL)
@@ -2024,6 +2099,36 @@ gtk_status_icon_get_geometry (GtkStatusIcon    *status_icon,
 #endif /* GDK_WINDOWING_X11 */
 }
 
+/**
+ * gtk_status_icon_get_x11_window_id:
+ * @status_icon: a #GtkStatusIcon
+ *
+ * This function is only useful on the X11/freedesktop.org platform.
+ * It returns a window ID for the widget in the underlying
+ * status icon implementation.  This is useful for the Galago 
+ * notification service, which can send a window ID in the protocol 
+ * in order for the server to position notification windows 
+ * pointing to a status icon reliably.
+ *
+ * This function is not intended for other use cases which are
+ * more likely to be met by one of the non-X11 specific methods, such
+ * as gtk_status_icon_position_menu().
+ *
+ * Return value: An 32 bit unsigned integer identifier for the 
+ * underlying X11 Window
+ *
+ * Since: 2.14
+ */
+guint32
+gtk_status_icon_get_x11_window_id (GtkStatusIcon *status_icon)
+{
+#ifdef GDK_WINDOWING_X11
+  gtk_widget_realize (GTK_WIDGET (status_icon->priv->tray_icon));
+  return GDK_WINDOW_XID (GTK_WIDGET (status_icon->priv->tray_icon)->window);
+#else
+  return 0;
+#endif
+}
 
 #define __GTK_STATUS_ICON_C__
 #include "gtkaliasdef.c"