]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0740: GTK4: scrollbar wrongly displayed v9.2.0740
authorFoxe Chen <chen.foxe@gmail.com>
Sun, 28 Jun 2026 16:46:50 +0000 (16:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Jun 2026 16:46:50 +0000 (16:46 +0000)
Problem:  GTK4: scrollbar wrongly displayed
Solution: Calculate scrollbar size in gui_mch_enable_scrollbar for gtk4
          gui (Foxe Chen)

closes: #20628

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

index 6e898f1c38cf2d2439763af9ba53ae260fed2ad5..7b08f786ff3b331dfa3a1fdc84fd39ab1bba7612 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -1725,11 +1725,6 @@ gui_set_shellsize(
     if (!gui.shell_created)
        return;
 
-#if defined(FEAT_GUI_GTK) && defined(USE_GTK4)
-    // Get the scrollbar width + height if possible
-    gui_mch_update_scrollbar_size();
-#endif
-
 #if defined(MSWIN) || defined(FEAT_GUI_GTK)
     // If not setting to a user specified size and maximized, calculate the
     // number of characters that fit in the maximized window.
index e96801eb4520c86b81db3cc3c005b175155c8416..5a4e78481d89213f10aa551215116501652fc992 100644 (file)
@@ -2766,6 +2766,64 @@ gui_mch_forked(void)
 {
 }
 
+/*
+ * Try getting the actual size of the scrollbar, and update gui.scrollbar_width
+ * and gui.scrollbar_height.
+ */
+    static void
+gui_gtk4_update_scrollbar_size(void)
+{
+    win_T      *wp;
+    int                w = -1, h = -1;
+    GtkWidget  *sbar;
+
+    FOR_ALL_WINDOWS(wp)
+    {
+       sbar = wp->w_scrollbars[SBAR_LEFT].id;
+
+       if (sbar == NULL || !gtk_widget_get_visible(sbar)
+               || (!gui.which_scrollbars[SBAR_LEFT]
+                   && wp->w_scrollbars[SBAR_RIGHT].id != NULL))
+           sbar = wp->w_scrollbars[SBAR_RIGHT].id;
+
+       if (sbar != NULL && gtk_widget_get_visible(sbar))
+       {
+           GtkRequisition  min, nat;
+           int             sw;
+
+           // Use preferred size, since widget may not have its size allocated
+           // yet.
+           gtk_widget_get_preferred_size(sbar, &min, &nat);
+           sw = MAX(min.width, nat.width);
+           if (sw > 0)
+           {
+               w = sw;
+               break;
+           }
+       }
+
+    }
+
+    sbar = gui.bottom_sbar.id;
+    if (sbar != NULL && gtk_widget_get_visible(sbar))
+    {
+       GtkRequisition min, nat;
+       int                 sh;
+
+       gtk_widget_get_preferred_size(sbar, &min, &nat);
+       sh = MAX(min.height, nat.height);
+
+       if (sh > 0)
+           h = sh;
+    }
+
+    if (w != -1)
+       gui.scrollbar_width = w;
+    if (h != -1)
+       gui.scrollbar_height = h;
+}
+
+
 /*
  * ============================================================
  * Scrollbar
@@ -2776,7 +2834,14 @@ gui_mch_forked(void)
 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag)
 {
     if (sb->id != NULL)
+    {
+       gboolean was_visible = gtk_widget_get_visible(sb->id);
+
        gtk_widget_set_visible(sb->id, flag);
+
+       if (!was_visible && flag)
+           gui_gtk4_update_scrollbar_size();
+    }
 }
 
 #if defined(FEAT_MENU)
@@ -4658,63 +4723,6 @@ gui_mch_destroy_scrollbar(scrollbar_T *sb)
     }
 }
 
-/*
- * Try getting the actual size of the scrollbar, and update gui.scrollbar_width
- * and gui.scrollbar_height.
- */
-    void
-gui_mch_update_scrollbar_size(void)
-{
-    win_T      *wp;
-    int                w = -1, h = -1;
-    GtkWidget  *sbar;
-
-    FOR_ALL_WINDOWS(wp)
-    {
-       sbar = wp->w_scrollbars[SBAR_LEFT].id;
-
-       if (sbar == NULL || !gtk_widget_get_visible(sbar)
-               || (!gui.which_scrollbars[SBAR_LEFT]
-                   && wp->w_scrollbars[SBAR_RIGHT].id != NULL))
-           sbar = wp->w_scrollbars[SBAR_RIGHT].id;
-
-       if (sbar != NULL && gtk_widget_get_visible(sbar))
-       {
-           GtkRequisition  min, nat;
-           int             sw;
-
-           // Use preferred size, since widget may not have its size allocated
-           // yet.
-           gtk_widget_get_preferred_size(sbar, &min, &nat);
-           sw = MAX(min.width, nat.width);
-           if (sw > 0)
-           {
-               w = sw;
-               break;
-           }
-       }
-
-    }
-
-    sbar = gui.bottom_sbar.id;
-    if (sbar != NULL && gtk_widget_get_visible(sbar))
-    {
-       GtkRequisition min, nat;
-       int                 sh;
-
-       gtk_widget_get_preferred_size(sbar, &min, &nat);
-       sh = MAX(min.height, nat.height);
-
-       if (sh > 0)
-           h = sh;
-    }
-
-    if (w != -1)
-       gui.scrollbar_width = w;
-    if (h != -1)
-       gui.scrollbar_height = h;
-}
-
 /*
  * ============================================================
  * Text area position
index eaf8eb26861956d6167d4f163ce3040685c46370..a40b1022602f343274ab3e84e8d101b89a12835c 100644 (file)
@@ -102,7 +102,6 @@ int gui_mch_get_scrollbar_xpadding(void);
 int gui_mch_get_scrollbar_ypadding(void);
 void gui_mch_create_scrollbar(scrollbar_T *sb, int orient);
 void gui_mch_destroy_scrollbar(scrollbar_T *sb);
-void gui_mch_update_scrollbar_size(void);
 void gui_mch_set_text_area_pos(int x, int y, int w, int h);
 void gui_gtk_calculate_bleed(int width, int height);
 char_u *gui_mch_browse(int saving, char_u *title, char_u *dflt, char_u *ext, char_u *initdir, char_u *filter);
index 0ca0f16e8df68755db6a96beb73563fe55774134..12315566019943ddec0014e47df53369d90d6869 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    740,
 /**/
     739,
 /**/