[gtk+/xi2] GtkButton: Use GTK+ device grabs.



commit d80a19e5a40b6abb4c697f6c7999935a62d4731a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Mar 9 18:25:24 2010 +0100

    GtkButton: Use GTK+ device grabs.

 gtk/gtkbutton.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index bbfa83d..bec7a08 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1752,24 +1752,24 @@ gtk_real_button_activate (GtkButton *button)
   guint32 time;
 
   priv = GTK_BUTTON_GET_PRIVATE (button);
+  device = gtk_get_current_event_device ();
+
+  g_return_if_fail (device && device->source == GDK_SOURCE_KEYBOARD);
 
   if (GTK_WIDGET_REALIZED (button) && !button->activate_timeout)
     {
-      device = gtk_get_current_event_device ();
       time = gtk_get_current_event_time ();
 
-      if (device &&
-          gdk_device_grab (device, button->event_window,
+      if (gdk_device_grab (device, button->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;
 	}
 
-      gtk_grab_add (widget);
-      
       button->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT,
 						button_activate_timeout,
 						button);
@@ -1794,9 +1794,9 @@ gtk_button_finish_activate (GtkButton *button,
   if (priv->grab_keyboard)
     {
       gdk_device_ungrab (priv->grab_keyboard, priv->grab_time);
+      gtk_device_grab_remove (widget, priv->grab_keyboard);
       priv->grab_keyboard = NULL;
     }
-  gtk_grab_remove (widget);
 
   button->button_down = FALSE;
 
@@ -2197,8 +2197,14 @@ gtk_button_grab_notify (GtkWidget *widget,
 			gboolean   was_grabbed)
 {
   GtkButton *button = GTK_BUTTON (widget);
+  GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
   gboolean save_in;
 
+  if (button->activate_timeout &&
+      priv->grab_keyboard &&
+      gtk_widget_device_is_shadowed (widget, priv->grab_keyboard))
+    gtk_button_finish_activate (button, FALSE);
+
   if (!was_grabbed)
     {
       save_in = button->in_button;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]