[gtk/gtk-3-24: 1/2] GtkStatusIcon/w32: Also set the tooltip on taskbar_created_msg



commit 6dc2f6f026dfebe746e44e4f0b27049ff747ea3c
Author: Luca Bacci <luca bacci982 gmail com>
Date:   Fri Aug 2 16:58:25 2019 +0000

    GtkStatusIcon/w32: Also set the tooltip on taskbar_created_msg
    
    When explorer.exe creates a taskbar it broadcasts a "TaskbarCreated"
    message to all toplevels. Applications, By handling that message,
    are able to re-create the icons to be displayed in the taskbar.
    
    Explorer creates a new taskbar in two circumstances:
    A) when explorer starts up
    B) when the DPI of the monitor changes
    
    A) happens either when explorer.exe is started for the first time at
       logon, or when it is restarted after being terminated.
    B) happens when the user changes the DPI preference of the active
       monitor where the desktop is displayed, or if the desktop is moved
       to a monitor with different DPI.
    
    Currently, this message is handled in Gtk and icons are re-created.
    However the current implementation has a small issue in that it
    doesn't set the tooltip on the new icons, so tooltips get lost
    after re-creation.
    
    The tooltip is important because Windows uses it for identification
    of taskbar icons and for storing and applying user preferences. For
    an explanation of that see:
    https://bugzilla.gnome.org/show_bug.cgi?id=609622
    
    With this commit the tooltip is correctly applied to new taskbar
    icons when handling taskbar_created_msg.
    
    See Merge Request !1003

 gtk/deprecated/gtkstatusicon.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
---
diff --git a/gtk/deprecated/gtkstatusicon.c b/gtk/deprecated/gtkstatusicon.c
index c872da7a85..c9923d5261 100644
--- a/gtk/deprecated/gtkstatusicon.c
+++ b/gtk/deprecated/gtkstatusicon.c
@@ -735,25 +735,25 @@ wndproc (HWND   hwnd,
          GtkStatusIcon *status_icon = GTK_STATUS_ICON (rover->data);
          GtkStatusIconPrivate *priv = status_icon->priv;
 
-         /* taskbar_created_msg is also fired when DPI changes. Try to delete existing icons if possible. */
-         if (!Shell_NotifyIconW (NIM_DELETE, &priv->nid))
-         {
-               g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_DELETE) on existing icon failed");
-         }
-
-         priv->nid.hWnd = hwnd;
-         priv->nid.uID = status_icon_id++;
-         priv->nid.uCallbackMessage = WM_GTK_TRAY_NOTIFICATION;
-         priv->nid.uFlags = NIF_MESSAGE;
-
-         if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
-           {
-             g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
-             priv->nid.hWnd = NULL;
-             continue;
-           }
-
-         gtk_status_icon_update_image (status_icon);
+          if (priv->visible)
+            {
+              /* taskbar_created_msg is also fired when DPI changes. Try to delete existing icons if 
possible. */
+              if (priv->nid.hWnd)
+                if (!Shell_NotifyIconW (NIM_DELETE, &priv->nid))
+                  g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_DELETE) on existing icon failed");
+
+              priv->nid.hWnd = hwnd;
+              priv->nid.uFlags &= ~NIF_ICON;
+
+              if (!Shell_NotifyIconW (NIM_ADD, &priv->nid))
+                {
+                  g_warning (G_STRLOC ": Shell_NotifyIcon(NIM_ADD) failed");
+                  priv->nid.hWnd = NULL;
+                  continue;
+                }
+
+              gtk_status_icon_update_image (status_icon);
+            }
        }
       return 0;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]