mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
Implement basic tablet_pad handling (bound to keyboard focus)
This commit is contained in:
parent
f696e980f1
commit
f375246657
7 changed files with 506 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wlr/types/wlr_input_device.h>
|
||||
|
||||
#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 */
|
||||
|
|
179
rootston/seat.c
179
rootston/seat.c
|
@ -5,6 +5,7 @@
|
|||
#include <time.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/config.h>
|
||||
#include <wlr/backend/libinput.h>
|
||||
#include <wlr/types/wlr_idle.h>
|
||||
#include <wlr/types/wlr_layer_shell.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
|
@ -16,6 +17,8 @@
|
|||
#include "rootston/seat.h"
|
||||
#include "rootston/xcursor.h"
|
||||
|
||||
#include <libinput.h>
|
||||
|
||||
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_desktop *desktop = seat->input->server->desktop;
|
||||
(void)wlr_make_tablet_pad(desktop->tablet_v2, seat->seat, device);
|
||||
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;
|
||||
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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue