diff options
author | Olivier Fourdan <ofourdan@redhat.com> | 2021-02-09 13:33:05 +0100 |
---|---|---|
committer | Olivier Fourdan <ofourdan@redhat.com> | 2021-02-15 09:42:00 +0100 |
commit | 71817928247971566903d56c0571db61b7933747 (patch) | |
tree | 36667ab952303d92166a7ffc4400119c54e00b77 /hw/xwayland/xwayland-input.c | |
parent | c5c5322ad69b0751f16c785a479b2989b8794235 (diff) |
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>
Diffstat (limited to 'hw/xwayland/xwayland-input.c')
-rw-r--r-- | hw/xwayland/xwayland-input.c | 136 |
1 files changed, 74 insertions, 62 deletions
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c index 48216c548..5fe290b3c 100644 --- a/hw/xwayland/xwayland-input.c +++ b/hw/xwayland/xwayland-input.c @@ -477,76 +477,88 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer, } 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; + 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 && - 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 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; - - valuator_mask_zero(&mask); - valuator_mask_set_unaccelerated(&mask, 0, dx, dx_unaccel); - valuator_mask_set_unaccelerated(&mask, 1, dy, dy_unaccel); - - QueuePointerEvents(xwl_seat->relative_pointer, MotionNotify, 0, - POINTER_RAWONLY, &mask); - } + if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) { + event_x *= xwl_seat->focus_window->scale_x; + event_y *= xwl_seat->focus_window->scale_y; + } - if (xwl_seat->pending_pointer_event.has_absolute) { - ValuatorMask mask; - DeviceIntPtr device; - int flags; - int sx = wl_fixed_to_int(xwl_seat->pending_pointer_event.x); - int sy = wl_fixed_to_int(xwl_seat->pending_pointer_event.y); - int dx = xwl_seat->focus_window->window->drawable.x; - int dy = xwl_seat->focus_window->window->drawable.y; - int x; - int y; - - if (xwl_window_has_viewport_enabled(xwl_seat->focus_window)) { - sx *= xwl_seat->focus_window->scale_x; - sy *= xwl_seat->focus_window->scale_y; - } + x = drawable_x + event_x; + y = drawable_y + event_y; - x = dx + sx; - y = dy + sy; + valuator_mask_zero(&mask); + valuator_mask_set(&mask, 0, x); + valuator_mask_set(&mask, 1, y); - valuator_mask_zero(&mask); - valuator_mask_set(&mask, 0, x); - valuator_mask_set(&mask, 1, y); + if (xwl_seat->pending_pointer_event.has_relative) { + flags = POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW; + device = xwl_seat->relative_pointer; + } else { + flags = POINTER_ABSOLUTE | POINTER_SCREEN; + device = xwl_seat->pointer; + } - if (xwl_seat->pending_pointer_event.has_relative) { - flags = POINTER_ABSOLUTE | POINTER_SCREEN | POINTER_NORAW; - device = xwl_seat->relative_pointer; - } else { - flags = POINTER_ABSOLUTE | POINTER_SCREEN; - device = xwl_seat->pointer; - } + 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; |