]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0577: GTK4: window resizing issues v9.2.0577
authorFoxe Chen <chen.foxe@gmail.com>
Sun, 31 May 2026 20:09:52 +0000 (20:09 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 31 May 2026 20:14:59 +0000 (20:14 +0000)
Problem:  GTK4: window size does not account for client-side decorations
Solution: Compute the client side decoration height from
          gui_resize_shell() (Foxe Chen)

fixes:  #20365
closes: #20388

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/gui.c
src/gui.h
src/gui_gtk4.c
src/proto/gui_gtk4.pro
src/version.c

index 8cf4c8fa48378e92e32353a6171a673772466a78..b0235eec28aa270c1dd86302cca29c6575f28359 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -1594,6 +1594,9 @@ again:
 
     // Flush pending output before redrawing
     out_flush();
+#if defined(FEAT_GUI_GTK) && defined(USE_GTK4)
+    gui_gtk_init_decor_height();
+#endif
 
     gui.num_cols = (pixel_width - gui_get_base_width()) / gui.char_width;
     gui.num_rows = (pixel_height - gui_get_base_height()) / gui.char_height;
index d1e5d2d5c062f21b07fa555b0a7cb1e855913559..609100a172470f4c7a5343094d07e28ec5584c95 100644 (file)
--- a/src/gui.h
+++ b/src/gui.h
@@ -475,6 +475,9 @@ typedef struct Gui
     char       *rsrc_input_method;
     char       *rsrc_preedit_type_name;
 #endif
+#if defined(FEAT_GUI_GTK) && defined(USE_GTK4)
+    int decor_height;
+#endif
 } gui_T;
 
 extern gui_T gui;                      // this is defined in gui.c
index 1596f19e5c2052a5bc7b464a7632f16a249e8e95..e7bbd9ad56ee82379e7d02a9bb4cadf95ccd0848 100644 (file)
@@ -816,6 +816,28 @@ gui_mch_settitle(char_u *title, char_u *icon UNUSED)
 
 static int in_set_shellsize = FALSE;
 
+/*
+ * Get height of window decorations, that we cannot determine directly. For
+ * example, the GtkHeaderBar widget. This is called in gui_resize_shell(), we
+ * cannot call it in gui_set_shellsize(), because that may be called before the
+ * drawarea/formwin is resized, which may cause the drawarea to be bigger than
+ * it actually is (while the window size is up to date), causing a negative
+ * "decor_height".
+ */
+    void
+gui_gtk_init_decor_height(void)
+{
+    int h = gtk_widget_get_height(gui.mainwin);
+
+    if (h == 0)
+       return;
+
+    h -= get_menu_tool_height();
+    h -= gtk_widget_get_height(gui.formwin);
+
+    gui.decor_height = h;
+}
+
     void
 gui_mch_set_shellsize(int width, int height,
        int min_width UNUSED, int min_height UNUSED,
@@ -824,6 +846,11 @@ gui_mch_set_shellsize(int width, int height,
 {
     width += get_menu_tool_width();
     height += get_menu_tool_height();
+
+    // GtkWindow default size also includes client side decorations, so must
+    // include it also.
+    height += gui.decor_height;
+
     gtk_window_set_default_size(GTK_WINDOW(gui.mainwin), width, height);
 }
 
@@ -3240,24 +3267,45 @@ get_menu_tool_width(void)
     int
 get_menu_tool_height(void)
 {
-    int height = 0;
-
+    GtkWidget *widgets[] = {
 #ifdef FEAT_MENU
-    if (gui.menubar != NULL && gtk_widget_get_visible(gui.menubar))
-    {
-       GtkRequisition req;
-       gtk_widget_get_preferred_size(gui.menubar, &req, NULL);
-       height += req.height;
-    }
+       gui.menubar,
 #endif
 #ifdef FEAT_TOOLBAR
-    if (gui.toolbar != NULL && gtk_widget_get_visible(gui.toolbar))
+       gui.toolbar,
+#endif
+#ifdef FEAT_GUI_TABLINE
+       gui.tabline
+#endif
+    };
+
+    int height = 0;
+
+    for (int i = 0; i < ARRAY_LENGTH(widgets); i++)
     {
-       GtkRequisition req;
-       gtk_widget_get_preferred_size(gui.toolbar, &req, NULL);
-       height += req.height;
+       GtkRequisition  min;
+       GtkRequisition  nat;
+       int             h;
+
+       if (widgets[i] == NULL || !gtk_widget_get_visible(widgets[i]))
+           continue;
+
+       h = gtk_widget_get_height(widgets[i]);
+
+       if (h == 0)
+       {
+           // Allocation hasn't been updated yet (widget just became visible).
+           // Query the preferred height so the caller gets a valid value
+           // before the layout pass runs.  Use the maximum of minimum and
+           // natural height: GTK may allocate min_h even when natural_h is
+           // smaller (e.g. GtkNotebook tab bar has min_h > natural_h due to
+           // CSS).
+           gtk_widget_get_preferred_size(widgets[i], &min, &nat);
+           height += MAX(min.height, nat.height);
+       }
+       else
+           height += h;
     }
-#endif
     return height;
 }
 
index 10f3ccc20286b8e2930f9894ac4ac0618562aa41..4d21e6a7032daa45138f3b5015878ff04a1fdb87 100644 (file)
@@ -19,6 +19,7 @@ void gui_mch_unmaximize(void);
 void gui_mch_set_fullscreen(int flag);
 void gui_mch_newfont(void);
 void gui_mch_settitle(char_u *title, char_u *icon);
+void gui_gtk_init_decor_height(void);
 void gui_mch_set_shellsize(int width, int height, int min_width, int min_height, int base_width, int base_height, int direction);
 void gui_mch_get_screen_dimensions(int *screen_w, int *screen_h);
 void gui_mch_enable_menu(int showit);
index dab821ad6488dbcd075a4c8fe1b69b9cc40d9e6f..b97066f50b78a418125576d7b73d6d9492fd87e4 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    577,
 /**/
     576,
 /**/