[gtk+] GtkMenuShell: take a single device for grabs.



commit 404f4c5d40c2ebf31da41144154abbc27de642a5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 16 01:09:41 2010 +0200

    GtkMenuShell: take a single device for grabs.
    
    The other device will always be the associated device.

 gtk/gtkmenu.c      |   34 ++++++++++++++++++----------------
 gtk/gtkmenushell.c |   49 +++++++++++++++++++++++++------------------------
 gtk/gtkmenushell.h |    9 +++------
 3 files changed, 46 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index e999994..9715b78 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -1528,7 +1528,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
     {
       if (popup_grab_on_window (xgrab_shell->window, keyboard, pointer, activate_time))
         {
-          _gtk_menu_shell_set_grab_devices (GTK_MENU_SHELL (xgrab_shell), keyboard, pointer);
+          _gtk_menu_shell_set_grab_device (GTK_MENU_SHELL (xgrab_shell), pointer);
           GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
         }
     }
@@ -1540,7 +1540,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
       transfer_window = menu_grab_transfer_window_get (menu);
       if (popup_grab_on_window (transfer_window, keyboard, pointer, activate_time))
         {
-          _gtk_menu_shell_set_grab_devices (GTK_MENU_SHELL (xgrab_shell), keyboard, pointer);
+          _gtk_menu_shell_set_grab_device (GTK_MENU_SHELL (xgrab_shell), pointer);
           GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
         }
     }
@@ -1556,7 +1556,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
       return;
     }
 
-  _gtk_menu_shell_set_grab_devices (GTK_MENU_SHELL (menu), keyboard, pointer);
+  _gtk_menu_shell_set_grab_device (GTK_MENU_SHELL (menu), pointer);
   menu_shell->active = TRUE;
   menu_shell->button = button;
 
@@ -1771,6 +1771,8 @@ gtk_menu_popdown (GtkMenu *menu)
   gtk_widget_hide (menu->toplevel);
   gtk_window_set_transient_for (GTK_WINDOW (menu->toplevel), NULL);
 
+  pointer = _gtk_menu_shell_get_grab_device (menu_shell);
+
   if (menu->torn_off)
     {
       gtk_widget_set_size_request (menu->tearoff_window, -1, -1);
@@ -1781,17 +1783,19 @@ gtk_menu_popdown (GtkMenu *menu)
 	} 
       else
 	{
-          GdkDevice *keyboard, *pointer;
-
           /* We popped up the menu from the tearoff, so we need to
 	   * release the grab - we aren't actually hiding the menu.
 	   */
-	  if (menu_shell->have_xgrab &&
-              _gtk_menu_shell_get_grab_devices (menu_shell, &keyboard, &pointer))
-	    {
-	      gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);
-	      gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
-	    }
+	  if (menu_shell->have_xgrab && pointer)
+            {
+              GdkDevice *keyboard;
+
+              gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
+              keyboard = gdk_device_get_associated_device (pointer);
+
+              if (keyboard)
+                gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);
+            }
 	}
 
       /* gtk_menu_popdown is called each time a menu item is selected from
@@ -1807,12 +1811,10 @@ gtk_menu_popdown (GtkMenu *menu)
 
   menu_shell->have_xgrab = FALSE;
 
-  _gtk_menu_shell_get_grab_devices (menu_shell, NULL, &pointer);
-
   if (pointer)
     gtk_device_grab_remove (GTK_WIDGET (menu), pointer);
 
-  _gtk_menu_shell_set_grab_devices (menu_shell, NULL, NULL);
+  _gtk_menu_shell_set_grab_device (menu_shell, NULL);
 
   menu_grab_transfer_window_destroy (menu);
 }
@@ -4333,7 +4335,7 @@ gtk_menu_position (GtkMenu *menu)
   widget = GTK_WIDGET (menu);
 
   screen = gtk_widget_get_screen (widget);
-  _gtk_menu_shell_get_grab_devices (GTK_MENU_SHELL (menu), NULL, &pointer);
+  pointer = _gtk_menu_shell_get_grab_device (GTK_MENU_SHELL (menu));
   gdk_display_get_device_state (gdk_screen_get_display (screen),
                                 pointer, &pointer_screen, &x, &y, NULL);
 
@@ -5452,7 +5454,7 @@ gtk_menu_grab_notify (GtkWidget *widget,
   GtkWidget *grab;
   GdkDevice *pointer;
 
-  _gtk_menu_shell_get_grab_devices (GTK_MENU_SHELL (widget), NULL, &pointer);
+  pointer = _gtk_menu_shell_get_grab_device (GTK_MENU_SHELL (widget));
 
   if (!pointer ||
       !gtk_widget_device_is_shadowed (widget, pointer))
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 615f9a4..f4cdc46 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -135,7 +135,6 @@ struct _GtkMenuShellPrivate
   GtkMnemonicHash *mnemonic_hash;
   GtkKeyHash *key_hash;
 
-  GdkDevice *grab_keyboard;
   GdkDevice *grab_pointer;
 
   guint take_focus : 1;
@@ -1097,12 +1096,16 @@ gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell)
 	}
       if (menu_shell->have_xgrab)
 	{
+          GdkDevice *keyboard;
+
           gdk_device_ungrab (priv->grab_pointer, GDK_CURRENT_TIME);
-          gdk_device_ungrab (priv->grab_keyboard, GDK_CURRENT_TIME);
+          keyboard = gdk_device_get_associated_device (priv->grab_pointer);
+
+          if (keyboard)
+            gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);
 
-	  menu_shell->have_xgrab = FALSE;
-          priv->grab_pointer = NULL;
-          priv->grab_keyboard = NULL;
+          menu_shell->have_xgrab = FALSE;
+          _gtk_menu_shell_set_grab_device (menu_shell, NULL);
 	}
 
       menu_shell->keyboard_mode = FALSE;
@@ -1752,36 +1755,34 @@ _gtk_menu_shell_remove_mnemonic (GtkMenuShell *menu_shell,
 }
 
 void
-_gtk_menu_shell_set_grab_devices (GtkMenuShell *menu_shell,
-                                  GdkDevice    *keyboard,
-                                  GdkDevice    *pointer)
+_gtk_menu_shell_set_grab_device (GtkMenuShell *menu_shell,
+                                 GdkDevice    *device)
 {
-  GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
+  GtkMenuShellPrivate *priv;
 
   g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
-  g_return_if_fail (!keyboard || GDK_IS_DEVICE (keyboard));
-  g_return_if_fail (!pointer || GDK_IS_DEVICE (pointer));
+  g_return_if_fail (!device || GDK_IS_DEVICE (device));
 
-  priv->grab_keyboard = keyboard;
-  priv->grab_pointer = pointer;
+  priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
+
+  if (!device)
+    priv->grab_pointer = NULL;
+  else if (device->source == GDK_SOURCE_KEYBOARD)
+    priv->grab_pointer = gdk_device_get_associated_device (device);
+  else
+    priv->grab_pointer = device;
 }
 
-gboolean
-_gtk_menu_shell_get_grab_devices (GtkMenuShell  *menu_shell,
-                                  GdkDevice    **keyboard,
-                                  GdkDevice    **pointer)
+GdkDevice *
+_gtk_menu_shell_get_grab_device (GtkMenuShell  *menu_shell)
 {
-  GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
+  GtkMenuShellPrivate *priv;
 
   g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), FALSE);
 
-  if (keyboard)
-    *keyboard = priv->grab_keyboard;
-
-  if (pointer)
-    *pointer = priv->grab_pointer;
+  priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
 
-  return TRUE;
+  return priv->grab_pointer;
 }
 
 /**
diff --git a/gtk/gtkmenushell.h b/gtk/gtkmenushell.h
index f8c5a32..d9b2307 100644
--- a/gtk/gtkmenushell.h
+++ b/gtk/gtkmenushell.h
@@ -119,12 +119,9 @@ void _gtk_menu_shell_select_last       (GtkMenuShell *menu_shell,
 void  _gtk_menu_shell_activate         (GtkMenuShell *menu_shell);
 gint  _gtk_menu_shell_get_popup_delay  (GtkMenuShell *menu_shell);
 
-void     _gtk_menu_shell_set_grab_devices (GtkMenuShell *menu_shell,
-                                           GdkDevice    *keyboard,
-                                           GdkDevice    *pointer);
-gboolean _gtk_menu_shell_get_grab_devices (GtkMenuShell  *menu_shell,
-                                           GdkDevice    **keyboard,
-                                           GdkDevice    **pointer);
+void        _gtk_menu_shell_set_grab_device (GtkMenuShell *menu_shell,
+                                             GdkDevice    *device);
+GdkDevice * _gtk_menu_shell_get_grab_device (GtkMenuShell *menu_shell);
 
 void  gtk_menu_shell_cancel            (GtkMenuShell *menu_shell);
 



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