Bug 1409493 - Load actual CSD config from Gtk+, r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Tue, 17 Oct 2017 21:19:48 +0200
changeset 684641 69b6fd8d278a4b2e2587d078fe7cda43a3a6da3a
parent 684640 afee4042d8dcd843c8c3c3e8a065f7734e4d1451
child 736928 560b342b5a3e2a77e5673d622c76a102cb9deeb1
push id85685
push userstransky@redhat.com
push dateMon, 23 Oct 2017 10:25:43 +0000
reviewersjhorak
bugs1409493
milestone58.0a1
Bug 1409493 - Load actual CSD config from Gtk+, r?jhorak MozReview-Commit-ID: GVHGXEk4IN
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1056,16 +1056,44 @@ nsLookAndFeel::EnsureInit()
                          "cursor-aspect-ratio", &sCaretRatio,
                          nullptr);
 
     GetSystemFontInfo(gtk_widget_get_style_context(entry),
                       &mFieldFontName, &mFieldFontStyle);
 
     gtk_widget_destroy(window);
     g_object_unref(labelWidget);
+
+    // Require GTK 3.20 for client-side decoration support.
+    sCSDAvailable = gtk_check_version(3, 20, 0) == nullptr;
+    if (sCSDAvailable) {
+        sCSDAvailable =
+            mozilla::Preferences::GetBool("widget.allow-client-side-decoration",
+                                          false);
+    }
+
+    if (sCSDAvailable) {
+        static auto sGtkHeaderBarGetDecorationLayoutPtr =
+          (const gchar* (*)(GtkWidget*))
+          dlsym(RTLD_DEFAULT, "gtk_header_bar_get_decoration_layout");
+
+        GtkWidget* headerBar = GetWidget(MOZ_GTK_HEADER_BAR);
+        const gchar* decorationLayout =
+            sGtkHeaderBarGetDecorationLayoutPtr(headerBar);
+        if (!decorationLayout) {
+            g_object_get(settings, "gtk-decoration-layout", &decorationLayout,
+                         nullptr);
+        }
+
+        if (decorationLayout) {
+            sCSDCloseButton = (strstr(decorationLayout, "close") != nullptr);
+            sCSDMaximizeButton = (strstr(decorationLayout, "maximize") != nullptr);
+            sCSDMinimizeButton = (strstr(decorationLayout, "minimize") != nullptr);
+        }
+    }
 }
 
 // virtual
 char16_t
 nsLookAndFeel::GetPasswordCharacterImpl()
 {
     EnsureInit();
     return sInvisibleCharacter;
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -27,16 +27,18 @@ public:
     virtual bool GetFontImpl(FontID aID, nsString& aFontName,
                              gfxFontStyle& aFontStyle,
                              float aDevPixPerCSSPixel);
 
     virtual void RefreshImpl();
     virtual char16_t GetPasswordCharacterImpl();
     virtual bool GetEchoPasswordImpl();
 
+    bool IsCSDAvailable() const { return sCSDAvailable; }
+
 protected:
 
     // Cached fonts
     bool mDefaultFontCached;
     bool mButtonFontCached;
     bool mFieldFontCached;
     bool mMenuFontCached;
     nsString mDefaultFontName;