summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorNick Schermer <nick@xfce.org>2010-02-26 14:08:35 +0100
committerNick Schermer <nick@xfce.org>2010-02-26 14:11:57 +0100
commite3178fa31b88c29306d6d892ea36ba79c74412aa (patch)
tree0e4ba653d5b21f238630d6d1ed2f1057e58ba572 /common
parent5362a49a7129e15763689c205dc1c8fd6ba2bf8d (diff)
downloadxfce4-panel-e3178fa31b88c29306d6d892ea36ba79c74412aa.tar.gz
Wait for grab when running popup menus at pointer.
Popup scripts doesn't really work if we don't wait until the pointer and keyboard grab is available.
Diffstat (limited to 'common')
-rw-r--r--common/panel-utils.c51
-rw-r--r--common/panel-utils.h16
2 files changed, 60 insertions, 7 deletions
diff --git a/common/panel-utils.c b/common/panel-utils.c
index b90541c5..6c958053 100644
--- a/common/panel-utils.c
+++ b/common/panel-utils.c
@@ -174,3 +174,54 @@ panel_utils_show_help (GtkWindow *parent,
g_free (uri);
}
+
+
+
+gboolean
+panel_utils_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;
+}
diff --git a/common/panel-utils.h b/common/panel-utils.h
index b10565be..79c3ee3b 100644
--- a/common/panel-utils.h
+++ b/common/panel-utils.h
@@ -27,13 +27,15 @@
if (xfce_titled_dialog_get_type () == 0) \
return;
-GtkBuilder *panel_utils_builder_new (XfcePanelPlugin *panel_plugin,
- const gchar *buffer,
- gsize length,
- GObject **dialog_return) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GtkBuilder *panel_utils_builder_new (XfcePanelPlugin *panel_plugin,
+ const gchar *buffer,
+ gsize length,
+ GObject **dialog_return) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-void panel_utils_show_help (GtkWindow *parent,
- const gchar *page,
- const gchar *offset);
+void panel_utils_show_help (GtkWindow *parent,
+ const gchar *page,
+ const gchar *offset);
+
+gboolean panel_utils_grab_available (void);
#endif /* !__PANEL_BUILDER_H__ */