mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
tablet-v2 tablet_pad grab implementation
Implement the basic logic for tablet-v2 tablet_pad's grabs. And plug in the default grab. Features like "holding" the focus should be implemented via grabs, like they are for pointer and keyboard.
This commit is contained in:
parent
2a58d4467f
commit
454f2a84a8
3 changed files with 196 additions and 6 deletions
|
@ -10,6 +10,14 @@
|
|||
/* 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_pad_v2_grab_interface;
|
||||
|
||||
struct wlr_tablet_pad_v2_grab {
|
||||
const struct wlr_tablet_pad_v2_grab_interface *interface;
|
||||
struct wlr_tablet_v2_tablet_pad *pad;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_tablet_client_v2;
|
||||
struct wlr_tablet_tool_client_v2;
|
||||
struct wlr_tablet_pad_client_v2;
|
||||
|
@ -70,6 +78,8 @@ struct wlr_tablet_v2_tablet_pad {
|
|||
struct wl_listener pad_destroy;
|
||||
|
||||
struct wlr_tablet_pad_client_v2 *current_client;
|
||||
struct wlr_tablet_pad_v2_grab *grab;
|
||||
struct wlr_tablet_pad_v2_grab default_grab;
|
||||
|
||||
struct {
|
||||
struct wl_signal button_feedback; // struct wlr_tablet_v2_event_feedback
|
||||
|
@ -155,7 +165,7 @@ 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,
|
||||
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);
|
||||
|
@ -166,6 +176,56 @@ 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);
|
||||
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_enter(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
struct wlr_tablet_v2_tablet *tablet,
|
||||
struct wlr_surface *surface);
|
||||
|
||||
void wlr_tablet_v2_tablet_pad_notify_button(
|
||||
struct wlr_tablet_v2_tablet_pad *pad, size_t button,
|
||||
uint32_t time, enum zwp_tablet_pad_v2_button_state state);
|
||||
|
||||
void wlr_tablet_v2_tablet_pad_notify_strip(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
uint32_t strip, double position, bool finger, uint32_t time);
|
||||
void wlr_tablet_v2_tablet_pad_notify_ring(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
uint32_t ring, double position, bool finger, uint32_t time);
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_leave(
|
||||
struct wlr_tablet_v2_tablet_pad *pad, struct wlr_surface *surface);
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_mode(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
size_t group, uint32_t mode, uint32_t time);
|
||||
|
||||
struct wlr_tablet_pad_v2_grab_interface {
|
||||
uint32_t (*enter)(
|
||||
struct wlr_tablet_pad_v2_grab *grab,
|
||||
struct wlr_tablet_v2_tablet *tablet,
|
||||
struct wlr_surface *surface);
|
||||
|
||||
void (*button)(struct wlr_tablet_pad_v2_grab *grab,size_t button,
|
||||
uint32_t time, enum zwp_tablet_pad_v2_button_state state);
|
||||
|
||||
void (*strip)(struct wlr_tablet_pad_v2_grab *grab,
|
||||
uint32_t strip, double position, bool finger, uint32_t time);
|
||||
void (*ring)(struct wlr_tablet_pad_v2_grab *grab,
|
||||
uint32_t ring, double position, bool finger, uint32_t time);
|
||||
|
||||
uint32_t (*leave)(struct wlr_tablet_pad_v2_grab *grab,
|
||||
struct wlr_surface *surface);
|
||||
|
||||
uint32_t (*mode)(struct wlr_tablet_pad_v2_grab *grab,
|
||||
size_t group, uint32_t mode, uint32_t time);
|
||||
|
||||
void (*cancel)(struct wlr_tablet_pad_v2_grab *grab);
|
||||
};
|
||||
|
||||
void wlr_tablet_v2_end_grab(struct wlr_tablet_v2_tablet_pad *pad);
|
||||
void wlr_tablet_v2_start_grab(struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_pad_v2_grab *grab);
|
||||
|
||||
bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet,
|
||||
struct wlr_surface *surface);
|
||||
#endif /* WLR_TYPES_WLR_TABLET_V2_H */
|
||||
|
|
|
@ -763,7 +763,7 @@ static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) {
|
|||
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,
|
||||
wlr_tablet_v2_tablet_pad_notify_ring(pad->tablet_v2_pad,
|
||||
event->ring, event->position,
|
||||
event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER,
|
||||
event->time_msec);
|
||||
|
@ -774,7 +774,7 @@ static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) {
|
|||
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,
|
||||
wlr_tablet_v2_tablet_pad_notify_strip(pad->tablet_v2_pad,
|
||||
event->strip, event->position,
|
||||
event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER,
|
||||
event->time_msec);
|
||||
|
@ -785,10 +785,10 @@ static void handle_tablet_pad_button(struct wl_listener *listener, void *data) {
|
|||
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,
|
||||
wlr_tablet_v2_tablet_pad_notify_mode(pad->tablet_v2_pad,
|
||||
event->group, event->mode, event->time_msec);
|
||||
|
||||
wlr_send_tablet_v2_tablet_pad_button(pad->tablet_v2_pad,
|
||||
wlr_tablet_v2_tablet_pad_notify_button(pad->tablet_v2_pad,
|
||||
event->button, event->time_msec,
|
||||
(enum zwp_tablet_pad_v2_button_state)event->state);
|
||||
}
|
||||
|
@ -1173,7 +1173,7 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
|
|||
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);
|
||||
wlr_tablet_v2_tablet_pad_notify_enter(pad->tablet_v2_pad, pad->tablet->tablet_v2, view->wlr_surface);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <wlr/types/wlr_tablet_v2.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
static struct wlr_tablet_pad_v2_grab_interface default_pad_interface;
|
||||
|
||||
struct tablet_pad_auxiliary_user_data {
|
||||
struct wlr_tablet_pad_client_v2 *pad;
|
||||
size_t index;
|
||||
|
@ -366,6 +368,9 @@ struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create(
|
|||
if (!pad) {
|
||||
return NULL;
|
||||
}
|
||||
pad->default_grab.interface = &default_pad_interface;
|
||||
pad->default_grab.pad = pad;
|
||||
pad->grab = &pad->default_grab;
|
||||
|
||||
pad->group_count = wl_list_length(&wlr_pad->groups);
|
||||
pad->groups = calloc(pad->group_count, sizeof(int));
|
||||
|
@ -564,3 +569,128 @@ bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet,
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_enter(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
struct wlr_tablet_v2_tablet *tablet,
|
||||
struct wlr_surface *surface) {
|
||||
if (pad->grab && pad->grab->interface->enter) {
|
||||
return pad->grab->interface->enter(pad->grab, tablet, surface);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wlr_tablet_v2_tablet_pad_notify_button(
|
||||
struct wlr_tablet_v2_tablet_pad *pad, size_t button,
|
||||
uint32_t time, enum zwp_tablet_pad_v2_button_state state) {
|
||||
if (pad->grab && pad->grab->interface->button) {
|
||||
pad->grab->interface->button(pad->grab, button, time, state);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_tablet_v2_tablet_pad_notify_strip(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
uint32_t strip, double position, bool finger, uint32_t time) {
|
||||
if (pad->grab && pad->grab->interface->strip) {
|
||||
pad->grab->interface->strip(pad->grab, strip, position, finger, time);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_tablet_v2_tablet_pad_notify_ring(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
uint32_t ring, double position, bool finger, uint32_t time) {
|
||||
if (pad->grab && pad->grab->interface->ring) {
|
||||
pad->grab->interface->ring(pad->grab, ring, position, finger, time);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_leave(
|
||||
struct wlr_tablet_v2_tablet_pad *pad, struct wlr_surface *surface) {
|
||||
if (pad->grab && pad->grab->interface->leave) {
|
||||
return pad->grab->interface->leave(pad->grab, surface);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t wlr_tablet_v2_tablet_pad_notify_mode(
|
||||
struct wlr_tablet_v2_tablet_pad *pad,
|
||||
size_t group, uint32_t mode, uint32_t time) {
|
||||
if (pad->grab && pad->grab->interface->mode) {
|
||||
return pad->grab->interface->mode(pad->grab, group, mode, time);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wlr_tablet_v2_start_grab(struct wlr_tablet_v2_tablet_pad *pad,
|
||||
struct wlr_tablet_pad_v2_grab *grab) {
|
||||
if (grab != &pad->default_grab) {
|
||||
struct wlr_tablet_pad_v2_grab *prev = pad->grab;
|
||||
grab->pad = pad;
|
||||
pad->grab = grab;
|
||||
if (prev) {
|
||||
if (prev->interface->cancel) {
|
||||
prev->interface->cancel(prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_tablet_v2_end_grab(struct wlr_tablet_v2_tablet_pad *pad) {
|
||||
struct wlr_tablet_pad_v2_grab *grab = pad->grab;
|
||||
if (grab && grab != &pad->default_grab) {
|
||||
pad->grab = &pad->default_grab;
|
||||
if (grab->interface->cancel) {
|
||||
grab->interface->cancel(grab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t default_pad_enter(
|
||||
struct wlr_tablet_pad_v2_grab *grab,
|
||||
struct wlr_tablet_v2_tablet *tablet,
|
||||
struct wlr_surface *surface) {
|
||||
return wlr_send_tablet_v2_tablet_pad_enter(grab->pad, tablet, surface);
|
||||
}
|
||||
|
||||
static void default_pad_button(struct wlr_tablet_pad_v2_grab *grab,size_t button,
|
||||
uint32_t time, enum zwp_tablet_pad_v2_button_state state) {
|
||||
wlr_send_tablet_v2_tablet_pad_button(grab->pad, button, time, state);
|
||||
}
|
||||
|
||||
static void default_pad_strip(struct wlr_tablet_pad_v2_grab *grab,
|
||||
uint32_t strip, double position, bool finger, uint32_t time) {
|
||||
wlr_send_tablet_v2_tablet_pad_strip(grab->pad, strip, position, finger, time);
|
||||
}
|
||||
|
||||
static void default_pad_ring(struct wlr_tablet_pad_v2_grab *grab,
|
||||
uint32_t ring, double position, bool finger, uint32_t time) {
|
||||
wlr_send_tablet_v2_tablet_pad_ring(grab->pad, ring, position, finger, time);
|
||||
}
|
||||
|
||||
static uint32_t default_pad_leave(struct wlr_tablet_pad_v2_grab *grab,
|
||||
struct wlr_surface *surface) {
|
||||
return wlr_send_tablet_v2_tablet_pad_leave(grab->pad, surface);
|
||||
}
|
||||
|
||||
static uint32_t default_pad_mode(struct wlr_tablet_pad_v2_grab *grab,
|
||||
size_t group, uint32_t mode, uint32_t time) {
|
||||
return wlr_send_tablet_v2_tablet_pad_mode(grab->pad, group, mode, time);
|
||||
}
|
||||
|
||||
static void default_pad_cancel(struct wlr_tablet_pad_v2_grab *grab) {
|
||||
// Do nothing, the default cancel can be ignored.
|
||||
}
|
||||
|
||||
static struct wlr_tablet_pad_v2_grab_interface default_pad_interface = {
|
||||
.enter = default_pad_enter,
|
||||
.button = default_pad_button,
|
||||
.strip = default_pad_strip,
|
||||
.ring = default_pad_ring,
|
||||
.leave = default_pad_leave,
|
||||
.mode = default_pad_mode,
|
||||
.cancel = default_pad_cancel,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue