[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 337/473: Add waiting for grabs; allows modifier as shortcut. Closes #64.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:58:27 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit 4d2737d66438de9a3179dd20633ce22291aeb990
Author: Kernc <kerncece at gmail.com>
Date: Thu Jan 23 06:13:28 2014 +0100
Add waiting for grabs; allows modifier as shortcut. Closes #64.
---
panel-plugin/plugin.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index 18d3c1d..2ffbb6f 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -27,6 +27,7 @@
extern "C"
{
#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
}
using namespace WhiskerMenu;
@@ -45,6 +46,52 @@ static void whiskermenu_free(XfcePanelPlugin*, Plugin* whiskermenu)
whiskermenu = NULL;
}
+// Wait for grab; allows modifier as shortcut
+// Adapted from http://git.xfce.org/xfce/xfce4-panel/tree/common/panel-utils.c#n122
+static bool panel_utils_grab_available()
+{
+ bool grab_succeed = false;
+
+ // Don't try to get the grab for longer then 1/4 second
+ GdkWindow* root = gdk_screen_get_root_window(xfce_gdk_screen_get_active(NULL));
+ GdkGrabStatus grab_pointer = GDK_GRAB_FROZEN;
+ GdkGrabStatus grab_keyboard = GDK_GRAB_FROZEN;
+ for (guint i = 0; i < (G_USEC_PER_SEC / 4 / 100); ++i)
+ {
+ grab_keyboard = gdk_keyboard_grab(root, true, GDK_CURRENT_TIME);
+ if (grab_keyboard == GDK_GRAB_SUCCESS)
+ {
+ const GdkEventMask pointer_mask = static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK);
+ 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 menu window 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("xfce4-whiskermenu-plugin: Unable to get keyboard and mouse grab. Menu popup failed.\n");
+ }
+
+ return grab_succeed;
+}
+
//-----------------------------------------------------------------------------
Plugin::Plugin(XfcePanelPlugin* plugin) :
@@ -300,7 +347,7 @@ void Plugin::orientation_changed(XfcePanelPlugin*, GtkOrientation orientation)
gboolean Plugin::remote_event(XfcePanelPlugin*, gchar* name, GValue* value)
{
- if (strcmp(name, "popup"))
+ if (strcmp(name, "popup") || !panel_utils_grab_available())
{
return false;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list