[Xfce4-commits] <xfce4-panel:devel> Add popup under cursor for window menu.

Nick Schermer noreply at xfce.org
Tue Feb 23 19:30:04 CET 2010


Updating branch refs/heads/devel
         to 4be43b022a2a64451f43d78772da45521a85b58b (commit)
       from 349f8929cc082c19c6e2a173be91ee398a27525a (commit)

commit 4be43b022a2a64451f43d78772da45521a85b58b
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Feb 23 19:28:26 2010 +0100

    Add popup under cursor for window menu.

 plugins/windowmenu/windowmenu.c              |   93 ++++++++++++-------------
 plugins/windowmenu/xfce4-popup-windowmenu.sh |    8 ++-
 2 files changed, 52 insertions(+), 49 deletions(-)

diff --git a/plugins/windowmenu/windowmenu.c b/plugins/windowmenu/windowmenu.c
index a4b1a70..9cbd212 100644
--- a/plugins/windowmenu/windowmenu.c
+++ b/plugins/windowmenu/windowmenu.c
@@ -127,10 +127,8 @@ static void      window_menu_plugin_window_closed           (WnckScreen
 static void      window_menu_plugin_windows_disconnect      (WindowMenuPlugin   *plugin);
 static void      window_menu_plugin_windows_connect         (WindowMenuPlugin   *plugin,
                                                              gboolean            traverse_windows);
-static gboolean  window_menu_plugin_button_press_event      (GtkWidget          *button,
-                                                             GdkEventButton     *event,
+static void      window_menu_plugin_menu                    (GtkWidget          *button,
                                                              WindowMenuPlugin   *plugin);
-static GtkWidget *window_menu_plugin_menu_new               (WindowMenuPlugin   *plugin);
 
 
 
@@ -255,8 +253,8 @@ window_menu_plugin_init (WindowMenuPlugin *plugin)
   gtk_container_add (GTK_CONTAINER (plugin), plugin->button);
   gtk_button_set_relief (GTK_BUTTON (plugin->button), GTK_RELIEF_NONE);
   gtk_widget_set_name (plugin->button, "windowmenu-button");
-  g_signal_connect (G_OBJECT (plugin->button), "button-press-event",
-                    G_CALLBACK (window_menu_plugin_button_press_event), plugin);
+  g_signal_connect (G_OBJECT (plugin->button), "toggled",
+      G_CALLBACK (window_menu_plugin_menu), plugin);
 
   plugin->icon = xfce_panel_image_new_from_source ("user-desktop");
   gtk_container_add (GTK_CONTAINER (plugin->button), plugin->icon);
@@ -579,7 +577,6 @@ window_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
                                  const GValue    *value)
 {
   WindowMenuPlugin *plugin = XFCE_WINDOW_MENU_PLUGIN (panel_plugin);
-  GdkEventButton    event;
 
   panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
 
@@ -587,12 +584,18 @@ window_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
       && GTK_WIDGET_VISIBLE (panel_plugin)
       && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin->button)))
     {
-      /* create fake event */
-      event.type = GDK_BUTTON_PRESS;
-      event.button = 1;
-      event.time = gtk_get_current_event_time ();
-
-      window_menu_plugin_button_press_event (plugin->button, &event, plugin);
+      if (value != NULL
+          && G_VALUE_HOLDS_BOOLEAN (value)
+          && g_value_get_boolean (value))
+        {
+          /* popup the menu under the pointer */
+          window_menu_plugin_menu (NULL, plugin);
+        }
+      else
+        {
+          /* show the menu */
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button), TRUE);
+        }
 
       /* don't popup another menu */
       return TRUE;
@@ -785,37 +788,6 @@ window_menu_plugin_windows_connect (WindowMenuPlugin *plugin,
 
 
 
-static gboolean
-window_menu_plugin_button_press_event (GtkWidget        *button,
-                                       GdkEventButton   *event,
-                                       WindowMenuPlugin *plugin)
-{
-  GtkWidget *menu;
-
-  panel_return_val_if_fail (XFCE_IS_WINDOW_MENU_PLUGIN (plugin), FALSE);
-  panel_return_val_if_fail (XFCE_IS_ARROW_BUTTON (button), FALSE);
-  panel_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (button), FALSE);
-
-  /* only respond to a normal button 1 press */
-  if (event->type != GDK_BUTTON_PRESS || event->button != 1)
-    return FALSE;
-
-  /* activate the toggle button */
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
-
-  /* popup the menu */
-  menu = window_menu_plugin_menu_new (plugin);
-  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
-                  xfce_panel_plugin_position_menu, plugin,
-                  event->button, event->time);
-
-
-
-  return TRUE;
-}
-
-
-
 static void
 window_menu_plugin_workspace_add (GtkWidget        *mi,
                                   WindowMenuPlugin *plugin)
@@ -1070,12 +1042,14 @@ static void
 window_menu_plugin_menu_selection_done (GtkWidget *menu,
                                         GtkWidget *button)
 {
-  panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+  panel_return_if_fail (button == NULL || GTK_IS_TOGGLE_BUTTON (button));
   panel_return_if_fail (GTK_IS_MENU (menu));
 
-  gtk_widget_destroy (menu);
+  if (button != NULL)
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
 
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+  /* delay destruction so we can handle the activate event first */
+  exo_gtk_object_destroy_later (GTK_OBJECT (menu));
 }
 
 
@@ -1175,8 +1149,6 @@ window_menu_plugin_menu_new (WindowMenuPlugin *plugin)
     w = h = 16;
 
   menu = gtk_menu_new ();
-  g_signal_connect (G_OBJECT (menu), "selection-done",
-      G_CALLBACK (window_menu_plugin_menu_selection_done), plugin->button);
   g_signal_connect (G_OBJECT (menu), "key-press-event",
       G_CALLBACK (window_menu_plugin_menu_key_press_event), plugin);
 
@@ -1368,3 +1340,28 @@ window_menu_plugin_menu_new (WindowMenuPlugin *plugin)
 
   return menu;
 }
+
+
+
+static void
+window_menu_plugin_menu (GtkWidget        *button,
+                         WindowMenuPlugin *plugin)
+{
+  GtkWidget *menu;
+
+  panel_return_if_fail (XFCE_IS_WINDOW_MENU_PLUGIN (plugin));
+  panel_return_if_fail (button == NULL || plugin->button == button);
+
+  if (button != NULL
+      && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+    return;
+
+  /* popup the menu */
+  menu = window_menu_plugin_menu_new (plugin);
+  g_signal_connect (G_OBJECT (menu), "deactivate",
+      G_CALLBACK (window_menu_plugin_menu_selection_done), button);
+
+  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                  button != NULL ? xfce_panel_plugin_position_menu : NULL,
+                  plugin, 1, gtk_get_current_event_time ());
+}
diff --git a/plugins/windowmenu/xfce4-popup-windowmenu.sh b/plugins/windowmenu/xfce4-popup-windowmenu.sh
index 067ec85..6d95fc6 100644
--- a/plugins/windowmenu/xfce4-popup-windowmenu.sh
+++ b/plugins/windowmenu/xfce4-popup-windowmenu.sh
@@ -20,12 +20,15 @@
 export TEXTDOMAIN="xfce4-panel"
 export TEXTDOMAINDIR="@localedir@"
 
+ATPOINTER="false"
+
 case "$1" in
   -h|--help)
     echo "$(gettext "Usage:")"
     echo "  $(basename $0) [$(gettext "OPTION")...]"
     echo
     echo "$(gettext "Options:")"
+    echo "  -p, --pointer   $(gettext "Popup menu at current mouse position")"
     echo "  -h, --help      $(gettext "Show help options")"
     echo "  -V, --version   $(gettext "Print version information and exit")"
     exit 0
@@ -34,8 +37,11 @@ case "$1" in
     exec @bindir@/xfce4-panel -V "$(basename $0)"
     exit 0
     ;;
+  -p|--pointer)
+    ATPOINTER="true"
+    ;;
 esac
 
-exec @bindir@/xfce4-panel --plugin-event=windowmenu:popup
+exec @bindir@/xfce4-panel --plugin-event=windowmenu:popup:bool:$ATPOINTER
 
 # vim:set ts=2 sw=2 et ai:



More information about the Xfce4-commits mailing list