From: Foxe Chen Date: Sun, 28 Jun 2026 16:46:50 +0000 (+0000) Subject: patch 9.2.0740: GTK4: scrollbar wrongly displayed X-Git-Tag: v9.2.0740^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27865e206ce6bba7cd5fe5ba379ce245e447bc92;p=thirdparty%2Fvim.git patch 9.2.0740: GTK4: scrollbar wrongly displayed 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 Signed-off-by: Christian Brabandt --- diff --git a/src/gui.c b/src/gui.c index 6e898f1c38..7b08f786ff 100644 --- 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. diff --git a/src/gui_gtk4.c b/src/gui_gtk4.c index e96801eb45..5a4e78481d 100644 --- a/src/gui_gtk4.c +++ b/src/gui_gtk4.c @@ -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 diff --git a/src/proto/gui_gtk4.pro b/src/proto/gui_gtk4.pro index eaf8eb2686..a40b102260 100644 --- a/src/proto/gui_gtk4.pro +++ b/src/proto/gui_gtk4.pro @@ -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); diff --git a/src/version.c b/src/version.c index 0ca0f16e8d..1231556601 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 740, /**/ 739, /**/