From: Foxe Chen Date: Sun, 21 Jun 2026 18:19:58 +0000 (+0000) Subject: patch 9.2.0696: GTK4: A few issues with toolbar support X-Git-Tag: v9.2.0696^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6616b354918c05ea5852e50f9a4010d8bce4abd;p=thirdparty%2Fvim.git patch 9.2.0696: GTK4: A few issues with toolbar support Problem: GTK4: A few issues with toolbar support Solution: Fix segfault when removing toolbar icon; bring focus to drawarea when button in overflow menu is clicked (Foxe Chen) closes: #20562 Signed-off-by: Foxe Chen Signed-off-by: Christian Brabandt --- diff --git a/src/gui_gtk4.c b/src/gui_gtk4.c index 27cf554226..4874b2f626 100644 --- a/src/gui_gtk4.c +++ b/src/gui_gtk4.c @@ -4666,10 +4666,9 @@ gui_mch_destroy_menu(vimmenu_T *menu) // For toolbar buttons and separators, remove from the toolbar box. if (menu->id != NULL && menu->id != (GtkWidget *)1) { - GtkWidget *parent_widget = gtk_widget_get_parent(menu->id); - - if (parent_widget != NULL) - gtk_box_remove(GTK_BOX(parent_widget), menu->id); + vim_toolbar_remove(VIM_TOOLBAR(gui.toolbar), menu->id); + menu->id = NULL; + return; } menu->id = NULL; diff --git a/src/gui_gtk4_tb.c b/src/gui_gtk4_tb.c index e3ed80b471..79682cfb13 100644 --- a/src/gui_gtk4_tb.c +++ b/src/gui_gtk4_tb.c @@ -35,8 +35,8 @@ struct _VimToolbar G_DEFINE_TYPE(VimToolbar, vim_toolbar, GTK_TYPE_WIDGET) - static void vim_toolbar_size_allocate(GtkWidget *widget, int width, int height, int baseline); - static void vim_toolbar_measure(GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline); +static void vim_toolbar_size_allocate(GtkWidget *widget, int width, int height, int baseline); +static void vim_toolbar_measure(GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum, int *natural, int *minimum_baseline, int *natural_baseline); static void vim_toolbar_dispose(GObject *object) @@ -192,6 +192,19 @@ set_button_style(GtkWidget *btn, int style, int iconsize, gboolean invalidate) g_object_set_data(G_OBJECT(btn), "toolbar-width", GINT_TO_POINTER(-1)); } +/* + * Always close overflow popover when button is clicked. + */ + static void +button_clicked(GtkWidget *widget UNUSED, VimToolbar *self) +{ + gtk_menu_button_popdown(GTK_MENU_BUTTON(self->overflow_btn)); + // Bring focus to drawarea, popping overflow menu down does not change + // focus. + gtk_widget_grab_focus(gui.drawarea); + gui_mch_flush(); +} + /* * Add a new toolbar button at the given index and return the widget. "icon" and * "text" may be NULL.. @@ -230,6 +243,9 @@ vim_toolbar_insert_button( set_button_style(btn, self->style, self->iconsize, TRUE); + g_signal_connect_object(btn, "clicked", + G_CALLBACK(button_clicked), self, G_CONNECT_DEFAULT); + vim_toolbar_insert(self, btn, idx); return btn; } @@ -279,6 +295,18 @@ vim_toolbar_set_style(VimToolbar *self, int style, int iconsize) gtk_widget_queue_allocate(GTK_WIDGET(self)); } +/* + * Remove the item from the toolbar. + */ + void +vim_toolbar_remove(VimToolbar *self, GtkWidget *item) +{ + gtk_box_remove(GTK_BOX(self->strip),item); + self->items = g_list_remove(self->items, item); + g_object_unref(item); + gtk_widget_queue_allocate(GTK_WIDGET(self)); +} + /* * If "overflow" is TRUE, then move "item" from the toolbar to the overflow, and * vice versa. diff --git a/src/gui_gtk4_tb.h b/src/gui_gtk4_tb.h index d3ff4f782f..541bd983eb 100644 --- a/src/gui_gtk4_tb.h +++ b/src/gui_gtk4_tb.h @@ -25,6 +25,7 @@ GtkWidget *vim_toolbar_new(void); GtkWidget *vim_toolbar_insert_button(VimToolbar *self, GtkWidget *icon, const char *text, int idx); GtkWidget *vim_toolbar_insert_separator(VimToolbar *self, int idx); void vim_toolbar_set_style(VimToolbar *self, int style, int iconsize); +void vim_toolbar_remove(VimToolbar *self, GtkWidget *item); #endif diff --git a/src/version.c b/src/version.c index c1e5a94073..5fca1bd8cf 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 */ +/**/ + 696, /**/ 695, /**/