backends: Move warp_pointer() to ClutterSeat

The onscreen pointer sprite is a per-seat element, so it makes sense
to move pointer warping over there too.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/852
This commit is contained in:
Carlos Garnacho 2019-10-09 18:01:34 +02:00
parent 9da275cf73
commit 1e9682b417
12 changed files with 67 additions and 92 deletions

View File

@ -546,3 +546,13 @@ clutter_seat_compress_motion (ClutterSeat *seat,
if (seat_class->compress_motion)
seat_class->compress_motion (seat, event, to_discard);
}
void
clutter_seat_warp_pointer (ClutterSeat *seat,
int x,
int y)
{
g_return_if_fail (CLUTTER_IS_SEAT (seat));
CLUTTER_SEAT_GET_CLASS (seat)->warp_pointer (seat, x, y);
}

View File

@ -106,6 +106,10 @@ struct _ClutterSeatClass
ClutterEvent *event,
const ClutterEvent *to_discard);
void (* warp_pointer) (ClutterSeat *seat,
int x,
int y);
/* Event platform data */
void (* copy_event_data) (ClutterSeat *seat,
const ClutterEvent *src,
@ -166,4 +170,9 @@ void clutter_seat_compress_motion (ClutterSeat *seat,
ClutterEvent *event,
const ClutterEvent *to_discard);
CLUTTER_EXPORT
void clutter_seat_warp_pointer (ClutterSeat *seat,
int x,
int y);
#endif /* CLUTTER_SEAT_H */

View File

@ -82,11 +82,6 @@ struct _MetaBackendClass
void (* finish_touch_sequence) (MetaBackend *backend,
ClutterEventSequence *sequence,
MetaSequenceState state);
void (* warp_pointer) (MetaBackend *backend,
int x,
int y);
MetaLogicalMonitor * (* get_current_logical_monitor) (MetaBackend *backend);
void (* set_keymap) (MetaBackend *backend,
@ -145,10 +140,6 @@ void meta_backend_finish_touch_sequence (MetaBackend *backend,
ClutterEventSequence *sequence,
MetaSequenceState state);
void meta_backend_warp_pointer (MetaBackend *backend,
int x,
int y);
MetaLogicalMonitor * meta_backend_get_current_logical_monitor (MetaBackend *backend);
struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend);

View File

@ -237,6 +237,7 @@ reset_pointer_position (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaMonitorManager *monitor_manager = priv->monitor_manager;
ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
MetaLogicalMonitor *primary;
primary =
@ -244,7 +245,7 @@ reset_pointer_position (MetaBackend *backend)
/* Move the pointer out of the way to avoid hovering over reactive
* elements (e.g. users list at login) causing undesired behaviour. */
meta_backend_warp_pointer (backend,
clutter_seat_warp_pointer (seat,
primary->rect.x + primary->rect.width * 0.9,
primary->rect.y + primary->rect.height * 0.9);
}
@ -1067,17 +1068,6 @@ meta_backend_finish_touch_sequence (MetaBackend *backend,
state);
}
/**
* meta_backend_warp_pointer: (skip)
*/
void
meta_backend_warp_pointer (MetaBackend *backend,
int x,
int y)
{
META_BACKEND_GET_CLASS (backend)->warp_pointer (backend, x, y);
}
MetaLogicalMonitor *
meta_backend_get_current_logical_monitor (MetaBackend *backend)
{

View File

@ -403,25 +403,6 @@ meta_backend_native_create_input_settings (MetaBackend *backend)
return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE, NULL);
}
static void
meta_backend_native_warp_pointer (MetaBackend *backend,
int x,
int y)
{
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
ClutterInputDevice *device = clutter_seat_get_pointer (seat);
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
/* XXX */
guint32 time_ = 0;
/* Warp the input device pointer state. */
meta_seat_native_warp_pointer (device, time_, x, y);
/* Warp displayed pointer cursor. */
meta_cursor_tracker_update_position (cursor_tracker, x, y);
}
static MetaLogicalMonitor *
meta_backend_native_get_current_logical_monitor (MetaBackend *backend)
{
@ -704,8 +685,6 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
backend_class->create_renderer = meta_backend_native_create_renderer;
backend_class->create_input_settings = meta_backend_native_create_input_settings;
backend_class->warp_pointer = meta_backend_native_warp_pointer;
backend_class->get_current_logical_monitor = meta_backend_native_get_current_logical_monitor;
backend_class->set_keymap = meta_backend_native_set_keymap;

View File

@ -32,6 +32,7 @@
#include <linux/input.h>
#include <math.h>
#include "backends/meta-cursor-tracker-private.h"
#include "backends/native/meta-seat-native.h"
#include "backends/native/meta-event-native.h"
#include "backends/native/meta-input-device-native.h"
@ -2612,6 +2613,20 @@ meta_seat_native_compress_motion (ClutterSeat *seat,
dy_unaccel + dst_dy_unaccel);
}
static void
meta_seat_native_warp_pointer (ClutterSeat *seat,
int x,
int y)
{
MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
MetaBackend *backend = meta_get_backend ();
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
notify_absolute_motion (seat_native->core_pointer, 0, x, y, NULL);
meta_cursor_tracker_update_position (cursor_tracker, x, y);
}
static void
meta_seat_native_class_init (MetaSeatNativeClass *klass)
{
@ -2635,6 +2650,7 @@ meta_seat_native_class_init (MetaSeatNativeClass *klass)
seat_class->create_virtual_device = meta_seat_native_create_virtual_device;
seat_class->get_supported_virtual_device_types = meta_seat_native_get_supported_virtual_device_types;
seat_class->compress_motion = meta_seat_native_compress_motion;
seat_class->warp_pointer = meta_seat_native_warp_pointer;
props[PROP_SEAT_ID] =
g_param_spec_string ("seat-id",
@ -2906,30 +2922,6 @@ meta_seat_native_update_xkb_state (MetaSeatNative *seat)
meta_seat_native_sync_leds (seat);
}
/**
* meta_seat_native_warp_pointer:
* @pointer_device: the pointer device to warp
* @time: the timestamp for the warp event
* @x: the new X position of the pointer
* @y: the new Y position of the pointer
*
* Warps the pointer to a new location. Technically, this is
* processed the same way as an absolute motion event from
* libinput: it simply generates an absolute motion event that
* will be processed on the next iteration of the mainloop.
*
* The intended use for this is for display servers that need
* to warp cursor the cursor to a new location.
*/
void
meta_seat_native_warp_pointer (ClutterInputDevice *pointer_device,
uint32_t time_,
int x,
int y)
{
notify_absolute_motion (pointer_device, ms2us(time_), x, y, NULL);
}
gint
meta_seat_native_acquire_device_id (MetaSeatNative *seat)
{

View File

@ -295,11 +295,6 @@ void meta_seat_native_remove_filter (MetaSeatNative *seat,
MetaEvdevFilterFunc func,
gpointer data);
void meta_seat_native_warp_pointer (ClutterInputDevice *pointer_device,
uint32_t time_,
int x,
int y);
struct xkb_state * meta_seat_native_get_xkb_state (MetaSeatNative *seat);
void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,

View File

@ -670,22 +670,6 @@ meta_backend_x11_finish_touch_sequence (MetaBackend *backend,
}
}
static void
meta_backend_x11_warp_pointer (MetaBackend *backend,
int x,
int y)
{
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
XIWarpPointer (priv->xdisplay,
META_VIRTUAL_CORE_POINTER_ID,
None,
meta_backend_x11_get_xwindow (x11),
0, 0, 0, 0,
x, y);
}
static MetaLogicalMonitor *
meta_backend_x11_get_current_logical_monitor (MetaBackend *backend)
{
@ -862,7 +846,6 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
backend_class->grab_device = meta_backend_x11_grab_device;
backend_class->ungrab_device = meta_backend_x11_ungrab_device;
backend_class->finish_touch_sequence = meta_backend_x11_finish_touch_sequence;
backend_class->warp_pointer = meta_backend_x11_warp_pointer;
backend_class->get_current_logical_monitor = meta_backend_x11_get_current_logical_monitor;
backend_class->get_keymap = meta_backend_x11_get_keymap;
backend_class->get_keymap_layout_group = meta_backend_x11_get_keymap_layout_group;

View File

@ -1500,6 +1500,21 @@ meta_seat_x11_get_supported_virtual_device_types (ClutterSeat *seat)
CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER);
}
static void
meta_seat_x11_warp_pointer (ClutterSeat *seat,
int x,
int y)
{
MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
XIWarpPointer (clutter_x11_get_default_display (),
seat_x11->pointer_id,
None,
clutter_x11_get_root_window (),
0, 0, 0, 0,
x, y);
}
static void
meta_seat_x11_class_init (MetaSeatX11Class *klass)
{
@ -1521,6 +1536,7 @@ meta_seat_x11_class_init (MetaSeatX11Class *klass)
seat_class->apply_kbd_a11y_settings = meta_seat_x11_apply_kbd_a11y_settings;
seat_class->create_virtual_device = meta_seat_x11_create_virtual_device;
seat_class->get_supported_virtual_device_types = meta_seat_x11_get_supported_virtual_device_types;
seat_class->warp_pointer = meta_seat_x11_warp_pointer;
props[PROP_OPCODE] =
g_param_spec_int ("opcode",

View File

@ -6858,8 +6858,10 @@ warp_grab_pointer (MetaWindow *window,
&display->grab_anchor_window_pos);
{
MetaBackend *backend = meta_get_backend ();
meta_backend_warp_pointer (backend, *x, *y);
ClutterSeat *seat;
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
clutter_seat_warp_pointer (seat, *x, *y);
}
if (meta_x11_error_trap_pop_with_return (display->x11_display) != Success)

View File

@ -643,6 +643,7 @@ meta_pointer_confinement_wayland_maybe_warp (MetaPointerConfinementWayland *self
GArray *borders;
float closest_distance_2 = FLT_MAX;
MetaBorder *closest_border = NULL;
ClutterSeat *seat;
unsigned int i;
float x;
float y;
@ -667,7 +668,9 @@ meta_pointer_confinement_wayland_maybe_warp (MetaPointerConfinementWayland *self
warp_to_behind_border (closest_border, &sx, &sy);
meta_wayland_surface_get_absolute_coordinates (surface, sx, sy, &x, &y);
meta_backend_warp_pointer (meta_get_backend (), (int)x, (int)y);
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
clutter_seat_warp_pointer (seat, (int)x, (int)y);
}
cairo_region_destroy (region);

View File

@ -923,7 +923,12 @@ locked_pointer_destroy (struct wl_client *client,
wl_resource_destroy (resource);
if (warp_pointer)
meta_backend_warp_pointer (meta_get_backend (), warp_x, warp_y);
{
ClutterSeat *seat;
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
clutter_seat_warp_pointer (seat, warp_x, warp_y);
}
}
static void