]> Pileus Git - ~andy/gtk/commitdiff
bgo#626336 - Don't assume that GtkButton is activated only when a keyboard event...
authorFederico Mena Quintero <federico@gnome.org>
Fri, 21 Jan 2011 19:36:27 +0000 (13:36 -0600)
committerFederico Mena Quintero <federico@gnome.org>
Fri, 21 Jan 2011 21:48:39 +0000 (15:48 -0600)
Buttons may also be activated at any time from gtk_widget_activate()
or related functions.  In that case, just do the 'show the button
as pushed for a short amount of time' trick, but don't actually
try to grab the keyboard device.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
gtk/gtkbutton.c

index 3d3bd8630c64e75eba2a01c101dd8cbba0350097..baad6ebf29c54d7568c3248223aee0b1280392d5 100644 (file)
@@ -1860,20 +1860,24 @@ gtk_real_button_activate (GtkButton *button)
   if (device && gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
     device = gdk_device_get_associated_device (device);
 
-  g_return_if_fail (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
-
   if (gtk_widget_get_realized (widget) && !priv->activate_timeout)
     {
       time = gtk_get_current_event_time ();
 
-      if (gdk_device_grab (device, priv->event_window,
-                           GDK_OWNERSHIP_WINDOW, TRUE,
-                           GDK_KEY_PRESS | GDK_KEY_RELEASE,
-                           NULL, time) == GDK_GRAB_SUCCESS)
-        {
-          gtk_device_grab_add (widget, device, TRUE);
-         priv->grab_keyboard = device;
-         priv->grab_time = 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_device_grab (device, priv->event_window,
+                              GDK_OWNERSHIP_WINDOW, TRUE,
+                              GDK_KEY_PRESS | GDK_KEY_RELEASE,
+                              NULL, time) == GDK_GRAB_SUCCESS)
+           {
+             gtk_device_grab_add (widget, device, TRUE);
+             priv->grab_keyboard = device;
+             priv->grab_time = time;
+           }
        }
 
       priv->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT,