Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sat, 22 Oct 2016 13:15:24 UTC Commit: 9fa27cb16ba6f82489fa91514052854774f000f6 https://github.com/geany/geany/commit/9fa27cb16ba6f82489fa91514052854774f000...
Log Message: ----------- splitwindow: Fix document selection popup on GTK >= 3.15.9 && <= 3.21.4
Works around GTK bug https://bugzilla.gnome.org/show_bug.cgi?id=769287. Stop emission of the ::show-menu signal if it was first emitted from an inactive toggle button, which happens only in the buggy case. This workaround tries to not negatively affect a correctly behaving GTK version in the unlikely case some distributions patched their version.
Fixes #1149.
Modified Paths: -------------- plugins/splitwindow.c
Modified: plugins/splitwindow.c 37 lines changed, 35 insertions(+), 2 deletions(-) =================================================================== @@ -247,7 +247,7 @@ static void on_doc_menu_item_clicked(gpointer item, GeanyDocument *doc) }
-static void on_doc_menu_show(GtkMenu *menu) +static void on_doc_show_menu(GtkMenuToolButton *button, GtkMenu *menu) { /* clear the old menu items */ gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback) gtk_widget_destroy, NULL); @@ -257,6 +257,34 @@ static void on_doc_menu_show(GtkMenu *menu) }
+#if GTK_CHECK_VERSION(3, 0, 0) +/* Blocks the ::show-menu signal if the menu's parent toggle button was inactive in the previous run. + * This is a hack to workaround https://bugzilla.gnome.org/show_bug.cgi?id=769287 + * and should NOT be used for any other version than 3.15.9 to 3.21.4, although the code tries and + * not block a legitimate signal in case the GTK version in use has been patched */ +static void show_menu_gtk316_fix(GtkMenuToolButton *button, gpointer data) +{ + /* we assume only a single menu can popup at once, so reentrency isn't an issue. + * if it was, we could use custom data on the button, but it shouldn't be required */ + static gboolean block_next = FALSE; + + if (block_next) + { + g_signal_stop_emission_by_name(button, "show-menu"); + block_next = FALSE; + } + else + { + GtkWidget *menu = gtk_menu_tool_button_get_menu(button); + GtkWidget *parent = gtk_menu_get_attach_widget(GTK_MENU(menu)); + + if (parent && GTK_IS_TOGGLE_BUTTON(parent) && ! gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(parent))) + block_next = TRUE; + } +} +#endif + + static GtkWidget *create_toolbar(void) { GtkWidget *toolbar, *item; @@ -275,7 +303,12 @@ static GtkWidget *create_toolbar(void)
item = gtk_menu_new(); gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(tool_item), item); - g_signal_connect(item, "show", G_CALLBACK(on_doc_menu_show), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + /* hack for https://bugzilla.gnome.org/show_bug.cgi?id=769287 */ + if (! gtk_check_version(3, 15, 9) && gtk_check_version(3, 21, 4+1)) + g_signal_connect(tool_item, "show-menu", G_CALLBACK(show_menu_gtk316_fix), NULL); +#endif + g_signal_connect(tool_item, "show-menu", G_CALLBACK(on_doc_show_menu), item);
tool_item = gtk_tool_item_new(); gtk_tool_item_set_expand(tool_item, TRUE);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).