92c277c
From 0388ce8e25535415d9bdd79ce14eb20e73859279 Mon Sep 17 00:00:00 2001
92c277c
From: Paul Cornett <paulcor@users.noreply.github.com>
92c277c
Date: Sat, 6 Feb 2016 16:07:28 -0800
92c277c
Subject: [PATCH] Allow SetClientSize() to set correct size even when size of
92c277c
 window decorations is not known
92c277c
92c277c
This should allow correct sizing of first TLW (when using SetClientSize())
92c277c
with backends using client-side decorations such as Wayland.
92c277c
92c277c
(cherry picked from commit bc4df78421a5b1e6fd9b218e89d03e59bd846d0a)
92c277c
---
92c277c
 src/gtk/toplevel.cpp | 27 +++++++++++++++++++++++++++
92c277c
 1 file changed, 27 insertions(+)
92c277c
92c277c
diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp
92c277c
index c3d42e8..a52dad0 100644
92c277c
--- a/src/gtk/toplevel.cpp
92c277c
+++ b/src/gtk/toplevel.cpp
92c277c
@@ -1194,6 +1194,14 @@ void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int si
92c277c
     }
92c277c
 }
92c277c
 
92c277c
+extern "C" {
92c277c
+static gboolean reset_size_request(void* data)
92c277c
+{
92c277c
+    gtk_widget_set_size_request(GTK_WIDGET(data), -1, -1);
92c277c
+    return false;
92c277c
+}
92c277c
+}
92c277c
+
92c277c
 void wxTopLevelWindowGTK::DoSetClientSize(int width, int height)
92c277c
 {
92c277c
     base_type::DoSetClientSize(width, height);
92c277c
@@ -1202,6 +1210,25 @@ void wxTopLevelWindowGTK::DoSetClientSize(int width, int height)
92c277c
     // Has to be done after calling base because it calls SetSize,
92c277c
     // which sets this true
92c277c
     m_deferShowAllowed = false;
92c277c
+
92c277c
+    if (m_wxwindow)
92c277c
+    {
92c277c
+        // If window is not resizable or not yet shown, set size request on
92c277c
+        // client widget, to make it more likely window will get correct size
92c277c
+        // even if our decorations size cache is incorrect (as it will be before
92c277c
+        // showing first TLW).
92c277c
+        if (!gtk_window_get_resizable(GTK_WINDOW(m_widget)))
92c277c
+        {
92c277c
+            gtk_widget_set_size_request(m_widget, -1, -1);
92c277c
+            gtk_widget_set_size_request(m_wxwindow, m_clientWidth, m_clientHeight);
92c277c
+        }
92c277c
+        else if (!IsShown())
92c277c
+        {
92c277c
+            gtk_widget_set_size_request(m_wxwindow, m_clientWidth, m_clientHeight);
92c277c
+            // Cancel size request at next idle to allow resizing
92c277c
+            g_idle_add_full(G_PRIORITY_LOW, reset_size_request, m_wxwindow, NULL);
92c277c
+        }
92c277c
+    }
92c277c
 }
92c277c
 
92c277c
 void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const