[mutter/wip/carlosg/xwayland-on-demand: 4/18] x11: Move focus sentinel to MetaX11Display



commit 3be68bad3a41f3b1df62c9165c5edba9206b1f39
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Dec 30 12:58:31 2018 +0100

    x11: Move focus sentinel to MetaX11Display
    
    This focus sentinel is a mechanism to avoid some X11-specific race
    conditions in focus-follows-pointer, using X11 mechanisms. Move it to
    MetaX11Display altogether.

 src/core/display-private.h         |  8 --------
 src/core/display.c                 | 32 --------------------------------
 src/core/window.c                  | 10 ++++++----
 src/x11/events.c                   |  4 ++--
 src/x11/meta-x11-display-private.h |  9 +++++++++
 src/x11/meta-x11-display.c         | 31 +++++++++++++++++++++++++++++++
 6 files changed, 48 insertions(+), 46 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 58603d1a7..d9846ecff 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -200,10 +200,6 @@ struct _MetaDisplay
   MetaEdgeResistanceData *grab_edge_resistance_data;
   unsigned int grab_last_user_action_was_snap;
 
-  /* we use property updates as sentinels for certain window focus events
-   * to avoid some race conditions on EnterNotify events
-   */
-  int         sentinel_counter;
   int        grab_resize_timeout_id;
 
   MetaKeyBindingManager key_binding_manager;
@@ -355,10 +351,6 @@ gboolean meta_grab_op_is_resizing (MetaGrabOp op);
 gboolean meta_grab_op_is_mouse    (MetaGrabOp op);
 gboolean meta_grab_op_is_keyboard (MetaGrabOp op);
 
-void meta_display_increment_focus_sentinel (MetaDisplay *display);
-void meta_display_decrement_focus_sentinel (MetaDisplay *display);
-gboolean meta_display_focus_sentinel_clear (MetaDisplay *display);
-
 void meta_display_queue_autoraise_callback  (MetaDisplay *display,
                                              MetaWindow  *window);
 void meta_display_remove_autoraise_callback (MetaDisplay *display);
diff --git a/src/core/display.c b/src/core/display.c
index 8dd9b4de0..9742763a0 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -682,7 +682,6 @@ meta_display_open (void)
     }
 
   display->current_time = META_CURRENT_TIME;
-  display->sentinel_counter = 0;
 
   display->grab_resize_timeout_id = 0;
   display->grab_have_keyboard = FALSE;
@@ -2484,37 +2483,6 @@ prefs_changed_callback (MetaPreference pref,
     }
 }
 
-void
-meta_display_increment_focus_sentinel (MetaDisplay *display)
-{
-  unsigned long data[1];
-
-  data[0] = meta_display_get_current_time (display);
-
-  XChangeProperty (display->x11_display->xdisplay,
-                   display->x11_display->xroot,
-                   display->x11_display->atom__MUTTER_SENTINEL,
-                   XA_CARDINAL,
-                   32, PropModeReplace, (guchar*) data, 1);
-
-  display->sentinel_counter += 1;
-}
-
-void
-meta_display_decrement_focus_sentinel (MetaDisplay *display)
-{
-  display->sentinel_counter -= 1;
-
-  if (display->sentinel_counter < 0)
-    display->sentinel_counter = 0;
-}
-
-gboolean
-meta_display_focus_sentinel_clear (MetaDisplay *display)
-{
-  return (display->sentinel_counter == 0);
-}
-
 void
 meta_display_sanity_check_timestamps (MetaDisplay *display,
                                       guint32      timestamp)
diff --git a/src/core/window.c b/src/core/window.c
index 3018c1b7b..ad7473229 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1893,9 +1893,10 @@ idle_calc_showing (gpointer data)
       while (tmp != NULL)
         {
           MetaWindow *window = tmp->data;
+          MetaDisplay *display = window->display;
 
-          if (!window->display->mouse_mode)
-            meta_display_increment_focus_sentinel (window->display);
+          if (display->x11_display && !display->mouse_mode)
+            meta_x11_display_increment_focus_sentinel (display->x11_display);
 
           tmp = tmp->next;
         }
@@ -2365,6 +2366,7 @@ meta_window_show (MetaWindow *window)
   gboolean needs_stacking_adjustment;
   MetaWindow *focus_window;
   gboolean notify_demands_attention = FALSE;
+  MetaDisplay *display = window->display;
 
   meta_topic (META_DEBUG_WINDOW_STATE,
               "Showing window %s, shaded: %d iconic: %d placed: %d\n",
@@ -2531,7 +2533,7 @@ meta_window_show (MetaWindow *window)
 
           meta_window_focus (window, timestamp);
         }
-      else
+      else if (display->x11_display)
         {
           /* Prevent EnterNotify events in sloppy/mouse focus from
            * erroneously focusing the window that had been denied
@@ -2539,7 +2541,7 @@ meta_window_show (MetaWindow *window)
            * ideas for a better way to accomplish the same thing, but
            * they're more involved so do it this way for now.
            */
-          meta_display_increment_focus_sentinel (window->display);
+          meta_x11_display_increment_focus_sentinel (display->x11_display);
         }
     }
 
diff --git a/src/x11/events.c b/src/x11/events.c
index 92b5d7015..5fdff162c 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -882,7 +882,7 @@ handle_input_xevent (MetaX11Display *x11_display,
           enter_event->mode != XINotifyGrab &&
           enter_event->mode != XINotifyUngrab &&
           enter_event->detail != XINotifyInferior &&
-          meta_display_focus_sentinel_clear (display))
+          meta_x11_display_focus_sentinel_clear (x11_display))
         {
           meta_window_handle_enter (window,
                                     enter_event->time,
@@ -1525,7 +1525,7 @@ handle_other_xevent (MetaX11Display *x11_display,
             if (event->xproperty.atom ==
                 x11_display->atom__MUTTER_SENTINEL)
               {
-                meta_display_decrement_focus_sentinel (display);
+                meta_x11_display_decrement_focus_sentinel (x11_display);
               }
           }
       }
diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h
index 708e23e69..7e4df4996 100644
--- a/src/x11/meta-x11-display-private.h
+++ b/src/x11/meta-x11-display-private.h
@@ -132,6 +132,11 @@ struct _MetaX11Display
     GList *output_streams;
   } selection;
 
+  /* we use property updates as sentinels for certain window focus events
+   * to avoid some race conditions on EnterNotify events
+   */
+  int sentinel_counter;
+
   guint keys_grabbed : 1;
 
   int composite_event_base;
@@ -218,4 +223,8 @@ MetaLogicalMonitor *meta_x11_display_xinerama_index_to_logical_monitor (MetaX11D
 void meta_x11_display_update_workspace_layout (MetaX11Display *x11_display);
 void meta_x11_display_update_workspace_names  (MetaX11Display *x11_display);
 
+void meta_x11_display_increment_focus_sentinel (MetaX11Display *x11_display);
+void meta_x11_display_decrement_focus_sentinel (MetaX11Display *x11_display);
+gboolean meta_x11_display_focus_sentinel_clear (MetaX11Display *x11_display);
+
 #endif /* META_X11_DISPLAY_PRIVATE_H */
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 233f8dce6..75e780c7b 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -2168,3 +2168,34 @@ prefs_changed_callback (MetaPreference pref,
       set_workspace_names (x11_display);
     }
 }
+
+void
+meta_x11_display_increment_focus_sentinel (MetaX11Display *x11_display)
+{
+  unsigned long data[1];
+
+  data[0] = meta_display_get_current_time (x11_display->display);
+
+  XChangeProperty (x11_display->xdisplay,
+                   x11_display->xroot,
+                   x11_display->atom__MUTTER_SENTINEL,
+                   XA_CARDINAL,
+                   32, PropModeReplace, (guchar*) data, 1);
+
+  x11_display->sentinel_counter += 1;
+}
+
+void
+meta_x11_display_decrement_focus_sentinel (MetaX11Display *x11_display)
+{
+  x11_display->sentinel_counter -= 1;
+
+  if (x11_display->sentinel_counter < 0)
+    x11_display->sentinel_counter = 0;
+}
+
+gboolean
+meta_x11_display_focus_sentinel_clear (MetaX11Display *x11_display)
+{
+  return (x11_display->sentinel_counter == 0);
+}


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