[mutter/wip/multitouch: 57/73] window: Make MetaWindow keep a pointer to the popup menu



commit 776628fde289747d4cd059761fef7d185b52197c
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 1 23:39:37 2011 +0200

    window: Make MetaWindow keep a pointer to the popup menu
    
    Multiple windows may now have different popup menus, responding
    only to the device pair that popped it up.

 src/core/core.c           |    8 +++++++-
 src/core/display.c        |   30 +++++++++++++++++++++++++-----
 src/core/keybindings.c    |    3 ++-
 src/core/window-private.h |    4 ++++
 src/core/window.c         |   30 ++++++++++++++++--------------
 5 files changed, 54 insertions(+), 21 deletions(-)
---
diff --git a/src/core/core.c b/src/core/core.c
index 6c80876..9ce271b 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -518,7 +518,13 @@ meta_core_show_window_menu (Display *xdisplay,
                             guint32  timestamp)
 {
   MetaWindow *window = get_window (xdisplay, frame_xwindow);
-  
+
+  /* There is already a menu popped up,
+   * most likely from another device
+   */
+  if (window->menu)
+    return;
+
   if (meta_prefs_get_raise_on_click ())
     meta_window_raise (window);
   meta_window_focus (window, timestamp);
diff --git a/src/core/display.c b/src/core/display.c
index 92595f1..b506832 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -522,9 +522,6 @@ meta_display_open (void)
 
   the_display->groups_by_leader = NULL;
 
-  the_display->window_with_menu = NULL;
-  the_display->window_menu = NULL;
-  
   the_display->screens = NULL;
   the_display->active_screen = NULL;
   
@@ -1967,7 +1964,8 @@ event_callback (XEvent   *event,
                                                     ev_root_y);
                     }
                 }
-              else if (n_button == meta_prefs_get_mouse_button_menu())
+              else if (!window->menu &&
+                       n_button == meta_prefs_get_mouse_button_menu())
                 {
                   if (meta_prefs_get_raise_on_click ())
                     meta_window_raise (window);
@@ -3609,7 +3607,29 @@ meta_display_begin_grab_op (MetaDisplay *display,
               root_x, root_y);
 
   grab_info = meta_display_get_grab_info (display, device);
-  
+
+  if (window && window->cur_grab &&
+      window->cur_grab != grab_info)
+    {
+      meta_verbose ("Attempt to perform window operation %u on window %s while"
+                    " operation %u is already in effect on the same window for"
+                    " the device pair %d/%d\n",
+                    op, window->desc, window->cur_grab->grab_op,
+                    meta_device_get_id (window->cur_grab->grab_pointer),
+                    meta_device_get_id (window->cur_grab->grab_keyboard));
+      return FALSE;
+    }
+
+  if (window && window->menu != NULL &&
+      window->menu_device != device)
+    {
+      meta_verbose ("Attempt to perform window operation %u on window %s while"
+                    " context menu is opened on that window for pointer %d\n",
+                    op, window->desc,
+                    meta_device_get_id (window->menu_device));
+      return FALSE;
+    }
+
   if (grab_info != NULL &&
       grab_info->grab_op != META_GRAB_OP_NONE)
     {
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 2c64eea..2f5535d 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -3181,7 +3181,8 @@ handle_activate_window_menu (MetaDisplay    *display,
   device = meta_input_event_get_device (display, event);
   focus_info = meta_display_get_focus_info (display, device);
 
-  if (focus_info->focus_window)
+  if (focus_info->focus_window &&
+      !focus_info->focus_window->menu)
     {
       Time evtime;
       int x, y;
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 1ab0ed7..65124db 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -107,6 +107,10 @@ struct _MetaWindow
   Window xgroup_leader;
   Window xclient_leader;
 
+  /* window menu if any, and the pointer that popped it up */
+  MetaWindowMenu *menu;
+  MetaDevice *menu_device;
+
   /* Initial workspace property */
   int initial_workspace;  
   
diff --git a/src/core/window.c b/src/core/window.c
index 73c7c79..b61212a 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -204,6 +204,9 @@ meta_window_finalize (GObject *object)
   if (window->frame_bounds)
     cairo_region_destroy (window->frame_bounds);
 
+  if (window->menu)
+    meta_ui_window_menu_free (window->menu);
+
   meta_icon_cache_free (&window->icon_cache);
 
   g_free (window->sm_client_id);
@@ -1574,9 +1577,9 @@ meta_window_unmanage (MetaWindow  *window,
 
   if (window->display->window_with_menu == window)
     {
-      meta_ui_window_menu_free (window->display->window_menu);
-      window->display->window_menu = NULL;
-      window->display->window_with_menu = NULL;
+      meta_ui_window_menu_free (window->menu);
+      window->menu_device = NULL;
+      window->menu = NULL;
     }
 
   if (destroying_windows_disallowed > 0)
@@ -8206,13 +8209,12 @@ menu_callback (MetaWindowMenu *menu,
       meta_verbose ("Menu callback on nonexistent window\n");
     }
 
-  if (display->window_menu == menu)
+  if (window && window->menu)
     {
-      display->window_menu = NULL;
-      display->window_with_menu = NULL;
+      meta_ui_window_menu_free (menu);
+      window->menu_device = NULL;
+      window->menu = NULL;
     }
-
-  meta_ui_window_menu_free (menu);
 }
 
 void
@@ -8231,11 +8233,11 @@ meta_window_show_menu (MetaWindow *window,
 
   g_return_if_fail (!window->override_redirect);
 
-  if (window->display->window_menu)
+  if (window->menu)
     {
-      meta_ui_window_menu_free (window->display->window_menu);
-      window->display->window_menu = NULL;
-      window->display->window_with_menu = NULL;
+      meta_ui_window_menu_free (window->menu);
+      window->menu_device = NULL;
+      window->menu = NULL;
     }
 
   ops = META_MENU_OP_NONE;
@@ -8342,8 +8344,8 @@ meta_window_show_menu (MetaWindow *window,
                              menu_callback,
                              NULL);
 
-  window->display->window_menu = menu;
-  window->display->window_with_menu = window;
+  window->menu_device = device;
+  window->menu = menu;
 
   meta_verbose ("Popping up window menu for %s\n", window->desc);
 



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