[Xfce4-commits] [panel-plugins/xfce4-clipman-plugin] 09/15: Use gtk_grab_add instead of g_usleep
noreply at xfce.org
noreply at xfce.org
Wed Jun 1 22:40:02 CEST 2016
This is an automated email from the git hooks/post-receive script.
schuellerf pushed a commit to branch master
in repository panel-plugins/xfce4-clipman-plugin.
commit 2172adab20bdb6e11bd2204e6bf76813eeee860b
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Tue May 31 16:01:28 2016 +0300
Use gtk_grab_add instead of g_usleep
Additionally, do the work to support grabs with Gtk 3.20.
---
panel-plugin/actions.c | 15 +++++-
panel-plugin/collector.c | 7 ++-
panel-plugin/main-status-icon.c | 7 ++-
panel-plugin/plugin.c | 73 ++++++++++++++++++---------
x11-clipboard-manager/gsd-clipboard-manager.c | 7 ++-
5 files changed, 81 insertions(+), 28 deletions(-)
diff --git a/panel-plugin/actions.c b/panel-plugin/actions.c
index 032bee1..a8890eb 100644
--- a/panel-plugin/actions.c
+++ b/panel-plugin/actions.c
@@ -689,8 +689,13 @@ clipman_actions_match_with_menu (ClipmanActions *actions,
GSList *l, *entries;
GdkModifierType state = 0;
GdkDisplay* display = gdk_display_get_default ();
+#if GTK_CHECK_VERSION (3, 20, 0)
+ GdkSeat *seat = gdk_display_get_default_seat (display);
+ GdkDevice *device = gdk_seat_get_pointer (seat);
+#else
GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
- GdkDevice* device = gdk_device_manager_get_client_pointer (device_manager);
+ GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);
+#endif
GdkScreen* screen = gdk_screen_get_default ();
GdkWindow * root_win = gdk_screen_get_root_window (screen);
@@ -760,7 +765,13 @@ clipman_actions_match_with_menu (ClipmanActions *actions,
gtk_container_add (GTK_CONTAINER (actions->priv->menu), mi);
gtk_widget_show_all (actions->priv->menu);
- usleep(100000);
+
+ if(!gtk_widget_has_grab(actions->priv->menu))
+ {
+ gtk_grab_add(actions->priv->menu);
+ }
+
+
gtk_menu_popup (GTK_MENU (actions->priv->menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
g_slist_free (entries);
diff --git a/panel-plugin/collector.c b/panel-plugin/collector.c
index 74af711..3d66850 100644
--- a/panel-plugin/collector.c
+++ b/panel-plugin/collector.c
@@ -147,8 +147,13 @@ cb_check_primary_clipboard (ClipmanCollector *collector)
{
GdkModifierType state = 0;
GdkDisplay* display = gdk_display_get_default ();
+#if GTK_CHECK_VERSION (3, 20, 0)
+ GdkSeat *seat = gdk_display_get_default_seat (display);
+ GdkDevice *device = gdk_seat_get_pointer (seat);
+#else
GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
- GdkDevice* device = gdk_device_manager_get_client_pointer (device_manager);
+ GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);
+#endif
GdkScreen* screen = gdk_screen_get_default ();
GdkWindow * root_win = gdk_screen_get_root_window (screen);
diff --git a/panel-plugin/main-status-icon.c b/panel-plugin/main-status-icon.c
index c51ef00..335dbbf 100644
--- a/panel-plugin/main-status-icon.c
+++ b/panel-plugin/main-status-icon.c
@@ -150,7 +150,12 @@ cb_status_icon_popup_menu (MyPlugin *plugin, guint button, guint activate_time)
}
gtk_menu_set_screen (GTK_MENU (plugin->popup_menu), gtk_status_icon_get_screen (plugin->status_icon));
- usleep(100000);
+
+ if(!gtk_widget_has_grab(plugin->popup_menu))
+ {
+ gtk_grab_add(plugin->popup_menu);
+ }
+
gtk_menu_popup (GTK_MENU (plugin->popup_menu), NULL, NULL,
(GtkMenuPositionFunc)gtk_status_icon_position_menu, plugin->status_icon,
0, gtk_get_current_event_time ());
diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c
index 26b176a..8f89b45 100644
--- a/panel-plugin/plugin.c
+++ b/panel-plugin/plugin.c
@@ -353,7 +353,12 @@ plugin_popup_menu (MyPlugin *plugin)
{
#ifdef PANEL_PLUGIN
gtk_menu_set_screen (GTK_MENU (plugin->menu), gtk_widget_get_screen (plugin->button));
- usleep(100000);
+
+ if(!gtk_widget_has_grab(plugin->menu))
+ {
+ gtk_grab_add(plugin->menu);
+ }
+
gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL,
plugin->menu_position_func, plugin,
0, gtk_get_current_event_time ());
@@ -363,7 +368,12 @@ plugin_popup_menu (MyPlugin *plugin)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_menu_set_screen (GTK_MENU (plugin->menu), gtk_status_icon_get_screen (plugin->status_icon));
G_GNUC_END_IGNORE_DEPRECATIONS
- usleep(100000);
+
+ if(!gtk_widget_has_grab(plugin->menu))
+ {
+ gtk_grab_add(plugin->menu);
+ }
+
gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL,
plugin->menu_position_func, plugin->status_icon,
0, gtk_get_current_event_time ());
@@ -453,7 +463,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
if (xfconf_channel_get_bool (plugin->channel, "/tweaks/popup-at-pointer", FALSE))
{
- usleep(100000);
gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL, NULL, NULL,
0, gtk_get_current_event_time ());
}
@@ -472,6 +481,16 @@ G_GNUC_END_IGNORE_DEPRECATIONS
return FALSE;
}
+#if GTK_CHECK_VERSION (3, 20, 0)
+static void
+make_window_visible (GdkSeat *seat,
+ GdkWindow *window,
+ gpointer user_data)
+{
+ gdk_window_show (window);
+}
+#endif
+
/* Code taken from xfwm4/src/menu.c:grab_available(). This should fix the case
* where binding 'xfdesktop -menu' to a keyboard shortcut sometimes works and
* sometimes doesn't. Credit for this one goes to Olivier.
@@ -479,32 +498,40 @@ G_GNUC_END_IGNORE_DEPRECATIONS
static gboolean
xfce_popup_grab_available (GdkWindow *win, guint32 timestamp)
{
- GdkEventMask mask =
- GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
- GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
- GDK_POINTER_MOTION_MASK;
GdkDisplay* display = gdk_window_get_display(win);
- GdkDeviceManager *device_manager = gdk_display_get_device_manager(display);
- GdkDevice* device = gdk_device_manager_get_client_pointer(device_manager);
- GdkGrabStatus g;
- gboolean grab_failed = FALSE;
+#if GTK_CHECK_VERSION (3, 20, 0)
+ GdkSeat *seat = gdk_display_get_default_seat (display);
+#else
+ GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
+ GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);
+#endif
+ GdkGrabStatus g = GDK_GRAB_ALREADY_GRABBED;
+ gboolean grab_failed = TRUE;
gint i = 0;
TRACE ("entering grab_available");
- g = gdk_device_grab (device, win, GDK_OWNERSHIP_WINDOW, TRUE, mask, NULL, timestamp);
-
- while ((i++ < 2500) && (grab_failed = (g != GDK_GRAB_SUCCESS)))
- {
- TRACE ("grab not available yet, waiting... (%i)", i);
- g_usleep (100);
- if (g != GDK_GRAB_SUCCESS)
- g = gdk_device_grab (device, win, GDK_OWNERSHIP_WINDOW, TRUE, mask, NULL, timestamp);
- }
-
- if (g == GDK_GRAB_SUCCESS)
+ /* With a keyboard grab elsewhere, we have to wait on that to clear.
+ * So try up to 2500 times and only keep trying when the failure is
+ * already grabbed, any other failure mode will never succeed.
+ */
+ while ((i++ < 2500) && grab_failed && g == GDK_GRAB_ALREADY_GRABBED)
{
- gdk_device_ungrab (device, timestamp);
+#if GTK_CHECK_VERSION (3, 20, 0)
+ g = gdk_seat_grab(seat, win, GDK_SEAT_CAPABILITY_KEYBOARD, TRUE, NULL, NULL, make_window_visible, NULL);
+ if (g == GDK_GRAB_SUCCESS)
+ {
+ gdk_seat_ungrab (seat);
+ grab_failed = FALSE;
+ }
+#else
+ g = gdk_device_grab(device, win, GDK_KEY_PRESS_MASK, TRUE, mask, NULL, timestamp);
+ if (g == GDK_GRAB_SUCCESS)
+ {
+ gdk_device_ungrab(device, timestamp);
+ grab_failed = FALSE;
+ }
+#endif
}
return (!grab_failed);
diff --git a/x11-clipboard-manager/gsd-clipboard-manager.c b/x11-clipboard-manager/gsd-clipboard-manager.c
index 892b262..3cff437 100644
--- a/x11-clipboard-manager/gsd-clipboard-manager.c
+++ b/x11-clipboard-manager/gsd-clipboard-manager.c
@@ -215,8 +215,13 @@ primary_clipboard_store (GsdClipboardManager *manager)
GdkModifierType state;
gchar *text;
GdkDisplay* display = gdk_display_get_default ();
+#if GTK_CHECK_VERSION (3, 20, 0)
+ GdkSeat *seat = gdk_display_get_default_seat (display);
+ GdkDevice *device = gdk_seat_get_pointer (seat);
+#else
GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
- GdkDevice* device = gdk_device_manager_get_client_pointer (device_manager);
+ GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);
+#endif
gdk_window_get_device_position (NULL, device, NULL, NULL, &state);
if (state & (GDK_BUTTON1_MASK|GDK_SHIFT_MASK)) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list