[Xfce4-commits] <xfce4-places-plugin:master> Added a remote popup script.

Andrzej noreply at xfce.org
Tue Sep 11 20:32:01 CEST 2012


Updating branch refs/heads/master
         to 89bad7fa73fcd9c61a67735c00f0eb3bb9c864af (commit)
       from 4ca5e93ab98b35a005d603077309ee6c4814e2b8 (commit)

commit 89bad7fa73fcd9c61a67735c00f0eb3bb9c864af
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Wed Sep 12 03:29:57 2012 +0900

    Added a remote popup script.
    
    The previous xfce4-popup-places[.c] did not work (old API?)
    The remote signal API is the same other popup scripts,
    e.g. xfce4-popup-applicationsmenu are using.
    
    Have not removed the old code yet.

 panel-plugin/Makefile.am           |   34 +++++-------
 panel-plugin/view.c                |  111 +++++++++++++++++++++++++++++++++--
 panel-plugin/xfce4-popup-places.sh |   48 +++++++++++++++
 3 files changed, 166 insertions(+), 27 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 64c85ef..fbb4dfa 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -1,21 +1,3 @@
-bin_PROGRAMS = xfce4-popup-places
-
-xfce4_popup_places_SOURCES =						\
-	xfce4-popup-places.c						\
-	xfce4-popup-places.h
-
-xfce4_popup_places_CFLAGS =						\
-	$(LIBX11_CFLAGS)						\
-	$(EXO_CFLAGS)							\
-	$(GTK_CFLAGS)
-
-xfce4_popup_places_LDADD =						\
-	$(LIBX11_LDFLAGS)						\
-	$(LIBX11_LIBS)							\
-	$(EXO_LIBS)							\
-	$(GTK_LIBS)
-
-
 
 plugindir = $(libdir)/xfce4/panel/plugins
 
@@ -90,6 +72,16 @@ libplaces_la_LDFLAGS = \
 	$(PLATFORM_LDFLAGS)
 
 #
+# xfce4-popup-places script
+#
+bin_SCRIPTS = \
+	xfce4-popup-places
+
+xfce4-popup-places: xfce4-popup-places.sh Makefile
+	$(AM_V_GEN) $(SED) -e "s,\@bindir\@,$(bindir),g" \
+	-e "s,\@localedir\@,$(localedir),g" $< >$@
+
+#
 # Desktop file
 #
 desktopdir = $(datadir)/xfce4/panel/plugins
@@ -97,8 +89,10 @@ desktop_in_files = places.desktop.in
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
-EXTRA_DIST = $(desktop_in_files)
+EXTRA_DIST = $(desktop_in_files) \
+	xfce4-popup-places.sh
 
-CLEANFILES = $(desktop_DATA)
+CLEANFILES = $(desktop_DATA) \
+	xfce4-popup-places
 
 # vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/panel-plugin/view.c b/panel-plugin/view.c
index b45ce2b..5378004 100644
--- a/panel-plugin/view.c
+++ b/panel-plugin/view.c
@@ -744,7 +744,8 @@ pview_update_menu(PlacesView *pd)
 }
 
 static void
-pview_open_menu(PlacesView *pd)
+pview_open_menu_at (PlacesView   *pd,
+                    GtkWidget    *button)
 {
     /* check if menu is needed, or it needs an update */
     if(pd->menu == NULL || pview_model_changed(pd->bookmark_groups))
@@ -754,19 +755,20 @@ pview_open_menu(PlacesView *pd)
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pd->button), TRUE);
 
     /* popup menu */
+    DBG("menu: %x", (guint)pd->menu);
     gtk_menu_popup (GTK_MENU (pd->menu), NULL, NULL,
-                    xfce_panel_plugin_position_menu,
-                    pd->plugin, 0,
+                    (button != NULL) ? xfce_panel_plugin_position_menu : NULL,
+                    pd->plugin, 1,
                     gtk_get_current_event_time ());
-    
+
     /* menu timeout to poll for model changes */
     if(pd->menu_timeout_id == 0){
 #if GLIB_CHECK_VERSION(2,14,0)
-        pd->menu_timeout_id = g_timeout_add_seconds_full(G_PRIORITY_LOW, 2, 
+        pd->menu_timeout_id = g_timeout_add_seconds_full(G_PRIORITY_LOW, 2,
                                    (GSourceFunc) pview_cb_menu_timeout, pd,
                                    NULL);
 #else
-        pd->menu_timeout_id = g_timeout_add_full(G_PRIORITY_LOW, 2000, 
+        pd->menu_timeout_id = g_timeout_add_full(G_PRIORITY_LOW, 2000,
                                    (GSourceFunc) pview_cb_menu_timeout, pd,
                                    NULL);
 #endif
@@ -776,6 +778,13 @@ pview_open_menu(PlacesView *pd)
     }
 }
 
+static void
+pview_open_menu(PlacesView *pd)
+{
+  if (pd != NULL)
+    pview_open_menu_at (pd, pd->button);
+}
+
 static GdkPixbuf*
 pview_pixbuf_factory(gint size)
 {
@@ -824,6 +833,92 @@ pview_button_update(PlacesView *view)
 
 }
 /********** Handle user message **********/
+
+/* copied from xfce4-panel/common/utils.c (panel_utils_grab_available) */
+static gboolean
+pview_grab_available (void)
+{
+  GdkScreen     *screen;
+  GdkWindow     *root;
+  GdkGrabStatus  grab_pointer = GDK_GRAB_FROZEN;
+  GdkGrabStatus  grab_keyboard = GDK_GRAB_FROZEN;
+  gboolean       grab_succeed = FALSE;
+  guint          i;
+  GdkEventMask   pointer_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+                                | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
+                                | GDK_POINTER_MOTION_MASK;
+
+  screen = xfce_gdk_screen_get_active (NULL);
+  root = gdk_screen_get_root_window (screen);
+
+  /* don't try to get the grab for longer then 1/4 second */
+  for (i = 0; i < (G_USEC_PER_SEC / 100 / 4); i++)
+    {
+      grab_keyboard = gdk_keyboard_grab (root, TRUE, GDK_CURRENT_TIME);
+      if (grab_keyboard == GDK_GRAB_SUCCESS)
+        {
+          grab_pointer = gdk_pointer_grab (root, TRUE, pointer_mask,
+                                           NULL, NULL, GDK_CURRENT_TIME);
+          if (grab_pointer == GDK_GRAB_SUCCESS)
+            {
+              grab_succeed = TRUE;
+              break;
+            }
+        }
+
+      g_usleep (100);
+    }
+
+  /* release the grab so the gtk_menu_popup() can take it */
+  if (grab_pointer == GDK_GRAB_SUCCESS)
+    gdk_pointer_ungrab (GDK_CURRENT_TIME);
+  if (grab_keyboard == GDK_GRAB_SUCCESS)
+    gdk_keyboard_ungrab (GDK_CURRENT_TIME);
+
+  if (!grab_succeed)
+    {
+      g_printerr (PACKAGE_NAME ": Unable to get keyboard and mouse "
+                  "grab. Menu popup failed.\n");
+    }
+
+  return grab_succeed;
+}
+
+
+static gboolean
+pview_remote_event(XfcePanelPlugin *panel_plugin,
+                   const gchar     *name,
+                   const GValue    *value,
+                   PlacesView      *view)
+{
+  g_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
+
+  DBG("remote event: %s, %x", name, (guint) view);
+
+  if (strcmp (name, "popup") == 0
+      && GTK_WIDGET_VISIBLE (panel_plugin)
+      && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view->button))
+      && pview_grab_available ()) /* checking if there is another menu on the screen */
+    {
+      if (value != NULL
+          && G_VALUE_HOLDS_BOOLEAN (value)
+          && g_value_get_boolean (value))
+        {
+          /* popup the menu under the pointer */
+          pview_open_menu_at (view, NULL);
+        }
+      else
+        {
+          /* show the menu */
+          pview_open_menu(view);
+        }
+      /* don't popup another menu */
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static gboolean
 pview_popup_command_message_received(GtkWidget *widget,
                                      GdkEventClient *ev,
@@ -925,7 +1020,9 @@ places_view_init(XfcePanelPlugin *plugin)
     g_signal_connect_swapped(view->button, "button-press-event",
                              G_CALLBACK(pview_cb_button_pressed), view);
 
-
+    /* remote control signal */
+    g_signal_connect(G_OBJECT(view->plugin), "remote-event",
+                     G_CALLBACK(pview_remote_event), view);
 
     /* set selection for xfce4-popup-places */
     pview_popup_command_set_selection(view);
diff --git a/panel-plugin/xfce4-popup-places.sh b/panel-plugin/xfce4-popup-places.sh
new file mode 100644
index 0000000..78c1d74
--- /dev/null
+++ b/panel-plugin/xfce4-popup-places.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Copyright (C) 2010 Nick Schermer <nick at xfce.org>
+# Copyright (C) 2012 Andrzej <ndrwrdck at gmail.com>
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+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
+    ;;
+  -V|--version)
+    exec @bindir@/xfce4-panel -V "$(basename $0)"
+    exit 0
+    ;;
+  -p|--pointer)
+    ATPOINTER="true"
+    ;;
+esac
+
+exec @bindir@/xfce4-panel --plugin-event=places:popup:bool:$ATPOINTER
+
+# vim:set ts=2 sw=2 et ai:


More information about the Xfce4-commits mailing list