From e235f7d33621b5879a5f9a8a1d89d4a8515857c3 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 24 Apr 2018 08:10:45 +0200 Subject: Basic tablet_v2 object lifetime --- include/rootston/cursor.h | 1 + include/rootston/desktop.h | 1 + 2 files changed, 2 insertions(+) (limited to 'include/rootston') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index a1a466c2..0478c3ca 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -40,6 +40,7 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; + struct wl_listener tool_proximity; struct wl_listener request_set_cursor; }; diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 88c5ca90..d9add26a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -56,6 +56,7 @@ struct roots_desktop { struct wlr_layer_shell *layer_shell; struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; struct wlr_screencopy_manager_v1 *screencopy; + struct wlr_tablet_manager_v2 *tablet_v2; struct wl_listener new_output; struct wl_listener layout_change; -- cgit v1.2.3 From f375246657e23926d98cc21ae66a5dae352ea50a Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 26 Apr 2018 12:31:25 +0200 Subject: Implement basic tablet_pad handling (bound to keyboard focus) --- backend/libinput/tablet_pad.c | 2 + include/rootston/seat.h | 23 ++++ include/wlr/types/wlr_tablet_pad.h | 2 + include/wlr/types/wlr_tablet_v2.h | 42 ++++++ rootston/seat.c | 177 ++++++++++++++++++++++++- types/wlr_tablet_pad.c | 1 + types/wlr_tablet_v2.c | 263 +++++++++++++++++++++++++++++++++++++ 7 files changed, 505 insertions(+), 5 deletions(-) (limited to 'include/rootston') diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 2558d09c..7c196bf1 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -124,6 +124,8 @@ void handle_tablet_pad_button(struct libinput_event *event, usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent)); wlr_event.button = libinput_event_tablet_pad_get_button_number(pevent); wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent); + wlr_event.group = libinput_tablet_pad_mode_group_get_index( + libinput_event_tablet_pad_get_mode_group(pevent)); switch (libinput_event_tablet_pad_get_button_state(pevent)) { case LIBINPUT_BUTTON_STATE_PRESSED: wlr_event.state = WLR_BUTTON_PRESSED; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 0e3043dd..31ddd6fa 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -31,6 +31,7 @@ struct roots_seat { struct wl_list pointers; struct wl_list touch; struct wl_list tablet_tools; + struct wl_list tablet_pads; struct wl_listener new_drag_icon; struct wl_listener destroy; @@ -80,12 +81,34 @@ struct roots_touch { struct roots_tablet_tool { struct roots_seat *seat; struct wlr_input_device *device; + struct wlr_tablet_v2_tablet *tablet_v2; + struct wl_listener device_destroy; struct wl_listener axis; struct wl_listener proximity; struct wl_listener tip; struct wl_listener button; struct wl_list link; + + struct wl_list pads; // struct roots_tablet_pad::tablet_link +}; + +struct roots_tablet_pad { + struct wl_list link; + struct wl_list tablet_link; + struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; + + struct roots_seat *seat; + struct wlr_input_device *device; + + struct wl_listener device_destroy; + struct wl_listener attach; + struct wl_listener button; + struct wl_listener ring; + struct wl_listener strip; + + struct roots_tablet_tool *tablet; + struct wl_listener tablet_destroy; }; struct roots_seat *roots_seat_create(struct roots_input *input, char *name); diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index b71f5b9a..ec291c75 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -20,6 +20,7 @@ struct wlr_tablet_pad { struct wl_signal button; struct wl_signal ring; struct wl_signal strip; + struct wl_signal attach_tablet; //struct wlr_tablet_tool } events; size_t button_count; @@ -52,6 +53,7 @@ struct wlr_event_tablet_pad_button { uint32_t button; enum wlr_button_state state; unsigned int mode; + unsigned int group; }; enum wlr_tablet_pad_ring_source { diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 358f0719..4b2fffe4 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -5,6 +5,11 @@ #include #include +#include "tablet-unstable-v2-protocol.h" + +struct wlr_tablet_tool_client_v2; +struct wlr_tablet_pad_client_v2; + struct wlr_tablet_manager_v2 { struct wl_global *wl_global; struct wl_list clients; // wlr_tablet_manager_client_v2::link @@ -30,6 +35,8 @@ struct wlr_tablet_v2_tablet_tool { struct wl_list clients; // wlr_tablet_tool_client_v2::tablet_link struct wl_listener tool_destroy; + + struct wlr_tablet_tool_client_v2 *current_client; }; struct wlr_tablet_v2_tablet_pad { @@ -38,7 +45,12 @@ struct wlr_tablet_v2_tablet_pad { struct wlr_input_device *wlr_device; struct wl_list clients; // wlr_tablet_pad_client_v2::tablet_link + size_t group_count; + uint32_t *groups; + struct wl_listener pad_destroy; + + struct wlr_tablet_pad_client_v2 *current_client; }; struct wlr_tablet_v2_tablet *wlr_make_tablet( @@ -59,4 +71,34 @@ struct wlr_tablet_v2_tablet_tool *wlr_make_tablet_tool( struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display); void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager); +uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_send_tablet_v2_tablet_tool_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y); + +void wlr_send_tablet_v2_tablet_tool_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool); + +uint32_t wlr_send_tablet_v2_tablet_pad_enter( + struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); + +void wlr_send_tablet_v2_tablet_pad_button( + struct wlr_tablet_v2_tablet_pad *pad, size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state); + +void wlr_send_tablet_v2_tablet_pad_strip( struct wlr_tablet_v2_tablet_pad *pad, + uint32_t strip, double position, bool finger, uint32_t time); +void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t ring, double position, bool finger, uint32_t time); + +uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_surface *surface); + +uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, + size_t group, uint32_t mode, uint32_t time); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/rootston/seat.c b/rootston/seat.c index 455e9b00..8f84fc4b 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,8 @@ #include "rootston/seat.h" #include "rootston/xcursor.h" +#include + static void handle_keyboard_key(struct wl_listener *listener, void *data) { struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, keyboard_key); @@ -393,6 +396,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->pointers); wl_list_init(&seat->touch); wl_list_init(&seat->tablet_tools); + wl_list_init(&seat->tablet_pads); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -546,13 +550,152 @@ static void seat_add_touch(struct roots_seat *seat, roots_seat_configure_cursor(seat); } +static void handle_tablet_pad_destroy(struct wl_listener *listener, + void *data) { + struct roots_tablet_pad *tablet_pad = + wl_container_of(listener, tablet_pad, device_destroy); + struct roots_seat *seat = tablet_pad->seat; + + wl_list_remove(&tablet_pad->device_destroy.link); + wl_list_remove(&tablet_pad->tablet_destroy.link); + wl_list_remove(&tablet_pad->attach.link); + wl_list_remove(&tablet_pad->link); + wl_list_remove(&tablet_pad->tablet_link); + + wl_list_remove(&tablet_pad->button.link); + wl_list_remove(&tablet_pad->strip.link); + wl_list_remove(&tablet_pad->ring.link); + free(tablet_pad); + + seat_update_capabilities(seat); +} + +static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, tablet_destroy); + + pad->tablet = NULL; + wl_list_remove(&pad->tablet_link); + wl_list_init(&pad->tablet_link); + + wl_list_remove(&pad->tablet_destroy.link); + wl_list_init(&pad->tablet_destroy.link); +} + +static void attach_tablet_pad(struct roots_tablet_pad *pad, + struct roots_tablet_tool *tool) { + wlr_log(L_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", + pad->device->name, tool->device->name); + + pad->tablet = tool; + wl_list_remove(&pad->tablet_link); + wl_list_insert(&tool->pads, &pad->tablet_link); + + wl_signal_add(&tool->device->events.destroy, + &pad->tablet_destroy); +} + +static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, attach); + struct wlr_tablet_tool *wlr_tool = data; + struct roots_tablet_tool *tool = wlr_tool->data; + + attach_tablet_pad(pad, tool); +} + +static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, ring); + struct wlr_event_tablet_pad_ring *event = data; + + wlr_send_tablet_v2_tablet_pad_ring(pad->tablet_v2_pad, + event->ring, event->position, + event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, strip); + struct wlr_event_tablet_pad_strip *event = data; + + wlr_send_tablet_v2_tablet_pad_strip(pad->tablet_v2_pad, + event->strip, event->position, + event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, + event->time_msec); +} + +static void handle_tablet_pad_button(struct wl_listener *listener, void *data) { + struct roots_tablet_pad *pad = + wl_container_of(listener, pad, button); + struct wlr_event_tablet_pad_button *event = data; + + wlr_send_tablet_v2_tablet_pad_mode(pad->tablet_v2_pad, + event->group, event->mode, event->time_msec); + + wlr_send_tablet_v2_tablet_pad_button(pad->tablet_v2_pad, + event->button, event->time_msec, event->state); +} + static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { - // TODO - // FIXME: This needs to be stored on the roots_tablet_tool + struct roots_tablet_pad *tablet_pad = + calloc(sizeof(struct roots_tablet_pad), 1); + if (!tablet_pad) { + wlr_log(L_ERROR, "could not allocate tablet_pad for seat"); + return; + } + + device->data = tablet_pad; + tablet_pad->device = device; + tablet_pad->seat = seat; + wl_list_init(&tablet_pad->tablet_link); + wl_list_insert(&seat->tablet_pads, &tablet_pad->link); + + tablet_pad->device_destroy.notify = handle_tablet_pad_destroy; + wl_signal_add(&tablet_pad->device->events.destroy, + &tablet_pad->device_destroy); + + tablet_pad->tablet_destroy.notify = handle_pad_tool_destroy; + + tablet_pad->attach.notify = handle_tablet_pad_attach; + wl_signal_add(&tablet_pad->device->tablet_pad->events.attach_tablet, &tablet_pad->attach); + + tablet_pad->button.notify = handle_tablet_pad_button; + wl_signal_add(&tablet_pad->device->tablet_pad->events.button, &tablet_pad->button); + + tablet_pad->strip.notify = handle_tablet_pad_strip; + wl_signal_add(&tablet_pad->device->tablet_pad->events.strip, &tablet_pad->strip); + + tablet_pad->ring.notify = handle_tablet_pad_ring; + wl_signal_add(&tablet_pad->device->tablet_pad->events.ring, &tablet_pad->ring); + struct roots_desktop *desktop = seat->input->server->desktop; - (void)wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + tablet_pad->tablet_v2_pad = + wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device); + + /* Search for a sibling tablet */ + if (!wlr_input_device_is_libinput(device)) { + /* We can only do this on libinput devices */ + return; + } + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct roots_tablet_tool *tool; + wl_list_for_each(tool, &seat->tablet_tools, link) { + if (!wlr_input_device_is_libinput(tool->device)) { + continue; + } + + struct libinput_device *li_dev = + wlr_libinput_get_device_handle(tool->device); + if (libinput_device_get_device_group(li_dev) == group) { + attach_tablet_pad(tablet_pad, tool); + break; + } + } } static void handle_tablet_tool_destroy(struct wl_listener *listener, @@ -564,6 +707,7 @@ static void handle_tablet_tool_destroy(struct wl_listener *listener, wlr_cursor_detach_input_device(seat->cursor->cursor, tablet_tool->device); wl_list_remove(&tablet_tool->device_destroy.link); wl_list_remove(&tablet_tool->link); + wl_list_remove(&tablet_tool->pads); free(tablet_tool); seat_update_capabilities(seat); @@ -581,6 +725,7 @@ static void seat_add_tablet_tool(struct roots_seat *seat, device->data = tablet_tool; tablet_tool->device = device; tablet_tool->seat = seat; + wl_list_init(&tablet_tool->pads); wl_list_insert(&seat->tablet_tools, &tablet_tool->link); tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; @@ -592,8 +737,23 @@ static void seat_add_tablet_tool(struct roots_seat *seat, struct roots_desktop *desktop = seat->input->server->desktop; - // FIXME: This needs to be stored on the roots_tablet_tool - (void)wlr_make_tablet(desktop->tablet_v2, seat->seat, device); + tablet_tool->tablet_v2 = + wlr_make_tablet(desktop->tablet_v2, seat->seat, device); + + struct libinput_device_group *group = + libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); + struct roots_tablet_pad *pad; + wl_list_for_each(pad, &seat->tablet_pads, link) { + if (!wlr_input_device_is_libinput(pad->device)) { + continue; + } + + struct libinput_device *li_dev = + wlr_libinput_get_device_handle(pad->device); + if (libinput_device_get_device_group(li_dev) == group) { + attach_tablet_pad(pad, tablet_tool); + } + } } void roots_seat_add_device(struct roots_seat *seat, @@ -859,6 +1019,13 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); + /* FIXME: Move this to a better place */ + struct roots_tablet_pad *pad; + wl_list_for_each(pad, &seat->tablet_pads, link) { + if (pad->tablet) { + wlr_send_tablet_v2_tablet_pad_enter(pad->tablet_v2_pad, pad->tablet->tablet_v2, view->wlr_surface); + } + } } else { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, NULL, 0, NULL); diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 3d25d685..f7d6c436 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -10,6 +10,7 @@ void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, wl_signal_init(&pad->events.button); wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.strip); + wl_signal_init(&pad->events.attach_tablet); } void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) { diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 3e4eaafc..f980aa0d 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -68,6 +68,10 @@ struct wlr_tablet_tool_client_v2 { struct wl_list tool_link; struct wl_client *client; struct wl_resource *resource; + + uint32_t proximity_serial; + + struct wl_event_source *frame_source; }; struct wlr_tablet_pad_client_v2 { @@ -76,6 +80,10 @@ struct wlr_tablet_pad_client_v2 { struct wl_client *client; struct wl_resource *resource; + uint32_t enter_serial; + uint32_t mode_serial; + uint32_t leave_serial; + size_t button_count; size_t group_count; @@ -284,6 +292,10 @@ static void destroy_tablet_tool(struct wl_resource *resource) { struct wlr_tablet_tool_client_v2 *client = wl_resource_get_user_data(resource); + if (client->frame_source) { + wl_event_source_remove(client->frame_source); + } + wl_list_remove(&client->seat_link); wl_list_remove(&client->tool_link); free(client); @@ -706,6 +718,13 @@ struct wlr_tablet_v2_tablet_pad *wlr_make_tablet_pad( return NULL; } + pad->group_count = wl_list_length(&wlr_pad->groups); + pad->groups = calloc(pad->group_count, sizeof(int)); + if (!pad->groups) { + free(pad); + return NULL; + } + pad->wlr_pad = wlr_pad; wl_list_init(&pad->clients); @@ -920,3 +939,247 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { return tablet; } + +/* Actual protocol foo */ + +static void send_tool_frame(void *data) { + struct wlr_tablet_tool_client_v2 *tool = data; + + zwp_tablet_tool_v2_send_frame(tool->resource, 0); + tool->frame_source = NULL; +} + +static void queue_tool_frame(struct wlr_tablet_tool_client_v2 *tool) { + if (!tool->frame_source) { + tool->frame_source = wl_event_loop_add_idle(NULL, send_tool_frame, tool); + } +} + +uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( + struct wlr_tablet_v2_tablet_tool *tool, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + struct wlr_tablet_client_v2 *tablet_tmp; + struct wlr_tablet_client_v2 *tablet_client = NULL; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + tablet_client = tablet_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tablet_client) { + return 0; + } + + struct wlr_tablet_tool_client_v2 *tool_tmp; + struct wlr_tablet_tool_client_v2 *tool_client; + wl_list_for_each(tool_tmp, &tool->clients, tool_link) { + if (tool_tmp->client == client) { + tool_client = tool_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tool_client) { + return 0; + } + + tool->current_client = tool_client; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++tool_client->proximity_serial; + + zwp_tablet_tool_v2_send_proximity_in(tool_client->resource, serial, + tablet_client->resource, surface->resource); + queue_tool_frame(tool_client); + + return serial; +} + +void wlr_send_tablet_v2_tablet_tool_motion( + struct wlr_tablet_v2_tablet_tool *tool, double x, double y) { + if (!tool->current_client) { + return; + } + + zwp_tablet_tool_v2_send_motion(tool->current_client->resource, + wl_fixed_from_double(x), wl_fixed_from_double(y)); + + queue_tool_frame(tool->current_client); +} + +void wlr_send_tablet_v2_tablet_tool_proximity_out( + struct wlr_tablet_v2_tablet_tool *tool) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_proximity_out(tool->current_client->resource); + // XXX: Get the time for the frame + if (tool->current_client->frame_source) { + wl_event_source_remove(tool->current_client->frame_source); + send_tool_frame(tool->current_client); + } + } +} + + +uint32_t wlr_send_tablet_v2_tablet_pad_enter( + struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + struct wlr_tablet_client_v2 *tablet_tmp; + struct wlr_tablet_client_v2 *tablet_client = NULL; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + tablet_client = tablet_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!tablet_client) { + return 0; + } + + struct wlr_tablet_pad_client_v2 *pad_tmp; + struct wlr_tablet_pad_client_v2 *pad_client; + wl_list_for_each(pad_tmp, &pad->clients, pad_link) { + if (pad_tmp->client == client) { + pad_client = pad_tmp; + break; + } + } + + // Couldn't find the client binding for the surface's client. Either + // the client didn't bind tablet_v2 at all, or not for the relevant + // seat + if (!pad_client) { + return 0; + } + + pad->current_client = pad_client; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad_client->enter_serial; + + zwp_tablet_pad_v2_send_enter(pad_client->resource, serial, + tablet_client->resource, surface->resource); + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + uint32_t time = now.tv_nsec / 1000; + + for (size_t i = 0; i < pad->group_count; ++i) { + zwp_tablet_pad_group_v2_send_mode_switch( + pad_client->groups[i], time, serial, pad->groups[i]); + } + + return serial; +} + +void wlr_send_tablet_v2_tablet_pad_button( + struct wlr_tablet_v2_tablet_pad *pad, size_t button, + uint32_t time, enum zwp_tablet_pad_v2_button_state state) { + + if (pad->current_client) { + zwp_tablet_pad_v2_send_button(pad->current_client->resource, + time, button, state); + } +} + +void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t strip, double position, bool finger, uint32_t time) { + if (!pad->current_client && + pad->current_client->strips && + pad->current_client->strips[strip]) { + return; + } + struct wl_resource *resource = pad->current_client->strips[strip]; + + if (finger) { + zwp_tablet_pad_strip_v2_send_source(resource, ZWP_TABLET_PAD_STRIP_V2_SOURCE_FINGER); + } + + if (position < 0) { + zwp_tablet_pad_strip_v2_send_stop(resource); + } else { + zwp_tablet_pad_strip_v2_send_position(resource, position * 65535); + } + zwp_tablet_pad_strip_v2_send_frame(resource, time); +} + +void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, + uint32_t ring, double position, bool finger, uint32_t time) { + if (!pad->current_client || + !pad->current_client->rings || + !pad->current_client->rings[ring]) { + return; + } + struct wl_resource *resource = pad->current_client->rings[ring]; + + if (finger) { + zwp_tablet_pad_ring_v2_send_source(resource, ZWP_TABLET_PAD_RING_V2_SOURCE_FINGER); + } + + if (position < 0) { + zwp_tablet_pad_ring_v2_send_stop(resource); + } else { + zwp_tablet_pad_ring_v2_send_angle(resource, position); + } + zwp_tablet_pad_ring_v2_send_frame(resource, time); +} + +uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pad, + struct wlr_surface *surface) { + if (!pad->current_client || + wl_resource_get_client(surface->resource) != pad->current_client->client) { + return 0; + } + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad->current_client->leave_serial; + + zwp_tablet_pad_v2_send_leave(pad->current_client->resource, serial, surface->resource); + return serial; +} + +uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, + size_t group, uint32_t mode, uint32_t time) { + if (!pad->current_client || + !pad->current_client->groups || + !pad->current_client->groups[group] ) { + return 0; + } + + if (pad->groups[group] == mode) { + return 0; + } + + pad->groups[group] = mode; + + /* Pre-increment keeps 0 clean. wraparound would be after 2^32 + * proximity_in. Someone wants to do the math how long that would take? + */ + uint32_t serial = ++pad->current_client->mode_serial; + + zwp_tablet_pad_group_v2_send_mode_switch( + pad->current_client->groups[group], time, serial, mode); + return serial; +} -- cgit v1.2.3 From 391eef6ea9acfd12856970548cb75dbef83dc702 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 2 May 2018 09:26:34 +0200 Subject: Propagate most axis events to clients --- backend/libinput/tablet_tool.c | 3 +- include/rootston/seat.h | 13 ++++++ include/wlr/types/wlr_tablet_v2.h | 15 +++++++ rootston/seat.c | 93 +++++++++++++++++++++++++++++++++++++-- types/wlr_tablet_v2.c | 51 ++++++++++++++++++++- 5 files changed, 170 insertions(+), 5 deletions(-) (limited to 'include/rootston') diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index f69e41f8..36b64836 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -270,7 +270,8 @@ void handle_tablet_tool_proximity(struct libinput_event *event, // If the tool is not unique, libinput will not find it again after the // proximity out, so we should destroy it - if (!tool->unique) { + if (!tool->unique && + libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { // The tool isn't unique, it can't be on multiple tablets assert(tool->pad_refs == 1); struct wlr_libinput_tablet *tablet = diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 31ddd6fa..1a0b889a 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -111,6 +111,19 @@ struct roots_tablet_pad { struct wl_listener tablet_destroy; }; +struct roots_tablet_tool_tool { + struct wl_list link; + struct wl_list tool_link; + struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; + + struct roots_seat *seat; + + struct wl_listener tool_destroy; + + struct roots_tablet_tool *current_tablet; + struct wl_listener tablet_destroy; +}; + struct roots_seat *roots_seat_create(struct roots_input *input, char *name); void roots_seat_destroy(struct roots_seat *seat); diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 4b2fffe4..a07a0177 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -7,6 +7,7 @@ #include "tablet-unstable-v2-protocol.h" +struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -27,6 +28,8 @@ struct wlr_tablet_v2_tablet { struct wl_list clients; // wlr_tablet_client_v2::tablet_link struct wl_listener tool_destroy; + + struct wlr_tablet_client_v2 *current_client; }; struct wlr_tablet_v2_tablet_tool { @@ -37,6 +40,9 @@ struct wlr_tablet_v2_tablet_tool { struct wl_listener tool_destroy; struct wlr_tablet_tool_client_v2 *current_client; + struct wlr_surface *focused_surface; + struct wl_listener surface_destroy; + struct wl_listener client_destroy; }; struct wlr_tablet_v2_tablet_pad { @@ -79,6 +85,12 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( void wlr_send_tablet_v2_tablet_tool_motion( struct wlr_tablet_v2_tablet_tool *tool, double x, double y); +void wlr_send_tablet_v2_tablet_tool_distance( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance); + +void wlr_send_tablet_v2_tablet_tool_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks); + void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); @@ -101,4 +113,7 @@ uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pa uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad, size_t group, uint32_t mode, uint32_t time); + +bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface); #endif /* WLR_TYPES_WLR_TABLET_V2_H */ diff --git a/rootston/seat.c b/rootston/seat.c index 8f84fc4b..eb909e78 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -101,13 +101,75 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { roots_cursor_handle_touch_motion(cursor, event); } +static void handle_tablet_tool_position(struct roots_cursor *cursor, + struct roots_tablet_tool *tool, + struct wlr_tablet_tool_tool *tool_tool, + bool change_x, bool change_y, double x, double y, + uint32_t time) { + if (!change_x && !change_y) { + return; + } + + wlr_cursor_warp_absolute(cursor->cursor, tool->device, + change_x ? x : -1 , change_y ? y : -1); + + double sx, sy; + struct roots_view *view = NULL; + struct roots_seat *seat = cursor->seat; + struct roots_desktop *desktop = seat->input->server->desktop; + struct wlr_surface *surface = desktop_surface_at(desktop, + cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); + struct roots_tablet_tool_tool *roots_tool = tool_tool->data; + + if (!surface) { + wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + /* XXX: TODO: Fallback pointer semantics */ + return; + } + + if (!wlr_surface_accepts_tablet_v2(tool->tablet_v2, surface)) { + wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); + /* XXX: TODO: Fallback pointer semantics */ + return; + } + + wlr_send_tablet_v2_tablet_tool_proximity_in(roots_tool->tablet_v2_tool, + tool->tablet_v2, surface); + + wlr_send_tablet_v2_tablet_tool_motion(roots_tool->tablet_v2_tool, sx, sy); +} + static void handle_tool_axis(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool Axis"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_axis *event = data; - roots_cursor_handle_tool_axis(cursor, event); + struct roots_tablet_tool_tool *roots_tool = event->tool->data; + + if (!roots_tool) { + wlr_log(L_DEBUG, "Tool Axis, before proximity"); + return; + } + + /** + * We need to handle them ourselves, not pass it into the cursor + * without any consideration + */ + handle_tablet_tool_position(cursor, event->device->data, event->tool, + event->updated_axes & WLR_TABLET_TOOL_AXIS_X, + event->updated_axes & WLR_TABLET_TOOL_AXIS_Y, + event->x, event->y, event->time_msec); + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { + wlr_send_tablet_v2_tablet_tool_distance(roots_tool->tablet_v2_tool, event->distance); + } + + if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { + wlr_send_tablet_v2_tablet_tool_wheel(roots_tool->tablet_v2_tool, event->wheel_delta, 0); + } + //roots_cursor_handle_tool_axis(cursor, event); } static void handle_tool_tip(struct wl_listener *listener, void *data) { @@ -119,7 +181,22 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { roots_cursor_handle_tool_tip(cursor, event); } +static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool destroy"); + struct roots_tablet_tool_tool *tool = + wl_container_of(listener, tool, tool_destroy); + + wl_list_remove(&tool->link); + wl_list_remove(&tool->tool_link); + + wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->tablet_destroy.link); + + free(tool); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Tool Proximity"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -128,8 +205,18 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct wlr_tablet_tool_tool *tool = event->tool; if (!tool->data) { - tool->data = wlr_make_tablet_tool(desktop->tablet_v2, cursor->seat->seat, tool); - } + struct roots_tablet_tool_tool *roots_tool = + calloc(1, sizeof(struct roots_tablet_tool_tool)); + roots_tool->seat = cursor->seat; + tool->data = roots_tool; + roots_tool->tablet_v2_tool = + wlr_make_tablet_tool(desktop->tablet_v2, cursor->seat->seat, tool); + roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; + wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); + } + + handle_tablet_tool_position(cursor, event->device->data, event->tool, + true, true, event->x, event->y, event->time_msec); } static void handle_request_set_cursor(struct wl_listener *listener, diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index f980aa0d..042713b7 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -950,8 +950,11 @@ static void send_tool_frame(void *data) { } static void queue_tool_frame(struct wlr_tablet_tool_client_v2 *tool) { + struct wl_display *display = wl_client_get_display(tool->client); + struct wl_event_loop *loop = wl_display_get_event_loop(display); if (!tool->frame_source) { - tool->frame_source = wl_event_loop_add_idle(NULL, send_tool_frame, tool); + tool->frame_source = + wl_event_loop_add_idle(loop, send_tool_frame, tool); } } @@ -961,6 +964,10 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( struct wlr_surface *surface) { struct wl_client *client = wl_resource_get_client(surface->resource); + if (tool->focused_surface == surface) { + return 0; + } + struct wlr_tablet_client_v2 *tablet_tmp; struct wlr_tablet_client_v2 *tablet_client = NULL; wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { @@ -1004,6 +1011,7 @@ uint32_t wlr_send_tablet_v2_tablet_tool_proximity_in( tablet_client->resource, surface->resource); queue_tool_frame(tool_client); + tool->focused_surface = surface; return serial; } @@ -1028,9 +1036,31 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( wl_event_source_remove(tool->current_client->frame_source); send_tool_frame(tool->current_client); } + tool->current_client = NULL; + } +} + +void wlr_send_tablet_v2_tablet_tool_distance( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_distance(tool->current_client->resource, + distance); + + queue_tool_frame(tool->current_client); } } +void wlr_send_tablet_v2_tablet_tool_wheel( + struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { + if (tool->current_client) { + zwp_tablet_tool_v2_send_wheel(tool->current_client->resource, + clicks, delta); + + queue_tool_frame(tool->current_client); + } + +} + uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, @@ -1183,3 +1213,22 @@ uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad pad->current_client->groups[group], time, serial, mode); return serial; } + +bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + + if (tablet->current_client && + tablet->current_client->client == client) { + return true; + } + + struct wlr_tablet_client_v2 *tablet_tmp; + wl_list_for_each(tablet_tmp, &tablet->clients, tablet_link) { + if (tablet_tmp->client == client) { + return true; + } + } + + return false; +} -- cgit v1.2.3 From 5c7a37f30922d973e176b0eec29bb5fddf241eee Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 4 May 2018 11:46:32 +0200 Subject: Add tool buttons --- backend/libinput/tablet_tool.c | 5 +++- include/rootston/cursor.h | 1 + include/wlr/types/wlr_tablet_v2.h | 11 +++++++ rootston/seat.c | 19 +++++++++--- types/wlr_tablet_v2.c | 63 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 91 insertions(+), 8 deletions(-) (limited to 'include/rootston') diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 36b64836..3a39f5dc 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -263,11 +263,14 @@ void handle_tablet_tool_proximity(struct libinput_event *event, break; case LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN: wlr_event.state = WLR_TABLET_TOOL_PROXIMITY_IN; - handle_tablet_tool_axis(event, libinput_dev); break; } wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event); + if (libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { + handle_tablet_tool_axis(event, libinput_dev); + } + // If the tool is not unique, libinput will not find it again after the // proximity out, so we should destroy it if (!tool->unique && diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 0478c3ca..f7410dec 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -41,6 +41,7 @@ struct roots_cursor { struct wl_listener tool_axis; struct wl_listener tool_tip; struct wl_listener tool_proximity; + struct wl_listener tool_button; struct wl_listener request_set_cursor; }; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index a07a0177..12995308 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -7,6 +7,9 @@ #include "tablet-unstable-v2-protocol.h" +/* This can probably be even lower,the tools don't have a lot of buttons */ +#define WLR_TABLEt_V2_TOOL_BUTTONS_CAP 16 + struct wlr_tablet_client_v2; struct wlr_tablet_tool_client_v2; struct wlr_tablet_pad_client_v2; @@ -43,6 +46,10 @@ struct wlr_tablet_v2_tablet_tool { struct wlr_surface *focused_surface; struct wl_listener surface_destroy; struct wl_listener client_destroy; + + uint32_t button_serial; + size_t num_buttons; + uint32_t pressed_buttons[WLR_TABLEt_V2_TOOL_BUTTONS_CAP]; }; struct wlr_tablet_v2_tablet_pad { @@ -94,6 +101,10 @@ void wlr_send_tablet_v2_tablet_tool_wheel( void wlr_send_tablet_v2_tablet_tool_proximity_out( struct wlr_tablet_v2_tablet_tool *tool); +uint32_t wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state); + uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_v2_tablet *tablet, diff --git a/rootston/seat.c b/rootston/seat.c index eb909e78..eb1e7e0b 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -140,7 +140,6 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, } static void handle_tool_axis(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool Axis"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -148,7 +147,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_axis *event = data; struct roots_tablet_tool_tool *roots_tool = event->tool->data; - if (!roots_tool) { + if (!roots_tool) { // Should this be an assert? wlr_log(L_DEBUG, "Tool Axis, before proximity"); return; } @@ -182,7 +181,6 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool destroy"); struct roots_tablet_tool_tool *tool = wl_container_of(listener, tool, tool_destroy); @@ -195,8 +193,18 @@ static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void * free(tool); } +static void handle_tool_button(struct wl_listener *listener, void *data) { + struct roots_cursor *cursor = + wl_container_of(listener, cursor, tool_button); + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); + struct wlr_event_tablet_tool_button *event = data; + struct roots_tablet_tool_tool *roots_tool = event->tool->data; + + wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, event->button, event->state); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { - wlr_log(L_DEBUG, "Tool Proximity"); struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); struct roots_desktop *desktop = cursor->seat->input->server->desktop; @@ -358,6 +366,9 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wl_signal_add(&wlr_cursor->events.tablet_tool_proximity, &seat->cursor->tool_proximity); seat->cursor->tool_proximity.notify = handle_tool_proximity; + wl_signal_add(&wlr_cursor->events.tablet_tool_button, &seat->cursor->tool_button); + seat->cursor->tool_button.notify = handle_tool_button; + wl_signal_add(&seat->seat->events.request_set_cursor, &seat->cursor->request_set_cursor); seat->cursor->request_set_cursor.notify = handle_request_set_cursor; diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 042713b7..104de65f 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -941,6 +941,47 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { } /* Actual protocol foo */ +// https://www.geeksforgeeks.org/move-zeroes-end-array/ +static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { + size_t count = 0; + + for (size_t i = 0; i < n; i++) { + if (arr[i] != 0) { + arr[count++] = arr[i]; + } + } + + size_t ret = count; + + while (count < n) { + arr[count++] = 0; + } + + return ret; +} + +static void tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, + uint32_t button, enum zwp_tablet_pad_v2_button_state state) { + bool found = false; + size_t i = 0; + for (; i < tool->num_buttons; ++i) { + if (tool->pressed_buttons[i] == button) { + found = true; + break; + } + } + + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && + tool->num_buttons < WLR_TABLEt_V2_TOOL_BUTTONS_CAP) { + tool->pressed_buttons[tool->num_buttons++] = button; + } + if (button == ZWP_TABLET_PAD_V2_BUTTON_STATE_RELEASED && found) { + tool->pressed_buttons[i] = 0; + tool->num_buttons = push_zeroes_to_end(tool->pressed_buttons, WLR_TABLEt_V2_TOOL_BUTTONS_CAP); + } + + assert(tool->num_buttons <= WLR_TABLEt_V2_TOOL_BUTTONS_CAP); +} static void send_tool_frame(void *data) { struct wlr_tablet_tool_client_v2 *tool = data; @@ -1041,7 +1082,7 @@ void wlr_send_tablet_v2_tablet_tool_proximity_out( } void wlr_send_tablet_v2_tablet_tool_distance( - struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { + struct wlr_tablet_v2_tablet_tool *tool, uint32_t distance) { if (tool->current_client) { zwp_tablet_tool_v2_send_distance(tool->current_client->resource, distance); @@ -1050,6 +1091,24 @@ void wlr_send_tablet_v2_tablet_tool_distance( } } +uint32_t wlr_send_tablet_v2_tablet_tool_button( + struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, + enum zwp_tablet_pad_v2_button_state state) { + tablet_tool_button_update(tool, button, state); + + if (tool->current_client) { + uint32_t serial = ++tool->button_serial; + + zwp_tablet_tool_v2_send_button(tool->current_client->resource, + serial, button, state); + queue_tool_frame(tool->current_client); + + return serial; + } + + return 0; +} + void wlr_send_tablet_v2_tablet_tool_wheel( struct wlr_tablet_v2_tablet_tool *tool, double delta, int32_t clicks) { if (tool->current_client) { @@ -1058,10 +1117,8 @@ void wlr_send_tablet_v2_tablet_tool_wheel( queue_tool_frame(tool->current_client); } - } - uint32_t wlr_send_tablet_v2_tablet_pad_enter( struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_v2_tablet *tablet, -- cgit v1.2.3 From b79d11395c9f8f26287e17e80066fd9034f05266 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 17 May 2018 09:59:37 +0200 Subject: Hook up set_cursor in rootston --- include/rootston/seat.h | 1 + include/wlr/types/wlr_tablet_v2.h | 1 + rootston/seat.c | 22 ++++++++++++++++++++++ types/wlr_tablet_v2.c | 27 ++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 5 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 1a0b889a..258c8840 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -118,6 +118,7 @@ struct roots_tablet_tool_tool { struct roots_seat *seat; + struct wl_listener set_cursor; struct wl_listener tool_destroy; struct roots_tablet_tool *current_tablet; diff --git a/include/wlr/types/wlr_tablet_v2.h b/include/wlr/types/wlr_tablet_v2.h index 0be672cb..5de12ec8 100644 --- a/include/wlr/types/wlr_tablet_v2.h +++ b/include/wlr/types/wlr_tablet_v2.h @@ -81,6 +81,7 @@ struct wlr_tablet_v2_event_cursor { uint32_t serial; int32_t hotspot_x; int32_t hotspot_y; + struct wlr_seat_client *seat_client; }; struct wlr_tablet_v2_event_feedback { diff --git a/rootston/seat.c b/rootston/seat.c index 6b12f682..3ca1404e 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -188,6 +188,7 @@ static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void * wl_list_remove(&tool->tool_link); wl_list_remove(&tool->tool_destroy.link); + wl_list_remove(&tool->set_cursor.link); free(tool); } @@ -203,6 +204,23 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, event->button, event->state); } +static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { + struct roots_tablet_tool_tool *tool = + wl_container_of(listener, tool, set_cursor); + struct wlr_tablet_v2_event_cursor *evt = data; + + + struct wlr_seat_pointer_request_set_cursor_event event = { + .surface = evt->surface, + .hotspot_x = evt->hotspot_x, + .hotspot_y = evt->hotspot_y, + .serial = evt->serial, + .seat_client = evt->seat_client, + }; + + roots_cursor_handle_request_set_cursor(tool->seat->cursor, &event); +} + static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct roots_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); @@ -221,6 +239,10 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { cursor->seat->seat, tool); roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); + + roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor; + wl_signal_add(&roots_tool->tablet_v2_tool->events.set_cursor, &roots_tool->set_cursor); + wl_list_init(&roots_tool->link); wl_list_init(&roots_tool->tool_link); } diff --git a/types/wlr_tablet_v2.c b/types/wlr_tablet_v2.c index 52089c47..5dec1c5d 100644 --- a/types/wlr_tablet_v2.c +++ b/types/wlr_tablet_v2.c @@ -67,6 +67,7 @@ struct wlr_tablet_tool_client_v2 { struct wl_client *client; struct wl_resource *resource; struct wlr_tablet_v2_tablet_tool *tool; + struct wlr_tablet_seat_client_v2 *seat; uint32_t proximity_serial; @@ -262,24 +263,34 @@ static void handle_wlr_tablet_destroy(struct wl_listener *listener, void *data) free(tablet); } +static const struct wlr_surface_role pointer_cursor_surface_role = { + .name = "wl_pointer-cursor", +}; + static void handle_tablet_tool_v2_set_cursor(struct wl_client *client, - struct wl_resource *resource, - uint32_t serial, + struct wl_resource *resource, uint32_t serial, struct wl_resource *surface_resource, - int32_t hotspot_x, - int32_t hotspot_y) { + int32_t hotspot_x, int32_t hotspot_y) { struct wlr_tablet_tool_client_v2 *tool = wl_resource_get_user_data(resource); if (!tool) { return; } - struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); + struct wlr_surface *surface; + if (surface_resource != NULL) { + surface = wlr_surface_from_resource(surface_resource); + if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, + surface_resource, WL_POINTER_ERROR_ROLE)) { + return; + } + } struct wlr_tablet_v2_event_cursor evt = { .surface = surface, .serial = serial, .hotspot_x = hotspot_x, .hotspot_y = hotspot_y, + .seat_client = tool->seat->seat, }; wl_signal_emit(&tool->tool->events.set_cursor, &evt); @@ -324,6 +335,10 @@ static void destroy_tablet_tool(struct wl_resource *resource) { wl_event_source_remove(client->frame_source); } + if (client->tool && client->tool->current_client == client) { + client->tool->current_client = NULL; + } + wl_list_remove(&client->seat_link); wl_list_remove(&client->tool_link); free(client); @@ -337,6 +352,7 @@ static void add_tablet_tool_client(struct wlr_tablet_seat_client_v2 *seat, return; } client->tool = tool; + client->seat = seat; client->resource = wl_resource_create(seat->wl_client, &zwp_tablet_tool_v2_interface, 1, 0); @@ -444,6 +460,7 @@ static void handle_wlr_tablet_tool_destroy(struct wl_listener *listener, void *d wl_list_for_each_safe(pos, tmp, &tool->clients, tool_link) { // XXX: Add a timer/flag to destroy if client is slow? zwp_tablet_tool_v2_send_removed(pos->resource); + pos->tool = NULL; } wl_list_remove(&tool->clients); -- cgit v1.2.3 From b84288af16f56295a66d58bdb41b7ba7c4dd54f3 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Thu, 14 Jun 2018 11:56:14 +0200 Subject: Remove unused tablet_pad list from tools --- include/rootston/seat.h | 3 --- rootston/seat.c | 8 -------- 2 files changed, 11 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 258c8840..071103cf 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -89,13 +89,10 @@ struct roots_tablet_tool { struct wl_listener tip; struct wl_listener button; struct wl_list link; - - struct wl_list pads; // struct roots_tablet_pad::tablet_link }; struct roots_tablet_pad { struct wl_list link; - struct wl_list tablet_link; struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; struct roots_seat *seat; diff --git a/rootston/seat.c b/rootston/seat.c index e95fa7f4..5bd6e752 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -719,7 +719,6 @@ static void handle_tablet_pad_destroy(struct wl_listener *listener, wl_list_remove(&tablet_pad->tablet_destroy.link); wl_list_remove(&tablet_pad->attach.link); wl_list_remove(&tablet_pad->link); - wl_list_remove(&tablet_pad->tablet_link); wl_list_remove(&tablet_pad->button.link); wl_list_remove(&tablet_pad->strip.link); @@ -734,8 +733,6 @@ static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, pad, tablet_destroy); pad->tablet = NULL; - wl_list_remove(&pad->tablet_link); - wl_list_init(&pad->tablet_link); wl_list_remove(&pad->tablet_destroy.link); wl_list_init(&pad->tablet_destroy.link); @@ -747,8 +744,6 @@ static void attach_tablet_pad(struct roots_tablet_pad *pad, pad->device->name, tool->device->name); pad->tablet = tool; - wl_list_remove(&pad->tablet_link); - wl_list_insert(&tool->pads, &pad->tablet_link); pad->tablet_destroy.notify = handle_pad_tool_destroy; wl_signal_add(&tool->device->events.destroy, &pad->tablet_destroy); @@ -810,7 +805,6 @@ static void seat_add_tablet_pad(struct roots_seat *seat, device->data = tablet_pad; tablet_pad->device = device; tablet_pad->seat = seat; - wl_list_init(&tablet_pad->tablet_link); wl_list_insert(&seat->tablet_pads, &tablet_pad->link); tablet_pad->device_destroy.notify = handle_tablet_pad_destroy; @@ -865,7 +859,6 @@ static void handle_tablet_tool_destroy(struct wl_listener *listener, wlr_cursor_detach_input_device(seat->cursor->cursor, tablet_tool->device); wl_list_remove(&tablet_tool->device_destroy.link); wl_list_remove(&tablet_tool->link); - wl_list_remove(&tablet_tool->pads); free(tablet_tool); seat_update_capabilities(seat); @@ -883,7 +876,6 @@ static void seat_add_tablet_tool(struct roots_seat *seat, device->data = tablet_tool; tablet_tool->device = device; tablet_tool->seat = seat; - wl_list_init(&tablet_tool->pads); wl_list_insert(&seat->tablet_tools, &tablet_tool->link); tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; -- cgit v1.2.3 From 9313ac1068105286a9541e540bd93cd2b2d5e5e9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Mon, 18 Jun 2018 09:30:32 +0200 Subject: propagate rename to rootston code --- include/rootston/seat.h | 10 ++--- rootston/seat.c | 98 ++++++++++++++++++++++++------------------------- 2 files changed, 54 insertions(+), 54 deletions(-) (limited to 'include/rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 071103cf..3ddb97c5 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -30,7 +30,7 @@ struct roots_seat { struct wl_list keyboards; struct wl_list pointers; struct wl_list touch; - struct wl_list tablet_tools; + struct wl_list tablets; struct wl_list tablet_pads; struct wl_listener new_drag_icon; @@ -78,7 +78,7 @@ struct roots_touch { struct wl_list link; }; -struct roots_tablet_tool { +struct roots_tablet { struct roots_seat *seat; struct wlr_input_device *device; struct wlr_tablet_v2_tablet *tablet_v2; @@ -104,11 +104,11 @@ struct roots_tablet_pad { struct wl_listener ring; struct wl_listener strip; - struct roots_tablet_tool *tablet; + struct roots_tablet *tablet; struct wl_listener tablet_destroy; }; -struct roots_tablet_tool_tool { +struct roots_tablet_tool { struct wl_list link; struct wl_list tool_link; struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; @@ -118,7 +118,7 @@ struct roots_tablet_tool_tool { struct wl_listener set_cursor; struct wl_listener tool_destroy; - struct roots_tablet_tool *current_tablet; + struct roots_tablet *current_tablet; struct wl_listener tablet_destroy; }; diff --git a/rootston/seat.c b/rootston/seat.c index 89a32fa9..892faaa0 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -102,21 +102,21 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_position(struct roots_cursor *cursor, - struct roots_tablet_tool *tool, - struct wlr_tablet_tool *tool_tool, + struct roots_tablet *tablet, + struct wlr_tablet_tool *tool, bool change_x, bool change_y, double x, double y, double dx, double dy) { if (!change_x && !change_y) { return; } - switch (tool_tool->type) { + switch (tool->type) { case WLR_TABLET_TOOL_TYPE_MOUSE: // They are 0 either way when they weren't modified - wlr_cursor_move(cursor->cursor, tool->device, dx, dy); + wlr_cursor_move(cursor->cursor, tablet->device, dx, dy); break; default: - wlr_cursor_warp_absolute(cursor->cursor, tool->device, + wlr_cursor_warp_absolute(cursor->cursor, tablet->device, change_x ? x : NAN, change_y ? y : NAN); } @@ -126,7 +126,7 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, struct roots_desktop *desktop = seat->input->server->desktop; struct wlr_surface *surface = desktop_surface_at(desktop, cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); - struct roots_tablet_tool_tool *roots_tool = tool_tool->data; + struct roots_tablet_tool *roots_tool = tool->data; if (!surface) { wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); @@ -134,14 +134,14 @@ static void handle_tablet_tool_position(struct roots_cursor *cursor, return; } - if (!wlr_surface_accepts_tablet_v2(tool->tablet_v2, surface)) { + if (!wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) { wlr_send_tablet_v2_tablet_tool_proximity_out(roots_tool->tablet_v2_tool); /* XXX: TODO: Fallback pointer semantics */ return; } wlr_send_tablet_v2_tablet_tool_proximity_in(roots_tool->tablet_v2_tool, - tool->tablet_v2, surface); + tablet->tablet_v2, surface); wlr_send_tablet_v2_tablet_tool_motion(roots_tool->tablet_v2_tool, sx, sy); } @@ -152,7 +152,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_axis *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; if (!roots_tool) { // Should this be an assert? wlr_log(WLR_DEBUG, "Tool Axis, before proximity"); @@ -205,7 +205,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_tip *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; if (event->state == WLR_TABLET_TOOL_TIP_DOWN) { wlr_send_tablet_v2_tablet_tool_down(roots_tool->tablet_v2_tool); @@ -214,8 +214,8 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { } } -static void handle_tablet_tool_tool_destroy(struct wl_listener *listener, void *data) { - struct roots_tablet_tool_tool *tool = +static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) { + struct roots_tablet_tool *tool = wl_container_of(listener, tool, tool_destroy); wl_list_remove(&tool->link); @@ -233,7 +233,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; wlr_idle_notify_activity(desktop->idle, cursor->seat->seat); struct wlr_event_tablet_tool_button *event = data; - struct roots_tablet_tool_tool *roots_tool = event->tool->data; + struct roots_tablet_tool *roots_tool = event->tool->data; wlr_send_tablet_v2_tablet_tool_button(roots_tool->tablet_v2_tool, (enum zwp_tablet_pad_v2_button_state)event->button, @@ -241,7 +241,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { } static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) { - struct roots_tablet_tool_tool *tool = + struct roots_tablet_tool *tool = wl_container_of(listener, tool, set_cursor); struct wlr_tablet_v2_event_cursor *evt = data; @@ -266,14 +266,14 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct wlr_tablet_tool *tool = event->tool; if (!tool->data) { - struct roots_tablet_tool_tool *roots_tool = - calloc(1, sizeof(struct roots_tablet_tool_tool)); + struct roots_tablet_tool *roots_tool = + calloc(1, sizeof(struct roots_tablet_tool)); roots_tool->seat = cursor->seat; tool->data = roots_tool; roots_tool->tablet_v2_tool = wlr_tablet_tool_create(desktop->tablet_v2, cursor->seat->seat, tool); - roots_tool->tool_destroy.notify = handle_tablet_tool_tool_destroy; + roots_tool->tool_destroy.notify = handle_tablet_tool_destroy; wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy); roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor; @@ -337,7 +337,7 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { struct roots_pointer *pointer; struct roots_touch *touch; - struct roots_tablet_tool *tablet_tool; + struct roots_tablet *tablet; struct roots_output *output; // reset mappings @@ -348,8 +348,8 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { wl_list_for_each(touch, &seat->touch, link) { seat_reset_device_mappings(seat, touch->device); } - wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - seat_reset_device_mappings(seat, tablet_tool->device); + wl_list_for_each(tablet, &seat->tablets, link) { + seat_reset_device_mappings(seat, tablet->device); } // configure device to output mappings @@ -369,8 +369,8 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { seat_set_device_output_mappings(seat, pointer->device, output->wlr_output); } - wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - seat_set_device_output_mappings(seat, tablet_tool->device, + wl_list_for_each(tablet, &seat->tablets, link) { + seat_set_device_output_mappings(seat, tablet->device, output->wlr_output); } wl_list_for_each(touch, &seat->touch, link) { @@ -554,7 +554,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_init(&seat->keyboards); wl_list_init(&seat->pointers); wl_list_init(&seat->touch); - wl_list_init(&seat->tablet_tools); + wl_list_init(&seat->tablets); wl_list_init(&seat->tablet_pads); wl_list_init(&seat->views); wl_list_init(&seat->drag_icons); @@ -589,7 +589,7 @@ static void seat_update_capabilities(struct roots_seat *seat) { if (!wl_list_empty(&seat->keyboards)) { caps |= WL_SEAT_CAPABILITY_KEYBOARD; } - if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablet_tools)) { + if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablets)) { caps |= WL_SEAT_CAPABILITY_POINTER; } if (!wl_list_empty(&seat->touch)) { @@ -739,7 +739,7 @@ static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) { } static void attach_tablet_pad(struct roots_tablet_pad *pad, - struct roots_tablet_tool *tool) { + struct roots_tablet *tool) { wlr_log(WLR_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"", pad->device->name, tool->device->name); @@ -753,7 +753,7 @@ static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) { struct roots_tablet_pad *pad = wl_container_of(listener, pad, attach); struct wlr_tablet_tool *wlr_tool = data; - struct roots_tablet_tool *tool = wlr_tool->data; + struct roots_tablet *tool = wlr_tool->data; attach_tablet_pad(pad, tool); } @@ -835,8 +835,8 @@ static void seat_add_tablet_pad(struct roots_seat *seat, struct libinput_device_group *group = libinput_device_get_device_group(wlr_libinput_get_device_handle(device)); - struct roots_tablet_tool *tool; - wl_list_for_each(tool, &seat->tablet_tools, link) { + struct roots_tablet *tool; + wl_list_for_each(tool, &seat->tablets, link) { if (!wlr_input_device_is_libinput(tool->device)) { continue; } @@ -850,44 +850,44 @@ static void seat_add_tablet_pad(struct roots_seat *seat, } } -static void handle_tablet_tool_destroy(struct wl_listener *listener, +static void handle_tablet_destroy(struct wl_listener *listener, void *data) { - struct roots_tablet_tool *tablet_tool = - wl_container_of(listener, tablet_tool, device_destroy); - struct roots_seat *seat = tablet_tool->seat; + struct roots_tablet *tablet = + wl_container_of(listener, tablet, device_destroy); + struct roots_seat *seat = tablet->seat; - wlr_cursor_detach_input_device(seat->cursor->cursor, tablet_tool->device); - wl_list_remove(&tablet_tool->device_destroy.link); - wl_list_remove(&tablet_tool->link); - free(tablet_tool); + wlr_cursor_detach_input_device(seat->cursor->cursor, tablet->device); + wl_list_remove(&tablet->device_destroy.link); + wl_list_remove(&tablet->link); + free(tablet); seat_update_capabilities(seat); } static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { - struct roots_tablet_tool *tablet_tool = - calloc(1, sizeof(struct roots_tablet_tool)); - if (!tablet_tool) { - wlr_log(WLR_ERROR, "could not allocate tablet_tool for seat"); + struct roots_tablet *tablet = + calloc(1, sizeof(struct roots_tablet)); + if (!tablet) { + wlr_log(WLR_ERROR, "could not allocate tablet for seat"); return; } - device->data = tablet_tool; - tablet_tool->device = device; - tablet_tool->seat = seat; - wl_list_insert(&seat->tablet_tools, &tablet_tool->link); + device->data = tablet; + tablet->device = device; + tablet->seat = seat; + wl_list_insert(&seat->tablets, &tablet->link); - tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; - wl_signal_add(&tablet_tool->device->events.destroy, - &tablet_tool->device_destroy); + tablet->device_destroy.notify = handle_tablet_destroy; + wl_signal_add(&tablet->device->events.destroy, + &tablet->device_destroy); wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); struct roots_desktop *desktop = seat->input->server->desktop; - tablet_tool->tablet_v2 = + tablet->tablet_v2 = wlr_tablet_create(desktop->tablet_v2, seat->seat, device); struct libinput_device_group *group = @@ -901,7 +901,7 @@ static void seat_add_tablet_tool(struct roots_seat *seat, struct libinput_device *li_dev = wlr_libinput_get_device_handle(pad->device); if (libinput_device_get_device_group(li_dev) == group) { - attach_tablet_pad(pad, tablet_tool); + attach_tablet_pad(pad, tablet); } } } -- cgit v1.2.3