Browse Source

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.
upstream/xfce4-panel-4.10.1
Nick Schermer 13 years ago
parent
commit
e3178fa31b
  1. 51
      common/panel-utils.c
  2. 16
      common/panel-utils.h
  3. 3
      plugins/applicationsmenu/applicationsmenu.c
  4. 3
      plugins/directorymenu/directorymenu.c
  5. 3
      plugins/windowmenu/windowmenu.c

51
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;
}

16
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__ */

3
plugins/applicationsmenu/applicationsmenu.c

@ -547,7 +547,8 @@ applications_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
&& g_value_get_boolean (value))
{
/* show menu under cursor */
applications_menu_plugin_menu (NULL, plugin);
if (panel_utils_grab_available ())
applications_menu_plugin_menu (NULL, plugin);
}
else
{

3
plugins/directorymenu/directorymenu.c

@ -462,7 +462,8 @@ directory_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
&& g_value_get_boolean (value))
{
/* popup the menu under the pointer */
directory_menu_plugin_menu (NULL, plugin);
if (panel_utils_grab_available ())
directory_menu_plugin_menu (NULL, plugin);
}
else
{

3
plugins/windowmenu/windowmenu.c

@ -589,7 +589,8 @@ window_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
&& g_value_get_boolean (value))
{
/* popup the menu under the pointer */
window_menu_plugin_menu (NULL, plugin);
if (panel_utils_grab_available ())
window_menu_plugin_menu (NULL, plugin);
}
else
{

Loading…
Cancel
Save