[geany/geany] dba7c7: Merge pull request #1272 from b4n/splitwindow/show-menu-gtk316

Colomban Wendling git-noreply at geany.org
Mon Oct 24 09:31:24 UTC 2016


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 24 Oct 2016 09:31:24 UTC
Commit:      dba7c763eddee4575d06b0b732920e61c05f0b3a
             https://github.com/geany/geany/commit/dba7c763eddee4575d06b0b732920e61c05f0b3a

Log Message:
-----------
Merge pull request #1272 from b4n/splitwindow/show-menu-gtk316

splitwindow: Fix document selection popup on GTK >= 3.15.9 && <= 3.21.4


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).


More information about the Commits mailing list