Blame 0001-rhbz-1392145-ensure-titlebar-close-button-matches-ou.patch

8d30234
From af8675040370ab7911fe9045fe546338abee20d2 Mon Sep 17 00:00:00 2001
8d30234
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
8d30234
Date: Fri, 16 Mar 2018 16:50:42 +0000
8d30234
Subject: [PATCH] rhbz#1392145 ensure titlebar close button matches 'outside'
8d30234
 direction
8d30234
8d30234
Change-Id: I20e925c58adb56acd4d1a63720d330c8b6613441
8d30234
---
8d30234
 vcl/inc/unx/gtk/gtkframe.hxx  |  1 +
8d30234
 vcl/source/app/svmain.cxx     |  3 ++-
8d30234
 vcl/unx/gtk3/gtk3gtkframe.cxx | 32 +++++++++++++++++++++++++++++++-
8d30234
 3 files changed, 34 insertions(+), 2 deletions(-)
8d30234
8d30234
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
8d30234
index 0c9b002cb264..bf0ade47db2a 100644
8d30234
--- a/vcl/inc/unx/gtk/gtkframe.hxx
8d30234
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
8d30234
@@ -173,6 +173,7 @@ class GtkSalFrame : public SalFrame
8d30234
     SalX11Screen                    m_nXScreen;
8d30234
     GtkWidget*                      m_pWindow;
8d30234
 #if GTK_CHECK_VERSION(3,0,0)
8d30234
+    GtkHeaderBar*                   m_pHeaderBar;
8d30234
     GtkGrid*                        m_pTopLevelGrid;
8d30234
 #endif
8d30234
     GtkEventBox*                    m_pEventBox;
8d30234
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
8d30234
index 8f546feb5f78..63931e8f23b2 100644
8d30234
--- a/vcl/source/app/svmain.cxx
8d30234
+++ b/vcl/source/app/svmain.cxx
8d30234
@@ -31,7 +31,7 @@
8d30234
 
8d30234
 #include <comphelper/processfactory.hxx>
8d30234
 #include <comphelper/asyncnotification.hxx>
8d30234
-
8d30234
+#include <i18nlangtag/mslangid.hxx>
8d30234
 #include <unotools/syslocaleoptions.hxx>
8d30234
 #include <vcl/svapp.hxx>
8d30234
 #include <vcl/vclmain.hxx>
8d30234
@@ -335,6 +335,7 @@ bool InitVCL()
8d30234
         OUString aLocaleString(SvtSysLocaleOptions().GetRealUILanguageTag().getGlibcLocaleString(".UTF-8"));
8d30234
         if (!aLocaleString.isEmpty())
8d30234
         {
8d30234
+            MsLangId::getSystemUILanguage(); //call this now to pin what the system UI really was
8d30234
             OUString envVar("LANGUAGE");
8d30234
             osl_setEnvironment(envVar.pData, aLocaleString.pData);
8d30234
         }
8d30234
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
8d30234
index 27a65caa3612..c8c98f5c5255 100644
8d30234
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
8d30234
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
8d30234
@@ -74,6 +74,8 @@
8d30234
 #  include <cstdio>
8d30234
 #endif
8d30234
 
8d30234
+#include <i18nlangtag/mslangid.hxx>
8d30234
+
8d30234
 #include <cstdlib>
8d30234
 #include <cmath>
8d30234
 
8d30234
@@ -477,6 +479,7 @@ bool GtkSalFrame::doKeyCallback( guint state,
8d30234
 
8d30234
 GtkSalFrame::GtkSalFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
8d30234
     : m_nXScreen( getDisplay()->GetDefaultXScreen() )
8d30234
+    , m_pHeaderBar(nullptr)
8d30234
     , m_pGraphics(nullptr)
8d30234
     , m_bGraphics(false)
8d30234
 {
8d30234
@@ -489,6 +492,7 @@ GtkSalFrame::GtkSalFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
8d30234
 
8d30234
 GtkSalFrame::GtkSalFrame( SystemParentData* pSysData )
8d30234
     : m_nXScreen( getDisplay()->GetDefaultXScreen() )
8d30234
+    , m_pHeaderBar(nullptr)
8d30234
     , m_pGraphics(nullptr)
8d30234
     , m_bGraphics(false)
8d30234
 {
8d30234
@@ -1241,6 +1245,27 @@ void GtkSalFrame::Init( SalFrame* pParent, SalFrameStyleFlags nStyle )
8d30234
         gtk_window_set_type_hint( GTK_WINDOW(m_pWindow), eType );
8d30234
         gtk_window_set_gravity( GTK_WINDOW(m_pWindow), GDK_GRAVITY_STATIC );
8d30234
         gtk_window_set_resizable( GTK_WINDOW(m_pWindow), bool(nStyle & SalFrameStyleFlags::SIZEABLE) );
8d30234
+
8d30234
+#if defined(GDK_WINDOWING_WAYLAND)
8d30234
+        //rhbz#1392145 under wayland/csd if we've overridden the default widget direction in order to set LibreOffice's
8d30234
+        //UI to the configured ui language but the system ui locale is a different text direction, then the toplevel
8d30234
+        //built-in close button of the titlebar follows the overridden direction rather than continue in the same
8d30234
+        //direction as every other titlebar on the user's desktop. So if they don't match set an explicit
8d30234
+        //header bar with the desired 'outside' direction
8d30234
+        if ((eType == GDK_WINDOW_TYPE_HINT_NORMAL || eType == GDK_WINDOW_TYPE_HINT_DIALOG) && GDK_IS_WAYLAND_DISPLAY(GtkSalFrame::getGdkDisplay()))
8d30234
+        {
8d30234
+            const bool bDesktopIsRTL = MsLangId::isRightToLeft(MsLangId::getSystemUILanguage());
8d30234
+            const bool bAppIsRTL = gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL;
8d30234
+            if (bDesktopIsRTL != bAppIsRTL)
8d30234
+            {
8d30234
+                m_pHeaderBar = GTK_HEADER_BAR(gtk_header_bar_new());
8d30234
+                gtk_widget_set_direction(GTK_WIDGET(m_pHeaderBar), bDesktopIsRTL ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
8d30234
+                gtk_header_bar_set_show_close_button(m_pHeaderBar, true);
8d30234
+                gtk_window_set_titlebar(GTK_WINDOW(m_pWindow), GTK_WIDGET(m_pHeaderBar));
8d30234
+                gtk_widget_show(GTK_WIDGET(m_pHeaderBar));
8d30234
+            }
8d30234
+        }
8d30234
+#endif
8d30234
     }
8d30234
     else if( nStyle & SalFrameStyleFlags::FLOAT )
8d30234
         gtk_window_set_type_hint( GTK_WINDOW(m_pWindow), GDK_WINDOW_TYPE_HINT_POPUP_MENU );
8d30234
@@ -1332,7 +1357,12 @@ void GtkSalFrame::SetTitle( const OUString& rTitle )
8d30234
 {
8d30234
     m_aTitle = rTitle;
8d30234
     if( m_pWindow && ! isChild() )
8d30234
-        gtk_window_set_title( GTK_WINDOW(m_pWindow), OUStringToOString( rTitle, RTL_TEXTENCODING_UTF8 ).getStr() );
8d30234
+    {
8d30234
+        OString sTitle(OUStringToOString(rTitle, RTL_TEXTENCODING_UTF8));
8d30234
+        gtk_window_set_title(GTK_WINDOW(m_pWindow), sTitle.getStr());
8d30234
+        if (m_pHeaderBar)
8d30234
+            gtk_header_bar_set_title(m_pHeaderBar, sTitle.getStr());
8d30234
+    }
8d30234
 }
8d30234
 
8d30234
 void GtkSalFrame::SetIcon( sal_uInt16 nIcon )
8d30234
-- 
8d30234
2.14.3
8d30234