Skip to content

Commit

Permalink
splitwindow: Fix document selection popup on GTK >= 3.15.9 && <= 3.21.4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b4n committed Oct 22, 2016
1 parent 2184580 commit 9fa27cb
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions plugins/splitwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 9fa27cb

Please sign in to comment.