[Xfce4-commits] <xfce4-appfinder:andrzejr/plugin> Added remote event and popup script, fixed button press event handler.

Andrzej noreply at xfce.org
Thu Feb 16 17:08:01 CET 2012


Updating branch refs/heads/andrzejr/plugin
         to cde7eeb485cbdf85727007e295f46a3940eb9117 (commit)
       from 5f8e442b70b3b8cd72e397729c81777a19640ca7 (commit)

commit cde7eeb485cbdf85727007e295f46a3940eb9117
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Fri Feb 17 01:06:43 2012 +0900

    Added remote event and popup script, fixed button press event handler.

 panel-plugin/Makefile.am              |   10 ++++
 panel-plugin/appfinder-plugin.c       |   79 ++++++++++++++++++++++++++------
 panel-plugin/xfce4-popup-appfinder.sh |   44 ++++++++++++++++++
 3 files changed, 118 insertions(+), 15 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index a28fc70..fafd742 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -37,6 +37,16 @@ libappfinder_la_LIBADD = \
 	$(LIBXFCE4UI_LIBS)
 
 #
+# xfce4-popup-appfinder script
+#
+bin_SCRIPTS = \
+	xfce4-popup-appfinder
+
+xfce4-popup-appfinder: xfce4-popup-appfinder.sh Makefile
+	$(AM_V_GEN) sed -e "s,\@bindir\@,$(bindir),g" \
+	-e "s,\@localedir\@,$(localedir),g" $< >$@
+
+#
 # .desktop file
 #
 desktopdir = $(datadir)/xfce4/panel/plugins
diff --git a/panel-plugin/appfinder-plugin.c b/panel-plugin/appfinder-plugin.c
index b4c893b..39b67ce 100644
--- a/panel-plugin/appfinder-plugin.c
+++ b/panel-plugin/appfinder-plugin.c
@@ -60,6 +60,7 @@ struct _XfceAppfinderPlugin
   GtkWidget       *appfinder_socket;
 
   gboolean         visible;
+
   gint             busy;
   gint             handler;
 
@@ -93,7 +94,10 @@ static gboolean  xfce_appfinder_plugin_size_changed     (XfcePanelPlugin
 static void      xfce_appfinder_plugin_mode_changed     (XfcePanelPlugin        *panel_plugin,
                                                          XfcePanelPluginMode     mode);
 static void      xfce_appfinder_plugin_configure_plugin (XfcePanelPlugin        *panel_plugin);
-static void      xfce_appfinder_plugin_activate         (GtkWidget              *widget,
+static gboolean  xfce_appfinder_plugin_remote_event     (XfcePanelPlugin        *panel_plugin,
+                                                         const gchar            *name,
+                                                         const GValue           *value);
+static gboolean  xfce_appfinder_plugin_button_pressed   (GtkWidget              *widget,
                                                          GdkEventButton         *event,
                                                          XfceAppfinderPlugin    *plugin);
 
@@ -122,6 +126,8 @@ xfce_appfinder_plugin_class_init (XfceAppfinderPluginClass *klass)
   plugin_class->size_changed = xfce_appfinder_plugin_size_changed;
   plugin_class->mode_changed = xfce_appfinder_plugin_mode_changed;
   plugin_class->configure_plugin = xfce_appfinder_plugin_configure_plugin;
+  plugin_class->remote_event = xfce_appfinder_plugin_remote_event;
+
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_BUTTON_TITLE,
                                    g_param_spec_boolean ("show-button-title",
@@ -171,7 +177,7 @@ xfce_appfinder_plugin_init (XfceAppfinderPlugin *plugin)
   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), "button-press-event",
-                    G_CALLBACK (xfce_appfinder_plugin_activate), plugin);
+                    G_CALLBACK (xfce_appfinder_plugin_button_pressed), plugin);
 
   plugin->box = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 1);
   gtk_container_add (GTK_CONTAINER (plugin->button), plugin->box);
@@ -399,30 +405,26 @@ xfce_appfinder_plugin_activate_dbus (DBusGProxy       *proxy,
 
 
 static void
-xfce_appfinder_plugin_activate (GtkWidget            *button,
-                                GdkEventButton       *event,
-                                XfceAppfinderPlugin  *plugin)
+xfce_appfinder_plugin_widget_toggle (XfceAppfinderPlugin  *plugin,
+                                     gboolean              visible)
 {
   GError      *error = NULL;
   gboolean     succeeded;
   gint         x, y;
 
   appfinder_return_if_fail (XFCE_IS_APPFINDER_PLUGIN (plugin));
-  appfinder_return_if_fail (button == NULL || plugin->button == button);
 
-  if (plugin->busy > 0)
+  if (plugin->busy > 0 || plugin->visible == visible)
     return;
 
   plugin->busy += 1;
 
-  APPFINDER_DEBUG ("button pressed %d", plugin->busy);
-
-  plugin->visible = !plugin->visible;
+  plugin->visible = visible;
 
-  if (button != NULL)
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), plugin->visible);
+  if (plugin->button != NULL)
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button), visible);
 
-  if (plugin->visible)
+  if (visible)
     {
       if (plugin->appfinder_window == NULL)
         xfce_appfinder_plugin_create_window (plugin);
@@ -447,8 +449,8 @@ xfce_appfinder_plugin_activate (GtkWidget            *button,
           return;
         }
 
-      if (plugin->visible)
-        gtk_widget_set_visible (plugin->appfinder_window, plugin->visible);
+      if (visible)
+        gtk_widget_set_visible (plugin->appfinder_window, visible);
     }
   else
     {
@@ -459,7 +461,26 @@ xfce_appfinder_plugin_activate (GtkWidget            *button,
 
 }
 
+static gboolean
+xfce_appfinder_plugin_button_pressed (GtkWidget            *button,
+                                      GdkEventButton       *event,
+                                      XfceAppfinderPlugin  *plugin)
+{
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_PLUGIN (plugin), FALSE);
+  appfinder_return_val_if_fail (button == NULL || plugin->button == button, FALSE);
+
+  if (event != NULL
+      && !(event->button == 1
+           && event->type == GDK_BUTTON_PRESS))
+    //&& !PANEL_HAS_FLAG (event->state, GDK_CONTROL_MASK)))
+    return FALSE;
+
+  APPFINDER_DEBUG ("button pressed %d", plugin->busy);
 
+  xfce_appfinder_plugin_widget_toggle (plugin, !plugin->visible);
+
+  return TRUE;
+}
 
 
 
@@ -552,6 +573,34 @@ xfce_appfinder_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
 
 
 
+static gboolean
+xfce_appfinder_plugin_remote_event (XfcePanelPlugin *panel_plugin,
+                                    const gchar     *name,
+                                    const GValue    *value)
+{
+  XfceAppfinderPlugin *plugin = XFCE_APPFINDER_PLUGIN (panel_plugin);
+
+  appfinder_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
+
+  APPFINDER_DEBUG ("remote event %s", name);
+
+  if (exo_str_is_equal (name, "popup")
+      && GTK_WIDGET_VISIBLE (panel_plugin)
+      && !plugin->visible)
+      //&& panel_utils_grab_available ())
+    {
+      /* show the widget at the button */
+      xfce_appfinder_plugin_widget_toggle (plugin, TRUE);
+
+      /* don't popup another widget */
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+
+
 static void
 xfce_appfinder_plugin_free_data (XfcePanelPlugin *panel_plugin)
 {
diff --git a/panel-plugin/xfce4-popup-appfinder.sh b/panel-plugin/xfce4-popup-appfinder.sh
new file mode 100644
index 0000000..a0000d1
--- /dev/null
+++ b/panel-plugin/xfce4-popup-appfinder.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# Copyright (C) 2010 Nick Schermer <nick at xfce.org>
+#
+# 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
+    ;;
+esac
+
+exec @bindir@/xfce4-panel --plugin-event=xfce4-appfinder-plugin:popup
+
+# vim:set ts=2 sw=2 et ai:


More information about the Xfce4-commits mailing list