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
This commit is contained in:
Armin Krezović 2017-08-26 22:24:21 +02:00 committed by Jonas Ådahl
parent 0a8ae8417c
commit 8e7e1eeef5
12 changed files with 67 additions and 47 deletions

View File

@ -176,7 +176,7 @@ translate_device_event (MetaBackendX11 *x11,
meta_backend_x11_translate_device_event (x11, device_event); 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)) 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 }; XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
int ret; int ret;
if (timestamp != CurrentTime) if (timestamp != META_CURRENT_TIME)
timestamp = MAX (timestamp, priv->latest_evtime); timestamp = MAX (timestamp, priv->latest_evtime);
XISetMask (mask.mask, XI_ButtonPress); XISetMask (mask.mask, XI_ButtonPress);

View File

@ -362,11 +362,14 @@ meta_begin_modal_for_plugin (MetaCompositor *compositor,
if (is_modal (display) || display->grab_op != META_GRAB_OP_NONE) if (is_modal (display) || display->grab_op != META_GRAB_OP_NONE)
return FALSE; return FALSE;
if (display->x11_display)
{
/* XXX: why is this needed? */ /* XXX: why is this needed? */
XIUngrabDevice (display->x11_display->xdisplay, XIUngrabDevice (display->x11_display->xdisplay,
META_VIRTUAL_CORE_POINTER_ID, META_VIRTUAL_CORE_POINTER_ID,
timestamp); timestamp);
XSync (display->x11_display->xdisplay, False); XSync (display->x11_display->xdisplay, False);
}
if (!grab_devices (options, timestamp)) if (!grab_devices (options, timestamp))
return FALSE; return FALSE;
@ -443,9 +446,8 @@ after_stage_paint (ClutterStage *stage,
} }
static void 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); Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
Window xroot = meta_x11_display_get_xroot (x11_display); Window xroot = meta_x11_display_get_xroot (x11_display);
int screen_number = meta_x11_display_get_screen_number (x11_display); int screen_number = meta_x11_display_get_screen_number (x11_display);
@ -489,10 +491,14 @@ void
meta_compositor_manage (MetaCompositor *compositor) meta_compositor_manage (MetaCompositor *compositor)
{ {
MetaDisplay *display = compositor->display; MetaDisplay *display = compositor->display;
Display *xdisplay = display->x11_display->xdisplay; Display *xdisplay = NULL;
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
if (display->x11_display)
{
xdisplay = display->x11_display->xdisplay;
meta_x11_display_set_cm_selection (display->x11_display); meta_x11_display_set_cm_selection (display->x11_display);
}
compositor->stage = meta_backend_get_stage (backend); 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); 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); compositor->plugin_mgr = meta_plugin_manager_new (compositor);
} }

View File

@ -595,6 +595,8 @@ enable_compositor (MetaDisplay *display)
{ {
MetaX11Display *x11_display = display->x11_display; MetaX11Display *x11_display = display->x11_display;
if (x11_display)
{
if (!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) || if (!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ||
!META_X11_DISPLAY_HAS_DAMAGE (x11_display)) !META_X11_DISPLAY_HAS_DAMAGE (x11_display))
{ {
@ -611,6 +613,7 @@ enable_compositor (MetaDisplay *display)
meta_warning ("Your version of COMPOSITE is too old."); meta_warning ("Your version of COMPOSITE is too old.");
return; return;
} }
}
if (!display->compositor) if (!display->compositor)
display->compositor = meta_compositor_new (display); display->compositor = meta_compositor_new (display);
@ -743,7 +746,7 @@ meta_display_open (void)
++i; ++i;
} }
display->current_time = CurrentTime; display->current_time = META_CURRENT_TIME;
display->sentinel_counter = 0; display->sentinel_counter = 0;
display->grab_resize_timeout_id = 0; display->grab_resize_timeout_id = 0;
@ -826,6 +829,7 @@ meta_display_open (void)
enable_compositor (display); enable_compositor (display);
if (display->x11_display)
meta_x11_display_create_guard_window (display->x11_display); meta_x11_display_create_guard_window (display->x11_display);
/* Set up touch support */ /* Set up touch support */
@ -849,7 +853,7 @@ meta_display_open (void)
else else
meta_x11_display_focus_the_no_focus_window (display->x11_display, timestamp); 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_x11_display_focus_the_no_focus_window (display->x11_display, timestamp);
meta_idle_monitor_init_dbus (); meta_idle_monitor_init_dbus ();
@ -1182,6 +1186,10 @@ meta_display_get_current_time (MetaDisplay *display)
guint32 guint32
meta_display_get_current_time_roundtrip (MetaDisplay *display) meta_display_get_current_time_roundtrip (MetaDisplay *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); 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; MetaWindow *focus_window = NULL;
MetaBackend *backend = meta_get_backend (); MetaBackend *backend = meta_get_backend ();
MetaStage *stage = META_STAGE (meta_backend_get_stage (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, meta_x11_display_xwindow_is_a_no_focus_window (display->x11_display,
display->x11_display->focus_xwindow); display->x11_display->focus_xwindow);
@ -1352,7 +1362,7 @@ meta_display_timestamp_too_old (MetaDisplay *display,
* timestamp_too_old_or_in_future). * timestamp_too_old_or_in_future).
*/ */
if (*timestamp == CurrentTime) if (*timestamp == META_CURRENT_TIME)
{ {
*timestamp = meta_display_get_current_time_roundtrip (display); *timestamp = meta_display_get_current_time_roundtrip (display);
return FALSE; return FALSE;

View File

@ -269,7 +269,7 @@ meta_display_handle_event (MetaDisplay *display,
event->type == CLUTTER_BUTTON_PRESS || event->type == CLUTTER_BUTTON_PRESS ||
event->type == CLUTTER_TOUCH_BEGIN)) 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, /* 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. * nor do we want to use them to sanity check other timestamps.
@ -410,7 +410,7 @@ meta_display_handle_event (MetaDisplay *display,
} }
#endif #endif
display->current_time = CurrentTime; display->current_time = META_CURRENT_TIME;
return bypass_clutter; return bypass_clutter;
} }

View File

@ -300,7 +300,7 @@ meta_finalize (void)
if (display) if (display)
meta_display_close (display, meta_display_close (display,
CurrentTime); /* I doubt correct timestamps matter here */ META_CURRENT_TIME); /* I doubt correct timestamps matter here */
#ifdef HAVE_WAYLAND #ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ()) if (meta_is_wayland_compositor ())

View File

@ -195,7 +195,7 @@ meta_restart_finish (void)
MetaDisplay *display = meta_get_display (); MetaDisplay *display = meta_get_display ();
Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display); Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display);
Atom atom_restart_helper = XInternAtom (xdisplay, "_MUTTER_RESTART_HELPER", False); 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);
} }
} }

View File

@ -5015,7 +5015,7 @@ meta_window_change_workspace_by_index (MetaWindow *window,
meta_display_get_workspace_by_index (display, space_index); meta_display_get_workspace_by_index (display, space_index);
if (!workspace && append) 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) if (workspace)
meta_window_change_workspace (window, workspace); meta_window_change_workspace (window, workspace);

View File

@ -1260,8 +1260,8 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
MetaWindow *not_this_one, MetaWindow *not_this_one,
guint32 timestamp) guint32 timestamp)
{ {
if (timestamp == CurrentTime) if (timestamp == META_CURRENT_TIME)
meta_warning ("CurrentTime used to choose focus window; " meta_warning ("META_CURRENT_TIME used to choose focus window; "
"focus window may not be correct.\n"); "focus window may not be correct.\n");
if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK || 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_DOCK &&
window->type != META_WINDOW_DESKTOP) window->type != META_WINDOW_DESKTOP)
{ {
if (timestamp == CurrentTime) if (timestamp == META_CURRENT_TIME)
{ {
/* We would like for this to never happen. However, if /* 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 * can mean ugly race conditions--and we can avoid these
* by allowing EnterNotify events (which come with * by allowing EnterNotify events (which come with
* timestamps) to handle focus. * timestamps) to handle focus.

View File

@ -43,6 +43,9 @@
#define META_VIRTUAL_CORE_POINTER_ID 2 #define META_VIRTUAL_CORE_POINTER_ID 2
#define META_VIRTUAL_CORE_KEYBOARD_ID 3 #define META_VIRTUAL_CORE_KEYBOARD_ID 3
/* Replacement for X11 CurrentTime */
#define META_CURRENT_TIME 0L
/** /**
* MetaFrameFlags: * MetaFrameFlags:
* @META_FRAME_ALLOWS_DELETE: frame allows delete * @META_FRAME_ALLOWS_DELETE: frame allows delete

View File

@ -467,7 +467,7 @@ x11_selection_data_send_finished (MetaSelectionBridge *selection,
gdk_x11_get_xatom_by_name ("DELETE"), gdk_x11_get_xatom_by_name ("DELETE"),
gdk_x11_get_xatom_by_name ("_META_SELECTION"), gdk_x11_get_xatom_by_name ("_META_SELECTION"),
selection->window, selection->window,
CurrentTime); META_CURRENT_TIME);
} }
xdnd_send_finished (selection->x11_selection->selection_data, 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 ("TARGETS"),
gdk_x11_get_xatom_by_name ("_META_SELECTION"), gdk_x11_get_xatom_by_name ("_META_SELECTION"),
selection->window, selection->window,
CurrentTime); META_CURRENT_TIME);
XFlush (xdisplay); XFlush (xdisplay);
} }
} }
@ -1631,7 +1631,7 @@ meta_xwayland_selection_handle_xfixes_selection_notify (MetaWaylandCompositor *c
if (event->owner != None && event->owner != selection->window && if (event->owner != None && event->owner != selection->window &&
focus && meta_xwayland_is_xwayland_surface (focus)) 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); selection->source = meta_wayland_data_source_xwayland_new (selection);
meta_wayland_data_device_set_dnd_source (&compositor->seat->data_device, meta_wayland_data_device_set_dnd_source (&compositor->seat->data_device,
selection->source); selection->source);
@ -1702,7 +1702,7 @@ meta_selection_bridge_ownership_notify (struct wl_listener *listener,
XSetSelectionOwner (xdisplay, XSetSelectionOwner (xdisplay,
selection->selection_atom, selection->selection_atom,
selection->window, selection->window,
CurrentTime); META_CURRENT_TIME);
} }
} }

View File

@ -241,7 +241,7 @@ event_get_time (MetaX11Display *x11_display,
case CirculateRequest: case CirculateRequest:
case MappingNotify: case MappingNotify:
default: default:
return CurrentTime; return META_CURRENT_TIME;
} }
} }
@ -1826,7 +1826,7 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
bypass_gtk = TRUE; bypass_gtk = TRUE;
} }
display->current_time = CurrentTime; display->current_time = META_CURRENT_TIME;
return bypass_gtk; return bypass_gtk;
} }

View File

@ -1290,7 +1290,7 @@ meta_x11_display_get_current_time_roundtrip (MetaX11Display *x11_display)
guint32 timestamp; guint32 timestamp;
timestamp = meta_display_get_current_time (x11_display->display); timestamp = meta_display_get_current_time (x11_display->display);
if (timestamp == CurrentTime) if (timestamp == META_CURRENT_TIME)
{ {
XEvent property_event; XEvent property_event;