neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

commit 614a6945528b1044da43a679212ce0ffd371852f
parent 70922f9f8084954df59036ba39bb1a48c92727b9
Author: Michael Forney <mforney@mforney.org>
Date:   Sat,  1 Jul 2023 13:56:06 -0700

pointer: Implement protocol version 8

Diffstat:
Mlibswc/pointer.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mlibswc/pointer.h | 8++++++--
Mlibswc/seat.c | 54+++++++++++++++++++++++++++++++++++-------------------
3 files changed, 106 insertions(+), 27 deletions(-)

diff --git a/libswc/pointer.c b/libswc/pointer.c @@ -32,6 +32,7 @@ #include "util.h" #include "cursor/cursor_data.h" +#include <assert.h> #include <stdio.h> #include <wld/wld.h> @@ -204,19 +205,53 @@ client_handle_button(struct pointer_handler *handler, uint32_t time, struct butt } static bool -client_handle_axis(struct pointer_handler *handler, uint32_t time, uint32_t axis, wl_fixed_t amount) +client_handle_axis(struct pointer_handler *handler, uint32_t time, enum wl_pointer_axis axis, enum wl_pointer_axis_source source, wl_fixed_t value, int value120) { struct pointer *pointer = wl_container_of(handler, pointer, client_handler); struct wl_resource *resource; + int ver; if (wl_list_empty(&pointer->focus.active)) return false; - wl_resource_for_each (resource, &pointer->focus.active) - wl_pointer_send_axis(resource, time, axis, amount); + if (pointer->client_axis_source != -1) { + assert(pointer->client_axis_source == source); + source = -1; + } else { + pointer->client_axis_source = source; + } + + wl_resource_for_each (resource, &pointer->focus.active) { + ver = wl_resource_get_version(resource); + if (source != -1 && ver >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION) + wl_pointer_send_axis_source(resource, source); + if (value120) { + if (ver >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION) + wl_pointer_send_axis_value120(resource, axis, value120); + else if (ver >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) + wl_pointer_send_axis_discrete(resource, axis, value120 / 120); + } + if (value) + wl_pointer_send_axis(resource, time, axis, value); + else if (ver >= WL_POINTER_AXIS_STOP_SINCE_VERSION) + wl_pointer_send_axis_stop(resource, time, axis); + } return true; } +static void +client_handle_frame(struct pointer_handler *handler) +{ + struct pointer *pointer = wl_container_of(handler, pointer, client_handler); + struct wl_resource *resource; + + wl_resource_for_each (resource, &pointer->focus.active) { + if (wl_resource_get_version(resource) >= WL_POINTER_FRAME_SINCE_VERSION) + wl_pointer_send_frame(resource); + } + pointer->client_axis_source = -1; +} + bool pointer_initialize(struct pointer *pointer) { @@ -232,6 +267,9 @@ pointer_initialize(struct pointer *pointer) pointer->client_handler.motion = client_handle_motion; pointer->client_handler.button = client_handle_button; pointer->client_handler.axis = client_handle_axis; + pointer->client_handler.frame = client_handle_frame; + pointer->client_handler.pending = false; + pointer->client_axis_source = -1; wl_list_init(&pointer->handlers); wl_list_insert(&pointer->handlers, &pointer->client_handler.link); wl_array_init(&pointer->buttons); @@ -385,6 +423,7 @@ pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t value, ui if (button->handler) { button->press.serial = serial; button->handler->button(button->handler, time, button, state); + button->handler->pending = true; } array_remove(&pointer->buttons, button, sizeof(*button)); @@ -404,6 +443,7 @@ pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t value, ui wl_list_for_each (handler, &pointer->handlers, link) { if (handler->button && handler->button(handler, time, button, state)) { button->handler = handler; + handler->pending = true; break; } } @@ -411,13 +451,15 @@ pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t value, ui } void -pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t amount) +pointer_handle_axis(struct pointer *pointer, uint32_t time, enum wl_pointer_axis axis, enum wl_pointer_axis_source source, wl_fixed_t value, int value120) { struct pointer_handler *handler; wl_list_for_each (handler, &pointer->handlers, link) { - if (handler->axis && handler->axis(handler, time, axis, amount)) + if (handler->axis && handler->axis(handler, time, axis, source, value, value120)) { + handler->pending = true; break; + } } } @@ -435,8 +477,25 @@ pointer_handle_absolute_motion(struct pointer *pointer, uint32_t time, wl_fixed_ clip_position(pointer, x, y); wl_list_for_each (handler, &pointer->handlers, link) { - if (handler->motion && handler->motion(handler, time, pointer->x, pointer->y)) + if (handler->motion && handler->motion(handler, time, pointer->x, pointer->y)) { + handler->pending = true; break; + } + } + + update_cursor(pointer); +} + +void +pointer_handle_frame(struct pointer *pointer) +{ + struct pointer_handler *handler; + + wl_list_for_each (handler, &pointer->handlers, link) { + if (handler->pending && handler->frame) { + handler->frame(handler); + handler->pending = false; + } } update_cursor(pointer); diff --git a/libswc/pointer.h b/libswc/pointer.h @@ -38,8 +38,10 @@ struct button { struct pointer_handler { bool (*motion)(struct pointer_handler *handler, uint32_t time, wl_fixed_t x, wl_fixed_t y); bool (*button)(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state); - bool (*axis)(struct pointer_handler *handler, uint32_t time, enum wl_pointer_axis axis, wl_fixed_t amount); + bool (*axis)(struct pointer_handler *handler, uint32_t time, enum wl_pointer_axis axis, enum wl_pointer_axis_source source, wl_fixed_t value, int value120); + void (*frame)(struct pointer_handler *handler); + int pending; struct wl_list link; }; @@ -64,6 +66,7 @@ struct pointer { struct wl_array buttons; struct wl_list handlers; struct pointer_handler client_handler; + enum wl_pointer_axis_source client_axis_source; wl_fixed_t x, y; pixman_region32_t region; @@ -79,8 +82,9 @@ struct button *pointer_get_button(struct pointer *pointer, uint32_t serial); struct wl_resource *pointer_bind(struct pointer *pointer, struct wl_client *client, uint32_t version, uint32_t id); void pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t button, uint32_t state); -void pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t amount); +void pointer_handle_axis(struct pointer *pointer, uint32_t time, enum wl_pointer_axis axis, enum wl_pointer_axis_source source, wl_fixed_t value, int value120); void pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, wl_fixed_t dx, wl_fixed_t dy); void pointer_handle_absolute_motion(struct pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y); +void pointer_handle_frame(struct pointer *pointer); #endif diff --git a/libswc/seat.c b/libswc/seat.c @@ -220,18 +220,6 @@ device_capabilities(struct libinput_device *device) return capabilities; } -static void -handle_libinput_axis_event(struct seat *seat, struct libinput_event_pointer *event, enum libinput_pointer_axis axis) -{ - wl_fixed_t amount; - - if (!libinput_event_pointer_has_axis(event, axis)) - return; - - amount = wl_fixed_from_double(libinput_event_pointer_get_axis_value(event, axis)); - pointer_handle_axis(&seat->pointer, libinput_event_pointer_get_time(event), axis, amount); -} - static int handle_libinput_data(int fd, uint32_t mask, void *data) { @@ -244,8 +232,10 @@ handle_libinput_data(int fd, uint32_t mask, void *data) struct libinput_event_keyboard *k; struct libinput_event_pointer *p; } event; - wl_fixed_t x, y; + wl_fixed_t x, y, value; uint32_t time, key, state; + enum wl_pointer_axis_source source; + int value120; if (libinput_dispatch(seat->libinput) != 0) { WARNING("libinput_dispatch failed: %s\n", strerror(errno)); @@ -273,6 +263,7 @@ handle_libinput_data(int fd, uint32_t mask, void *data) x = wl_fixed_from_double(libinput_event_pointer_get_dx(event.p)); y = wl_fixed_from_double(libinput_event_pointer_get_dy(event.p)); pointer_handle_relative_motion(&seat->pointer, time, x, y); + pointer_handle_frame(&seat->pointer); break; case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: screen = wl_container_of(swc.screens.next, screen, link); @@ -282,6 +273,7 @@ handle_libinput_data(int fd, uint32_t mask, void *data) x = wl_fixed_from_double(libinput_event_pointer_get_absolute_x_transformed(event.p, rect->width)); y = wl_fixed_from_double(libinput_event_pointer_get_absolute_y_transformed(event.p, rect->height)); pointer_handle_absolute_motion(&seat->pointer, time, x, y); + pointer_handle_frame(&seat->pointer); break; case LIBINPUT_EVENT_POINTER_BUTTON: event.p = libinput_event_get_pointer_event(generic_event); @@ -292,20 +284,44 @@ handle_libinput_data(int fd, uint32_t mask, void *data) if (state == LIBINPUT_BUTTON_STATE_PRESSED) { /* qemu generates GEAR_UP/GEAR_DOWN events on scroll, so pass * those through as axis events. */ + source = WL_POINTER_AXIS_SOURCE_WHEEL; switch (key) { case BTN_GEAR_DOWN: - pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(10)); + pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, wl_fixed_from_int(10), 120); break; case BTN_GEAR_UP: - pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(-10)); + pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, wl_fixed_from_int(-10), -120); break; } } + pointer_handle_frame(&seat->pointer); break; - case LIBINPUT_EVENT_POINTER_AXIS: + case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: + source = WL_POINTER_AXIS_SOURCE_WHEEL; + goto scroll; + case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: + source = WL_POINTER_AXIS_SOURCE_FINGER; + goto scroll; + case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: + source = WL_POINTER_AXIS_SOURCE_CONTINUOUS; + goto scroll; + scroll: event.p = libinput_event_get_pointer_event(generic_event); - handle_libinput_axis_event(seat, event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); - handle_libinput_axis_event(seat, event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + time = libinput_event_pointer_get_time(event.p); + value120 = 0; + if (libinput_event_pointer_has_axis(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { + value = wl_fixed_from_double(libinput_event_pointer_get_scroll_value(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)); + if (source == WL_POINTER_AXIS_SOURCE_WHEEL) + value120 = libinput_event_pointer_get_scroll_value_v120(event.p, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_VERTICAL_SCROLL, source, value, value120); + } + if (libinput_event_pointer_has_axis(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { + value = wl_fixed_from_double(libinput_event_pointer_get_scroll_value(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)); + if (source == WL_POINTER_AXIS_SOURCE_WHEEL) + value120 = libinput_event_pointer_get_scroll_value_v120(event.p, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + pointer_handle_axis(&seat->pointer, time, WL_POINTER_AXIS_HORIZONTAL_SCROLL, source, value, value120); + } + pointer_handle_frame(&seat->pointer); break; default: break; @@ -382,7 +398,7 @@ seat_create(struct wl_display *display, const char *seat_name) ERROR("Could not allocate seat name string\n"); goto error1; } - seat->global = wl_global_create(display, &wl_seat_interface, 4, seat, &bind_seat); + seat->global = wl_global_create(display, &wl_seat_interface, 8, seat, &bind_seat); if (!seat->global) goto error2; seat->capabilities = 0;