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,76 +477,88 @@ 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)
{
double dx, dx_unaccel;
double dy, 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);
}
static void
dispatch_absolute_motion(struct xwl_seat *xwl_seat)
{ {
ValuatorMask mask; ValuatorMask mask;
DeviceIntPtr device;
int flags;
int event_x = wl_fixed_to_int(xwl_seat->pending_pointer_event.x);
int event_y = wl_fixed_to_int(xwl_seat->pending_pointer_event.y);
int drawable_x = xwl_seat->focus_window->window->drawable.x;
int drawable_y = xwl_seat->focus_window->window->drawable.y;
int x;
int y;
if (xwl_seat->pointer_warp_emulator && if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) {
xwl_seat->pending_pointer_event.has_relative) { event_x *= xwl_seat->focus_window->scale_x;
double dx; event_y *= xwl_seat->focus_window->scale_y;
double dy; }
double dx_unaccel;
double dy_unaccel;
dx = xwl_seat->pending_pointer_event.dx; x = drawable_x + event_x;
dy = xwl_seat->pending_pointer_event.dy; y = drawable_y + event_y;
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 dy, dy_unaccel;
dx = xwl_seat->pending_pointer_event.dx; valuator_mask_zero(&mask);
dy = xwl_seat->pending_pointer_event.dy; valuator_mask_set(&mask, 0, x);
dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel; valuator_mask_set(&mask, 1, y);
dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel;
valuator_mask_zero(&mask); if (xwl_seat->pending_pointer_event.has_relative) {
valuator_mask_set_unaccelerated(&mask, 0, dx, dx_unaccel); flags = POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW;
valuator_mask_set_unaccelerated(&mask, 1, dy, dy_unaccel); device = xwl_seat->relative_pointer;
} else {
flags = POINTER_ABSOLUTE | POINTER_SCREEN;
device = xwl_seat->pointer;
}
QueuePointerEvents(xwl_seat->relative_pointer, MotionNotify, 0, QueuePointerEvents(device, MotionNotify, 0, flags, &mask);
POINTER_RAWONLY, &mask); }
}
if (xwl_seat->pending_pointer_event.has_absolute) { static void
ValuatorMask mask; dispatch_relative_motion(struct xwl_seat *xwl_seat)
DeviceIntPtr device; {
int flags; ValuatorMask mask;
int sx = wl_fixed_to_int(xwl_seat->pending_pointer_event.x); double event_dx = xwl_seat->pending_pointer_event.dx;
int sy = wl_fixed_to_int(xwl_seat->pending_pointer_event.y); double event_dy = xwl_seat->pending_pointer_event.dy;
int dx = xwl_seat->focus_window->window->drawable.x; double event_dx_unaccel = xwl_seat->pending_pointer_event.dx_unaccel;
int dy = xwl_seat->focus_window->window->drawable.y; double event_dy_unaccel = xwl_seat->pending_pointer_event.dy_unaccel;
int x;
int y;
if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) { valuator_mask_zero(&mask);
sx *= xwl_seat->focus_window->scale_x; valuator_mask_set_unaccelerated(&mask, 0, event_dx, event_dx_unaccel);
sy *= xwl_seat->focus_window->scale_y; valuator_mask_set_unaccelerated(&mask, 1, event_dy, event_dy_unaccel);
}
x = dx + sx; QueuePointerEvents(xwl_seat->relative_pointer, MotionNotify, 0,
y = dy + sy; POINTER_RAWONLY, &mask);
}
valuator_mask_zero(&mask); static void
valuator_mask_set(&mask, 0, x); dispatch_pointer_motion_event(struct xwl_seat *xwl_seat)
valuator_mask_set(&mask, 1, y); {
Bool has_relative = xwl_seat->pending_pointer_event.has_relative;
Bool has_absolute = xwl_seat->pending_pointer_event.has_absolute;
if (xwl_seat->pending_pointer_event.has_relative) { if (xwl_seat->pointer_warp_emulator && has_relative) {
flags = POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW; dispatch_relative_motion_with_warp(xwl_seat);
device = xwl_seat->relative_pointer; } else {
} else { if (has_relative)
flags = POINTER_ABSOLUTE | POINTER_SCREEN; dispatch_relative_motion(xwl_seat);
device = xwl_seat->pointer;
}
QueuePointerEvents(device, MotionNotify, 0, flags, &mask); if (has_absolute)
} dispatch_absolute_motion(xwl_seat);
} }
xwl_seat->pending_pointer_event.has_absolute = FALSE; xwl_seat->pending_pointer_event.has_absolute = FALSE;