[mutter] Prepare for making MetaX11Display conditional



commit 8e7e1eeef59c4f74046e6783b6334c1432255c5a
Author: Armin Krezović <krezovic armin gmail com>
Date:   Sat Aug 26 22:24:21 2017 +0200

    Prepare for making MetaX11Display conditional
    
    - Stop using CurrentTime, introduce META_CURRENT_TIME
    - Use g_get_monotonic_time () instead of relying on an
      X server running and making roundtrip to it
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759538

 src/backends/x11/meta-backend-x11.c   |  4 +--
 src/compositor/compositor.c           | 27 ++++++++++++--------
 src/core/display.c                    | 48 +++++++++++++++++++++--------------
 src/core/events.c                     |  4 +--
 src/core/main.c                       |  2 +-
 src/core/restart.c                    |  2 +-
 src/core/window.c                     |  2 +-
 src/core/workspace.c                  |  8 +++---
 src/meta/common.h                     |  3 +++
 src/wayland/meta-xwayland-selection.c |  8 +++---
 src/x11/events.c                      |  4 +--
 src/x11/meta-x11-display.c            |  2 +-
 12 files changed, 67 insertions(+), 47 deletions(-)
---
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 2b131d2d0..458ac92b0 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -176,7 +176,7 @@ translate_device_event (MetaBackendX11 *x11,
 
   meta_backend_x11_translate_device_event (x11, device_event);
 
-  if (!device_event->send_event && device_event->time != CurrentTime)
+  if (!device_event->send_event && device_event->time != META_CURRENT_TIME)
     {
       if (XSERVER_TIME_IS_BEFORE (device_event->time, priv->latest_evtime))
         {
@@ -547,7 +547,7 @@ meta_backend_x11_grab_device (MetaBackend *backend,
   XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
   int ret;
 
-  if (timestamp != CurrentTime)
+  if (timestamp != META_CURRENT_TIME)
     timestamp = MAX (timestamp, priv->latest_evtime);
 
   XISetMask (mask.mask, XI_ButtonPress);
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index b47c7cab3..e9cccd0f2 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -362,11 +362,14 @@ meta_begin_modal_for_plugin (MetaCompositor   *compositor,
   if (is_modal (display) || display->grab_op != META_GRAB_OP_NONE)
     return FALSE;
 
-  /* XXX: why is this needed? */
-  XIUngrabDevice (display->x11_display->xdisplay,
-                  META_VIRTUAL_CORE_POINTER_ID,
-                  timestamp);
-  XSync (display->x11_display->xdisplay, False);
+  if (display->x11_display)
+    {
+      /* XXX: why is this needed? */
+      XIUngrabDevice (display->x11_display->xdisplay,
+                      META_VIRTUAL_CORE_POINTER_ID,
+                      timestamp);
+      XSync (display->x11_display->xdisplay, False);
+    }
 
   if (!grab_devices (options, timestamp))
     return FALSE;
@@ -443,9 +446,8 @@ after_stage_paint (ClutterStage *stage,
 }
 
 static void
-redirect_windows (MetaDisplay *display)
+redirect_windows (MetaX11Display *x11_display)
 {
-  MetaX11Display *x11_display = meta_display_get_x11_display (display);
   Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
   Window xroot = meta_x11_display_get_xroot (x11_display);
   int screen_number = meta_x11_display_get_screen_number (x11_display);
@@ -489,10 +491,14 @@ void
 meta_compositor_manage (MetaCompositor *compositor)
 {
   MetaDisplay *display = compositor->display;
-  Display *xdisplay = display->x11_display->xdisplay;
+  Display *xdisplay = NULL;
   MetaBackend *backend = meta_get_backend ();
 
-  meta_x11_display_set_cm_selection (display->x11_display);
+  if (display->x11_display)
+    {
+      xdisplay = display->x11_display->xdisplay;
+      meta_x11_display_set_cm_selection (display->x11_display);
+    }
 
   compositor->stage = meta_backend_get_stage (backend);
 
@@ -558,7 +564,8 @@ meta_compositor_manage (MetaCompositor *compositor)
       compositor->have_x11_sync_object = meta_sync_ring_init (xdisplay);
     }
 
-  redirect_windows (display);
+  if (display->x11_display)
+    redirect_windows (display->x11_display);
 
   compositor->plugin_mgr = meta_plugin_manager_new (compositor);
 }
diff --git a/src/core/display.c b/src/core/display.c
index c58fc6306..1df7bdc65 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -595,21 +595,24 @@ enable_compositor (MetaDisplay *display)
 {
   MetaX11Display *x11_display = display->x11_display;
 
-  if (!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ||
-      !META_X11_DISPLAY_HAS_DAMAGE (x11_display))
+  if (x11_display)
     {
-      meta_warning ("Missing %s extension required for compositing",
-                    !META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ?
-                    "composite" : "damage");
-      return;
-    }
+      if (!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ||
+          !META_X11_DISPLAY_HAS_DAMAGE (x11_display))
+        {
+          meta_warning ("Missing %s extension required for compositing",
+                        !META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ?
+                        "composite" : "damage");
+          return;
+        }
 
-  int version = (x11_display->composite_major_version * 10) +
-                 x11_display->composite_minor_version;
-  if (version < 3)
-    {
-      meta_warning ("Your version of COMPOSITE is too old.");
-      return;
+      int version = (x11_display->composite_major_version * 10) +
+                     x11_display->composite_minor_version;
+      if (version < 3)
+        {
+          meta_warning ("Your version of COMPOSITE is too old.");
+          return;
+        }
     }
 
   if (!display->compositor)
@@ -743,7 +746,7 @@ meta_display_open (void)
       ++i;
     }
 
-  display->current_time = CurrentTime;
+  display->current_time = META_CURRENT_TIME;
   display->sentinel_counter = 0;
 
   display->grab_resize_timeout_id = 0;
@@ -826,7 +829,8 @@ meta_display_open (void)
 
   enable_compositor (display);
 
-  meta_x11_display_create_guard_window (display->x11_display);
+  if (display->x11_display)
+    meta_x11_display_create_guard_window (display->x11_display);
 
   /* Set up touch support */
   display->gesture_tracker = meta_gesture_tracker_new ();
@@ -849,7 +853,7 @@ meta_display_open (void)
       else
         meta_x11_display_focus_the_no_focus_window (display->x11_display, timestamp);
     }
-  else
+  else if (display->x11_display)
     meta_x11_display_focus_the_no_focus_window (display->x11_display, timestamp);
 
   meta_idle_monitor_init_dbus ();
@@ -1182,7 +1186,11 @@ meta_display_get_current_time (MetaDisplay *display)
 guint32
 meta_display_get_current_time_roundtrip (MetaDisplay *display)
 {
-  return meta_x11_display_get_current_time_roundtrip (display->x11_display);
+  if (meta_is_wayland_compositor ())
+    /* Xwayland uses monotonic clock, so lets use it here as well */
+    return (guint32) (g_get_monotonic_time () / 1000);
+  else
+    return meta_x11_display_get_current_time_roundtrip (display->x11_display);
 }
 
 /**
@@ -1270,7 +1278,9 @@ meta_display_sync_wayland_input_focus (MetaDisplay *display)
   MetaWindow *focus_window = NULL;
   MetaBackend *backend = meta_get_backend ();
   MetaStage *stage = META_STAGE (meta_backend_get_stage (backend));
-  gboolean is_focus_xwindow =
+  gboolean is_focus_xwindow = FALSE;
+
+  if (display->x11_display)
     meta_x11_display_xwindow_is_a_no_focus_window (display->x11_display,
                                                    display->x11_display->focus_xwindow);
 
@@ -1352,7 +1362,7 @@ meta_display_timestamp_too_old (MetaDisplay *display,
    * timestamp_too_old_or_in_future).
    */
 
-  if (*timestamp == CurrentTime)
+  if (*timestamp == META_CURRENT_TIME)
     {
       *timestamp = meta_display_get_current_time_roundtrip (display);
       return FALSE;
diff --git a/src/core/events.c b/src/core/events.c
index 92503a168..2868e250a 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -269,7 +269,7 @@ meta_display_handle_event (MetaDisplay        *display,
        event->type == CLUTTER_BUTTON_PRESS ||
        event->type == CLUTTER_TOUCH_BEGIN))
     {
-      if (CurrentTime == display->current_time)
+      if (META_CURRENT_TIME == display->current_time)
         {
           /* We can't use missing (i.e. invalid) timestamps to set user time,
            * nor do we want to use them to sanity check other timestamps.
@@ -410,7 +410,7 @@ meta_display_handle_event (MetaDisplay        *display,
     }
 #endif
 
-  display->current_time = CurrentTime;
+  display->current_time = META_CURRENT_TIME;
   return bypass_clutter;
 }
 
diff --git a/src/core/main.c b/src/core/main.c
index a9548f728..f3e4b3290 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -300,7 +300,7 @@ meta_finalize (void)
 
   if (display)
     meta_display_close (display,
-                        CurrentTime); /* I doubt correct timestamps matter here */
+                        META_CURRENT_TIME); /* I doubt correct timestamps matter here */
 
 #ifdef HAVE_WAYLAND
   if (meta_is_wayland_compositor ())
diff --git a/src/core/restart.c b/src/core/restart.c
index dec799b16..cce79d47e 100644
--- a/src/core/restart.c
+++ b/src/core/restart.c
@@ -195,7 +195,7 @@ meta_restart_finish (void)
       MetaDisplay *display = meta_get_display ();
       Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display);
       Atom atom_restart_helper = XInternAtom (xdisplay, "_MUTTER_RESTART_HELPER", False);
-      XSetSelectionOwner (xdisplay, atom_restart_helper, None, CurrentTime);
+      XSetSelectionOwner (xdisplay, atom_restart_helper, None, META_CURRENT_TIME);
     }
 }
 
diff --git a/src/core/window.c b/src/core/window.c
index 59852e8f9..3526f3cc6 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -5015,7 +5015,7 @@ meta_window_change_workspace_by_index (MetaWindow *window,
     meta_display_get_workspace_by_index (display, space_index);
 
   if (!workspace && append)
-    workspace = meta_display_append_new_workspace (display, FALSE, CurrentTime);
+    workspace = meta_display_append_new_workspace (display, FALSE, META_CURRENT_TIME);
 
   if (workspace)
     meta_window_change_workspace (window, workspace);
diff --git a/src/core/workspace.c b/src/core/workspace.c
index adb926081..464398fd0 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -1260,8 +1260,8 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
                                      MetaWindow    *not_this_one,
                                      guint32        timestamp)
 {
-  if (timestamp == CurrentTime)
-    meta_warning ("CurrentTime used to choose focus window; "
+  if (timestamp == META_CURRENT_TIME)
+    meta_warning ("META_CURRENT_TIME used to choose focus window; "
                   "focus window may not be correct.\n");
 
   if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK ||
@@ -1275,11 +1275,11 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
           window->type != META_WINDOW_DOCK &&
           window->type != META_WINDOW_DESKTOP)
         {
-          if (timestamp == CurrentTime)
+          if (timestamp == META_CURRENT_TIME)
             {
 
               /* We would like for this to never happen.  However, if
-               * it does happen then we kludge since using CurrentTime
+               * it does happen then we kludge since using META_CURRENT_TIME
                * can mean ugly race conditions--and we can avoid these
                * by allowing EnterNotify events (which come with
                * timestamps) to handle focus.
diff --git a/src/meta/common.h b/src/meta/common.h
index ba987562a..d5dae613a 100644
--- a/src/meta/common.h
+++ b/src/meta/common.h
@@ -43,6 +43,9 @@
 #define META_VIRTUAL_CORE_POINTER_ID 2
 #define META_VIRTUAL_CORE_KEYBOARD_ID 3
 
+/* Replacement for X11 CurrentTime */
+#define META_CURRENT_TIME 0L
+
 /**
  * MetaFrameFlags:
  * @META_FRAME_ALLOWS_DELETE: frame allows delete
diff --git a/src/wayland/meta-xwayland-selection.c b/src/wayland/meta-xwayland-selection.c
index e46d08ad9..557deb56f 100644
--- a/src/wayland/meta-xwayland-selection.c
+++ b/src/wayland/meta-xwayland-selection.c
@@ -467,7 +467,7 @@ x11_selection_data_send_finished (MetaSelectionBridge *selection,
                          gdk_x11_get_xatom_by_name ("DELETE"),
                          gdk_x11_get_xatom_by_name ("_META_SELECTION"),
                          selection->window,
-                         CurrentTime);
+                         META_CURRENT_TIME);
     }
 
   xdnd_send_finished (selection->x11_selection->selection_data,
@@ -1616,7 +1616,7 @@ meta_xwayland_selection_handle_xfixes_selection_notify (MetaWaylandCompositor *c
                              gdk_x11_get_xatom_by_name ("TARGETS"),
                              gdk_x11_get_xatom_by_name ("_META_SELECTION"),
                              selection->window,
-                             CurrentTime);
+                             META_CURRENT_TIME);
           XFlush (xdisplay);
         }
     }
@@ -1631,7 +1631,7 @@ meta_xwayland_selection_handle_xfixes_selection_notify (MetaWaylandCompositor *c
       if (event->owner != None && event->owner != selection->window &&
           focus && meta_xwayland_is_xwayland_surface (focus))
         {
-          selection->client_message_timestamp = CurrentTime;
+          selection->client_message_timestamp = META_CURRENT_TIME;
           selection->source = meta_wayland_data_source_xwayland_new (selection);
           meta_wayland_data_device_set_dnd_source (&compositor->seat->data_device,
                                                    selection->source);
@@ -1702,7 +1702,7 @@ meta_selection_bridge_ownership_notify (struct wl_listener *listener,
       XSetSelectionOwner (xdisplay,
                           selection->selection_atom,
                           selection->window,
-                          CurrentTime);
+                          META_CURRENT_TIME);
     }
 }
 
diff --git a/src/x11/events.c b/src/x11/events.c
index 61ce70f3e..871592347 100644
--- a/src/x11/events.c
+++ b/src/x11/events.c
@@ -241,7 +241,7 @@ event_get_time (MetaX11Display *x11_display,
     case CirculateRequest:
     case MappingNotify:
     default:
-      return CurrentTime;
+      return META_CURRENT_TIME;
     }
 }
 
@@ -1826,7 +1826,7 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
         bypass_gtk = TRUE;
     }
 
-  display->current_time = CurrentTime;
+  display->current_time = META_CURRENT_TIME;
   return bypass_gtk;
 }
 
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 64a0d0fc5..40b940e79 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1290,7 +1290,7 @@ meta_x11_display_get_current_time_roundtrip (MetaX11Display *x11_display)
   guint32 timestamp;
 
   timestamp = meta_display_get_current_time (x11_display->display);
-  if (timestamp == CurrentTime)
+  if (timestamp == META_CURRENT_TIME)
     {
       XEvent property_event;
 


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