[Xfce4-commits] <xfce4-panel:master> Applicationmenu: Show menu on button-press-event (bug #8047).
Nick Schermer
noreply at xfce.org
Sun Oct 23 20:18:01 CEST 2011
Updating branch refs/heads/master
to 7aa32d384c375e79f96213007ba1aa32b9525040 (commit)
from 5385d9914b43ee74c0b1da093b44515777a81409 (commit)
commit 7aa32d384c375e79f96213007ba1aa32b9525040
Author: Nick Schermer <nick at xfce.org>
Date: Sun Oct 23 20:15:22 2011 +0200
Applicationmenu: Show menu on button-press-event (bug #8047).
This allows to select a menuitem without releasing the
mouse button and also feel a bit faster.
plugins/applicationsmenu/applicationsmenu.c | 37 +++++++++++++++++---------
1 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/plugins/applicationsmenu/applicationsmenu.c b/plugins/applicationsmenu/applicationsmenu.c
index 9872153..5b2045d 100644
--- a/plugins/applicationsmenu/applicationsmenu.c
+++ b/plugins/applicationsmenu/applicationsmenu.c
@@ -108,7 +108,8 @@ static gboolean applications_menu_plugin_remote_event (XfcePanelPlugin
const gchar *name,
const GValue *value);
static void applications_menu_plugin_menu_reload (ApplicationsMenuPlugin *plugin);
-static void applications_menu_plugin_menu (GtkWidget *button,
+static gboolean applications_menu_plugin_menu (GtkWidget *button,
+ GdkEventButton *event,
ApplicationsMenuPlugin *plugin);
@@ -233,7 +234,7 @@ applications_menu_plugin_init (ApplicationsMenuPlugin *plugin)
gtk_widget_set_name (plugin->button, "applicationmenu-button");
gtk_button_set_relief (GTK_BUTTON (plugin->button), GTK_RELIEF_NONE);
gtk_widget_set_tooltip_text (plugin->button, DEFAULT_TITLE);
- g_signal_connect (G_OBJECT (plugin->button), "toggled",
+ g_signal_connect (G_OBJECT (plugin->button), "button-press-event",
G_CALLBACK (applications_menu_plugin_menu), plugin);
plugin->box = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 1);
@@ -630,12 +631,12 @@ applications_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
&& g_value_get_boolean (value))
{
/* show menu under cursor */
- applications_menu_plugin_menu (NULL, plugin);
+ applications_menu_plugin_menu (NULL, NULL, plugin);
}
else
{
/* show the menu at the button */
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button), TRUE);
+ applications_menu_plugin_menu (plugin->button, NULL, plugin);
}
/* don't popup another menu */
@@ -980,8 +981,9 @@ applications_menu_plugin_menu_add (GtkWidget *gtk_menu,
-static void
+static gboolean
applications_menu_plugin_menu (GtkWidget *button,
+ GdkEventButton *event,
ApplicationsMenuPlugin *plugin)
{
GtkWidget *mi;
@@ -990,12 +992,17 @@ applications_menu_plugin_menu (GtkWidget *button,
gchar *filename;
GFile *file;
- panel_return_if_fail (XFCE_IS_APPLICATIONS_MENU_PLUGIN (plugin));
- panel_return_if_fail (button == NULL || plugin->button == button);
+ panel_return_val_if_fail (XFCE_IS_APPLICATIONS_MENU_PLUGIN (plugin), FALSE);
+ panel_return_val_if_fail (button == NULL || plugin->button == button, FALSE);
- if (button != NULL
- && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- return;
+ if (event != NULL
+ && !(event->button == 1
+ && event->type == GDK_BUTTON_PRESS
+ && !PANEL_HAS_FLAG (event->state, GDK_CONTROL_MASK)))
+ return FALSE;
+
+ if (button != NULL)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
if (plugin->menu == NULL)
{
@@ -1043,18 +1050,22 @@ applications_menu_plugin_menu (GtkWidget *button,
{
xfce_dialog_show_error (NULL, error, _("Failed to load the applications menu"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+ if (button != NULL)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
if (G_LIKELY (error != NULL))
g_error_free (error);
if (G_LIKELY (menu != NULL))
g_object_unref (G_OBJECT (menu));
- return;
+ return FALSE;
}
}
gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL,
button != NULL ? xfce_panel_plugin_position_menu : NULL,
- plugin, 1, gtk_get_current_event_time ());
+ plugin, 1,
+ event != NULL ? event->time : gtk_get_current_event_time ());
+
+ return TRUE;
}
More information about the Xfce4-commits
mailing list