xwayland: Split dispatch_pointer_motion_event

This is a cleanup patch, no functional change.

Split the function dispatch_pointer_motion_event() into three separate
simpler functions, relative motion with a warp emulator, relative motion
and absolute motion.

This makes the code a lot easier to read for me, rather than having
everything in a single function with nested if/else conditions.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Olivier Fourdan 2021-02-09 13:33:05 +01:00
parent c5c5322ad6
commit 7181792824

View File

@ -477,27 +477,8 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer,
} }
static void static void
dispatch_pointer_motion_event(struct xwl_seat *xwl_seat) dispatch_relative_motion_with_warp(struct xwl_seat *xwl_seat)
{ {
ValuatorMask mask;
if (xwl_seat->pointer_warp_emulator &&
xwl_seat->pending_pointer_event.has_relative) {
double dx;
double dy;
double dx_unaccel;
double dy_unaccel;
dx = xwl_seat->pending_pointer_event.dx;
dy = xwl_seat->pending_pointer_event.dy;
dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel;
dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel;
xwl_pointer_warp_emulator_handle_motion(xwl_seat->pointer_warp_emulator,
dx, dy,
dx_unaccel, dy_unaccel);
} else if (xwl_seat->pending_pointer_event.has_absolute ||
xwl_seat->pending_pointer_event.has_relative) {
if (xwl_seat->pending_pointer_event.has_relative) {
double dx, dx_unaccel; double dx, dx_unaccel;
double dy, dy_unaccel; double dy, dy_unaccel;
@ -506,32 +487,31 @@ dispatch_pointer_motion_event(struct xwl_seat *xwl_seat)
dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel; dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel;
dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel; dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel;
valuator_mask_zero(&mask); xwl_pointer_warp_emulator_handle_motion(xwl_seat->pointer_warp_emulator,
valuator_mask_set_unaccelerated(&mask, 0, dx, dx_unaccel); dx, dy,
valuator_mask_set_unaccelerated(&mask, 1, dy, dy_unaccel); dx_unaccel, dy_unaccel);
QueuePointerEvents(xwl_seat->relative_pointer, MotionNotify, 0,
POINTER_RAWONLY, &mask);
} }
if (xwl_seat->pending_pointer_event.has_absolute) { static void
dispatch_absolute_motion(struct xwl_seat *xwl_seat)
{
ValuatorMask mask; ValuatorMask mask;
DeviceIntPtr device; DeviceIntPtr device;
int flags; int flags;
int sx = wl_fixed_to_int(xwl_seat->pending_pointer_event.x); int event_x = wl_fixed_to_int(xwl_seat->pending_pointer_event.x);
int sy = wl_fixed_to_int(xwl_seat->pending_pointer_event.y); int event_y = wl_fixed_to_int(xwl_seat->pending_pointer_event.y);
int dx = xwl_seat->focus_window->window->drawable.x; int drawable_x = xwl_seat->focus_window->window->drawable.x;
int dy = xwl_seat->focus_window->window->drawable.y; int drawable_y = xwl_seat->focus_window->window->drawable.y;
int x; int x;
int y; int y;
if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) { if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) {
sx *= xwl_seat->focus_window->scale_x; event_x *= xwl_seat->focus_window->scale_x;
sy *= xwl_seat->focus_window->scale_y; event_y *= xwl_seat->focus_window->scale_y;
} }
x = dx + sx; x = drawable_x + event_x;
y = dy + sy; y = drawable_y + event_y;
valuator_mask_zero(&mask); valuator_mask_zero(&mask);
valuator_mask_set(&mask, 0, x); valuator_mask_set(&mask, 0, x);
@ -547,6 +527,38 @@ dispatch_pointer_motion_event(struct xwl_seat *xwl_seat)
QueuePointerEvents(device, MotionNotify, 0, flags, &mask); QueuePointerEvents(device, MotionNotify, 0, flags, &mask);
} }
static void
dispatch_relative_motion(struct xwl_seat *xwl_seat)
{
ValuatorMask mask;
double event_dx = xwl_seat->pending_pointer_event.dx;
double event_dy = xwl_seat->pending_pointer_event.dy;
double event_dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel;
double event_dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel;
valuator_mask_zero(&mask);
valuator_mask_set_unaccelerated(&mask, 0, event_dx, event_dx_unaccel);
valuator_mask_set_unaccelerated(&mask, 1, event_dy, event_dy_unaccel);
QueuePointerEvents(xwl_seat->relative_pointer, MotionNotify, 0,
POINTER_RAWONLY, &mask);
}
static void
dispatch_pointer_motion_event(struct xwl_seat *xwl_seat)
{
Bool has_relative = xwl_seat->pending_pointer_event.has_relative;
Bool has_absolute = xwl_seat->pending_pointer_event.has_absolute;
if (xwl_seat->pointer_warp_emulator && has_relative) {
dispatch_relative_motion_with_warp(xwl_seat);
} else {
if (has_relative)
dispatch_relative_motion(xwl_seat);
if (has_absolute)
dispatch_absolute_motion(xwl_seat);
} }
xwl_seat->pending_pointer_event.has_absolute = FALSE; xwl_seat->pending_pointer_event.has_absolute = FALSE;