Blame SOURCES/0001-use-gdk_wayland_window_set_application_id-when-it-be.patch

2654e0
From f1cace2cd06b20fc1431f15892a4293fa3601b39 Mon Sep 17 00:00:00 2001
2654e0
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
2654e0
Date: Wed, 8 Jul 2020 10:13:26 +0100
2654e0
Subject: [PATCH] use gdk_wayland_window_set_application_id when it becomes
2654e0
 available
2654e0
MIME-Version: 1.0
2654e0
Content-Type: text/plain; charset=UTF-8
2654e0
Content-Transfer-Encoding: 8bit
2654e0
2654e0
Change-Id: I60775dcbfbc396f195a71f219668944d0bfecf31
2654e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98325
2654e0
Tested-by: Caolán McNamara <caolanm@redhat.com>
2654e0
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2654e0
(cherry picked from commit 2d8e2813ddc87f7ce03b97e4d603df11613461f0)
2654e0
2654e0
gdk_wayland_window_set_application_id doesn't work when called early
2654e0
2654e0
after mapped it definitely works
2654e0
2654e0
Change-Id: Ide0fa636ee26acea0d938aef08532b9396fe901a
2654e0
---
2654e0
 vcl/inc/unx/gtk/gtkframe.hxx  |  3 +++
2654e0
 vcl/unx/gtk3/gtk3gtkframe.cxx | 49 +++++++++++++++++++++++++++++------
2654e0
 2 files changed, 44 insertions(+), 8 deletions(-)
2654e0
2654e0
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
2654e0
index ccf9064..49b6937 100644
2654e0
--- a/vcl/inc/unx/gtk/gtkframe.hxx
2654e0
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
2654e0
@@ -206,6 +206,7 @@ class GtkSalFrame : public SalFrame
2654e0
     GtkDropTarget*                  m_pDropTarget;
2654e0
     GtkDragSource*                  m_pDragSource;
2654e0
     bool                            m_bGeometryIsProvisional;
2654e0
+    bool                            m_bIconSetWhileUnmapped;
2654e0
 
2654e0
     GtkSalMenu*                     m_pSalMenu;
2654e0
 
2654e0
@@ -315,6 +316,8 @@ class GtkSalFrame : public SalFrame
2654e0
 
2654e0
     void SetScreen( unsigned int nNewScreen, SetType eType, tools::Rectangle const *pSize = nullptr );
2654e0
 
2654e0
+    void SetIcon(const char* pIcon);
2654e0
+
2654e0
 public:
2654e0
     cairo_surface_t*                m_pSurface;
2654e0
     basegfx::B2IVector              m_aFrameSize;
2654e0
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
2654e0
index 786aa40..624c75a 100644
2654e0
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
2654e0
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
2654e0
@@ -55,6 +55,7 @@
2654e0
 
2654e0
 #include <cstdlib>
2654e0
 #include <cmath>
2654e0
+#include <dlfcn.h>
2654e0
 
2654e0
 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
2654e0
 #include <com/sun/star/awt/MouseButton.hpp>
2654e0
@@ -922,6 +923,7 @@ void GtkSalFrame::InitCommon()
2654e0
     m_pDropTarget       = nullptr;
2654e0
     m_pDragSource       = nullptr;
2654e0
     m_bGeometryIsProvisional = false;
2654e0
+    m_bIconSetWhileUnmapped = false;
2654e0
     m_ePointerStyle     = static_cast<PointerStyle>(0xffff);
2654e0
     m_pSalMenu          = nullptr;
2654e0
     m_nWatcherId        = 0;
2654e0
@@ -1217,6 +1219,28 @@ void GtkSalFrame::SetTitle( const OUString& rTitle )
2654e0
     }
2654e0
 }
2654e0
 
2654e0
+void GtkSalFrame::SetIcon(const char* appicon)
2654e0
+{
2654e0
+    gtk_window_set_icon_name(GTK_WINDOW(m_pWindow), appicon);
2654e0
+
2654e0
+#if defined(GDK_WINDOWING_WAYLAND)
2654e0
+    if (DLSYM_GDK_IS_WAYLAND_DISPLAY(getGdkDisplay()))
2654e0
+    {
2654e0
+        static auto set_application_id = reinterpret_cast<void (*) (GdkWindow*, const char*)>(
2654e0
+                                             dlsym(nullptr, "gdk_wayland_window_set_application_id"));
2654e0
+        if (set_application_id)
2654e0
+        {
2654e0
+            GdkWindow* gdkWindow = gtk_widget_get_window(m_pWindow);
2654e0
+            set_application_id(gdkWindow, appicon);
2654e0
+
2654e0
+            // gdk_wayland_window_set_application_id doesn't seem to work before
2654e0
+            // the window is mapped, so set this for real when/if we are mapped
2654e0
+            m_bIconSetWhileUnmapped = !gtk_widget_get_mapped(m_pWindow);
2654e0
+        }
2654e0
+    }
2654e0
+#endif
2654e0
+}
2654e0
+
2654e0
 void GtkSalFrame::SetIcon( sal_uInt16 nIcon )
2654e0
 {
2654e0
     if( (m_nStyle & (SalFrameStyleFlags::PLUG|SalFrameStyleFlags::SYSTEMCHILD|SalFrameStyleFlags::FLOAT|SalFrameStyleFlags::INTRO|SalFrameStyleFlags::OWNERDRAWDECORATION))
2654e0
@@ -1240,7 +1264,8 @@ void GtkSalFrame::SetIcon( sal_uInt16 nIcon )
2654e0
     else
2654e0
         appicon = g_strdup ("libreoffice-startcenter");
2654e0
 
2654e0
-    gtk_window_set_icon_name (GTK_WINDOW (m_pWindow), appicon);
2654e0
+    SetIcon(appicon);
2654e0
+
2654e0
     g_free (appicon);
2654e0
 }
2654e0
 
2654e0
@@ -1309,13 +1334,18 @@ void GtkSalFrame::Show( bool bVisible, bool /*bNoActivate*/ )
2654e0
             }
2654e0
 
2654e0
 #if defined(GDK_WINDOWING_WAYLAND)
2654e0
-            //rhbz#1334915, gnome#779143, tdf#100158
2654e0
-            //gtk under wayland lacks a way to change the app_id
2654e0
-            //of a window, so brute force everything as a
2654e0
-            //startcenter when initially shown to at least get
2654e0
-            //the default LibreOffice icon and not the broken
2654e0
-            //app icon
2654e0
-            if (DLSYM_GDK_IS_WAYLAND_DISPLAY(getGdkDisplay()))
2654e0
+            /*
2654e0
+             rhbz#1334915, gnome#779143, tdf#100158
2654e0
+             https://gitlab.gnome.org/GNOME/gtk/-/issues/767
2654e0
+
2654e0
+             before gdk_wayland_window_set_application_id was available gtk
2654e0
+             under wayland lacked a way to change the app_id of a window, so
2654e0
+             brute force everything as a startcenter when initially shown to at
2654e0
+             least get the default LibreOffice icon and not the broken app icon
2654e0
+            */
2654e0
+            static bool bAppIdImmutable = DLSYM_GDK_IS_WAYLAND_DISPLAY(getGdkDisplay()) &&
2654e0
+                                          !dlsym(nullptr, "gdk_wayland_window_set_application_id");
2654e0
+            if (bAppIdImmutable)
2654e0
             {
2654e0
                 OString sOrigName(g_get_prgname());
2654e0
                 g_set_prgname("libreoffice-startcenter");
2654e0
@@ -3039,6 +3069,9 @@ gboolean GtkSalFrame::signalMap(GtkWidget *, GdkEvent*, gpointer frame)
2654e0
 {
2654e0
     GtkSalFrame* pThis = static_cast<GtkSalFrame*>(frame);
2654e0
 
2654e0
+    if (pThis->m_bIconSetWhileUnmapped)
2654e0
+        pThis->SetIcon(gtk_window_get_icon_name(GTK_WINDOW(pThis->m_pWindow)));
2654e0
+
2654e0
     pThis->CallCallbackExc( SalEvent::Resize, nullptr );
2654e0
     pThis->TriggerPaintEvent();
2654e0
 
2654e0
-- 
2654e0
2.26.2
2654e0