gtkbutton: Avoid keyboard grabs
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 18 Aug 2017 17:16:19 +0000 (19:16 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Fri, 18 Aug 2017 18:45:07 +0000 (20:45 +0200)
Seems to be there for the sole purpose of ensuring the button
shall receive the key release on keyboard-triggered activation.

For the cases where this makes sense (eg. comboboxes, menubuttons,
...) gtk+ already does ensure the menu is popup after key release.
This makes the grab pretty useless, and there's many other cases
where it doesn't make sense (eg. button being activated
programmatically from an event handler in another widget).

Fixes button activation unintendedly triggering shortcut inhibition
on wayland.

https://bugzilla.gnome.org/show_bug.cgi?id=786480

gtk/gtkbutton.c
gtk/gtkbuttonprivate.h

index 57d04ef036fa6da8f48ffc86f239327f5cc9c85f..b39d55b408897add0a837d13be95fc7f8b33e2c8 100644 (file)
@@ -1990,7 +1990,6 @@ gtk_real_button_activate (GtkButton *button)
   GtkWidget *widget = GTK_WIDGET (button);
   GtkButtonPrivate *priv = button->priv;
   GdkDevice *device;
-  guint32 time;
 
   device = gtk_get_current_event_device ();
 
@@ -1999,21 +1998,13 @@ gtk_real_button_activate (GtkButton *button)
 
   if (gtk_widget_get_realized (widget) && !priv->activate_timeout)
     {
-      time = gtk_get_current_event_time ();
-
       /* bgo#626336 - Only grab if we have a device (from an event), not if we
        * were activated programmatically when no event is available.
        */
       if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
        {
-          if (gdk_seat_grab (gdk_device_get_seat (device), priv->event_window,
-                             GDK_SEAT_CAPABILITY_KEYBOARD, TRUE,
-                             NULL, NULL, NULL, NULL) == GDK_GRAB_SUCCESS)
-            {
-              gtk_device_grab_add (widget, device, TRUE);
-              priv->grab_keyboard = device;
-              priv->grab_time = time;
-           }
+          gtk_device_grab_add (widget, device, TRUE);
+          priv->grab_keyboard = device;
        }
 
       priv->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT,
@@ -2037,7 +2028,6 @@ gtk_button_finish_activate (GtkButton *button,
 
   if (priv->grab_keyboard)
     {
-      gdk_seat_ungrab (gdk_device_get_seat (priv->grab_keyboard));
       gtk_device_grab_remove (widget, priv->grab_keyboard);
       priv->grab_keyboard = NULL;
     }
index 5114a9926b9254451168b9fc9e8704f27b9fc5e8..b9bb219aa288857ac5b73e7e3ea5d883be37a3b5 100644 (file)
@@ -48,7 +48,6 @@ struct _GtkButtonPrivate
   gfloat                 baseline_align;
 
   guint                  activate_timeout;
-  guint32                grab_time;
 
   GtkPositionType        image_position;