]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0696: GTK4: A few issues with toolbar support v9.2.0696
authorFoxe Chen <chen.foxe@gmail.com>
Sun, 21 Jun 2026 18:19:58 +0000 (18:19 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 21 Jun 2026 18:19:58 +0000 (18:19 +0000)
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 <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/gui_gtk4.c
src/gui_gtk4_tb.c
src/gui_gtk4_tb.h
src/version.c

index 27cf554226baf04d5eb4d0e65b272e56b3f39cde..4874b2f6265e00945c3dc3dc9a79ab0f465212f7 100644 (file)
@@ -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;
 
index e3ed80b471af00b95467573eadf8813e598e105c..79682cfb13a10f7f7acd54fce39bc01726ca4aca 100644 (file)
@@ -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.
index d3ff4f782f09fc5942e18feffa07a071b2e02f83..541bd983eb248bc42b3806d257af4cbe5f0b098d 100644 (file)
@@ -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
 
index c1e5a940732e6f0af5420355ebe3e716466d1828..5fca1bd8cf0a80fdc68ea865d47fc3aac64906fa 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    696,
 /**/
     695,
 /**/