summaryrefslogtreecommitdiff
path: root/src/platform/wayland/pointer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/wayland/pointer.c')
-rw-r--r--src/platform/wayland/pointer.c154
1 files changed, 53 insertions, 101 deletions
diff --git a/src/platform/wayland/pointer.c b/src/platform/wayland/pointer.c
index 4652849..83f6e2f 100644
--- a/src/platform/wayland/pointer.c
+++ b/src/platform/wayland/pointer.c
@@ -34,77 +34,30 @@ static struct yasl_vector2i device_from_fixed(const struct wayland_surface *w,
};
}
-static inline int motion_button(uint64_t buttons)
-{
- static const uint8_t motion_btn_lut[256] = {
- [0] = 3,
- [1] = 0, [2] = 1, [3] = 0, [4] = 2, [5] = 0, [6] = 1, [7] = 0,
- [8] = 3, [9] = 0, [10] = 1, [11] = 0, [12] = 2, [13] = 0, [14] = 1, [15] = 0,
- [16] = 4, [17] = 0, [18] = 1, [19] = 0, [20] = 2, [21] = 0, [22] = 1, [23] = 0,
- [24] = 3, [25] = 0, [26] = 1, [27] = 0, [28] = 2, [29] = 0, [30] = 1, [31] = 0,
- [32] = 5, [33] = 0, [34] = 1, [35] = 0, [36] = 2, [37] = 0, [38] = 1, [39] = 0,
- [40] = 3, [41] = 0, [42] = 1, [43] = 0, [44] = 2, [45] = 0, [46] = 1, [47] = 0,
- [48] = 4, [49] = 0, [50] = 1, [51] = 0, [52] = 2, [53] = 0, [54] = 1, [55] = 0,
- [56] = 3, [57] = 0, [58] = 1, [59] = 0, [60] = 2, [61] = 0, [62] = 1, [63] = 0,
- [64] = 6, [65] = 0, [66] = 1, [67] = 0, [68] = 2, [69] = 0, [70] = 1, [71] = 0,
- [72] = 3, [73] = 0, [74] = 1, [75] = 0, [76] = 2, [77] = 0, [78] = 1, [79] = 0,
- [80] = 4, [81] = 0, [82] = 1, [83] = 0, [84] = 2, [85] = 0, [86] = 1, [87] = 0,
- [88] = 3, [89] = 0, [90] = 1, [91] = 0, [92] = 2, [93] = 0, [94] = 1, [95] = 0,
- [96] = 5, [97] = 0, [98] = 1, [99] = 0, [100] = 2, [101] = 0, [102] = 1, [103] = 0,
- [104] = 3, [105] = 0, [106] = 1, [107] = 0, [108] = 2, [109] = 0, [110] = 1, [111] = 0,
- [112] = 4, [113] = 0, [114] = 1, [115] = 0, [116] = 2, [117] = 0, [118] = 1, [119] = 0,
- [120] = 3, [121] = 0, [122] = 1, [123] = 0, [124] = 2, [125] = 0, [126] = 1, [127] = 0,
- [128] = 7, [129] = 0, [130] = 1, [131] = 0, [132] = 2, [133] = 0, [134] = 1, [135] = 0,
- [136] = 3, [137] = 0, [138] = 1, [139] = 0, [140] = 2, [141] = 0, [142] = 1, [143] = 0,
- [144] = 4, [145] = 0, [146] = 1, [147] = 0, [148] = 2, [149] = 0, [150] = 1, [151] = 0,
- [152] = 3, [153] = 0, [154] = 1, [155] = 0, [156] = 2, [157] = 0, [158] = 1, [159] = 0,
- [160] = 5, [161] = 0, [162] = 1, [163] = 0, [164] = 2, [165] = 0, [166] = 1, [167] = 0,
- [168] = 3, [169] = 0, [170] = 1, [171] = 0, [172] = 2, [173] = 0, [174] = 1, [175] = 0,
- [176] = 4, [177] = 0, [178] = 1, [179] = 0, [180] = 2, [181] = 0, [182] = 1, [183] = 0,
- [184] = 3, [185] = 0, [186] = 1, [187] = 0, [188] = 2, [189] = 0, [190] = 1, [191] = 0,
- [192] = 6, [193] = 0, [194] = 1, [195] = 0, [196] = 2, [197] = 0, [198] = 1, [199] = 0,
- [200] = 3, [201] = 0, [202] = 1, [203] = 0, [204] = 2, [205] = 0, [206] = 1, [207] = 0,
- [208] = 4, [209] = 0, [210] = 1, [211] = 0, [212] = 2, [213] = 0, [214] = 1, [215] = 0,
- [216] = 3, [217] = 0, [218] = 1, [219] = 0, [220] = 2, [221] = 0, [222] = 1, [223] = 0,
- [224] = 5, [225] = 0, [226] = 1, [227] = 0, [228] = 2, [229] = 0, [230] = 1, [231] = 0,
- [232] = 3, [233] = 0, [234] = 1, [235] = 0, [236] = 2, [237] = 0, [238] = 1, [239] = 0,
- [240] = 4, [241] = 0, [242] = 1, [243] = 0, [244] = 2, [245] = 0, [246] = 1, [247] = 0,
- [248] = 3, [249] = 0, [250] = 1, [251] = 0, [252] = 2, [253] = 0, [254] = 1, [255] = 0,
- };
- return motion_btn_lut[(uint8_t)buttons];
-}
-
void seat_note_input(struct seat *s, uint32_t serial)
{
s->input_serial = serial;
s->conn->active_seat = s;
}
-static void push_mouse(struct seat *s, struct wayland_surface *w, struct yasl_mouse_event ev)
+static void push_pointer(struct seat *s, struct wayland_surface *w,
+ enum yasl_event_type type, struct yasl_pointer_event ev)
{
- ev.mods = (unsigned)seat_modifiers(s);
- struct yasl_input_event input_ev = {
- .kind = YASL_INPUT_MOUSE,
+ ev.mods = (uint32_t)seat_modifiers(s);
+ struct yasl_event input_ev = {
+ .type = type,
.surface = &w->base,
- .mouse = ev,
+ .pointer = ev,
};
input_queue_push(&surface_root(w)->input, &input_ev);
}
-static void report_mouse(struct seat *s, struct wayland_surface *w, struct yasl_vector2i pos,
- int button, enum yasl_pointer_kind kind)
-{
- push_mouse(s, w, (struct yasl_mouse_event){
- .pos = pos, .button = button, .kind = kind,
- });
-}
-
static void report_wheel(struct seat *s, struct wayland_surface *w,
struct yasl_vector2i pos, double x, double y)
{
if ((x == 0 && y == 0) || !isfinite(x) || !isfinite(y)) return;
- push_mouse(s, w, (struct yasl_mouse_event){
- .pos = pos, .kind = YASL_PTR_SCROLL, .scroll = {x, y},
+ push_pointer(s, w, YASL_EVENT_POINTER_SCROLL, (struct yasl_pointer_event){
+ .pos = pos, .scroll = {x, y},
});
}
@@ -238,7 +191,7 @@ void wayland_surface_set_cursor(struct wayland_surface *w, enum yasl_cursor shap
static void press_queue_flush(struct seat *s, struct press_queue *q,
struct wayland_surface *only, uint64_t *buttons,
- struct yasl_mouse_event like)
+ struct yasl_pointer_event like)
{
int kept = 0;
int count = q->n;
@@ -251,11 +204,11 @@ static void press_queue_flush(struct seat *s, struct press_queue *q,
if (!p.surface) continue;
uint64_t mask = 1ull << p.button;
*buttons = (*buttons & ~mask) | ((uint64_t)(!p.release) << p.button);
- struct yasl_mouse_event ev = like;
+ struct yasl_pointer_event ev = like;
ev.pos = p.pos;
- ev.button = p.button;
- ev.kind = (enum yasl_pointer_kind)p.release;
- push_mouse(s, p.surface, ev);
+ ev.button = (enum yasl_pointer_button)p.button;
+ enum yasl_event_type type = p.release ? YASL_EVENT_POINTER_UP : YASL_EVENT_POINTER_DOWN;
+ push_pointer(s, p.surface, type, ev);
}
q->head = 0;
q->n = kept;
@@ -308,7 +261,9 @@ static void flush_pending_motion(struct seat *s, struct wayland_surface *w)
{
if (!s->motion_pending) return;
s->motion_pending = false;
- report_mouse(s, w, s->pointer_pos, motion_button(s->pointer_buttons), YASL_PTR_MOTION);
+ push_pointer(s, w, YASL_EVENT_POINTER_MOTION, (struct yasl_pointer_event){
+ .pos = s->pointer_pos,
+ });
}
static void pointer_enter(void *data, struct wl_pointer *pointer,
@@ -459,9 +414,13 @@ static void pointer_frame(void *data, struct wl_pointer *pointer)
if (left) {
s->ptr_left = NULL;
if (s->ptr_left_motion)
- report_mouse(s, left, s->ptr_left_pos, motion_button(s->pointer_buttons), YASL_PTR_MOTION);
- press_queue_flush(s, &s->ptr_presses, left, &s->pointer_buttons, (struct yasl_mouse_event){0});
- report_mouse(s, left, s->ptr_left_pos, 3, YASL_PTR_LEAVE);
+ push_pointer(s, left, YASL_EVENT_POINTER_MOTION, (struct yasl_pointer_event){
+ .pos = s->ptr_left_pos,
+ });
+ press_queue_flush(s, &s->ptr_presses, left, &s->pointer_buttons, (struct yasl_pointer_event){0});
+ push_pointer(s, left, YASL_EVENT_POINTER_LEAVE, (struct yasl_pointer_event){
+ .pos = s->ptr_left_pos,
+ });
struct yasl_vector2i pos = s->pointer_pos;
bool motion = s->motion_pending;
uint32_t serial = s->pointer_focus ? s->pointer_serial : 0;
@@ -479,7 +438,7 @@ static void pointer_frame(void *data, struct wl_pointer *pointer)
}
flush_pending_motion(s, w);
- press_queue_flush(s, &s->ptr_presses, NULL, &s->pointer_buttons, (struct yasl_mouse_event){0});
+ press_queue_flush(s, &s->ptr_presses, NULL, &s->pointer_buttons, (struct yasl_pointer_event){0});
pointer_frame_scroll(s, w);
}
@@ -523,10 +482,10 @@ static struct yasl_vector2i touch_pos(const struct touch_point *p)
static void touch_report(struct seat *s, struct touch_point *p, int button,
- enum yasl_pointer_kind kind)
+ enum yasl_event_type type)
{
- push_mouse(s, p->surface, (struct yasl_mouse_event){
- .pos = touch_pos(p), .button = button, .kind = kind,
+ push_pointer(s, p->surface, type, (struct yasl_pointer_event){
+ .pos = touch_pos(p), .button = (enum yasl_pointer_button)button,
.device = YASL_PTR_DEV_TOUCH,
});
}
@@ -584,7 +543,7 @@ static void touch_frame(void *data, struct wl_touch *touch)
if (p->down && !s->touch_primary && !s->touch_scrolling) {
s->touch_primary = p;
s->touch_pressed = true;
- touch_report(s, p, 0, YASL_PTR_PRESS);
+ touch_report(s, p, 0, YASL_EVENT_POINTER_DOWN);
}
if (!p->up) {
active_n++;
@@ -597,7 +556,7 @@ static void touch_frame(void *data, struct wl_touch *touch)
struct touch_point *primary = s->touch_primary;
if (primary && !s->touch_scrolling && active_n >= 2) {
if (s->touch_pressed)
- touch_report(s, primary, 0, YASL_PTR_RELEASE);
+ touch_report(s, primary, 0, YASL_EVENT_POINTER_UP);
s->touch_pressed = false;
s->touch_scrolling = true;
s->touch_scroll_y = centroid_n ? centroid_sum / centroid_n : 0;
@@ -607,13 +566,14 @@ static void touch_frame(void *data, struct wl_touch *touch)
s->touch_scroll_y = y;
if (dy != 0.0) {
double lines = dy / SCROLL_PX_PER_LINE;
- push_mouse(s, primary->surface, (struct yasl_mouse_event){
- .pos = touch_pos(primary), .kind = YASL_PTR_SCROLL,
- .scroll = {0, -lines}, .device = YASL_PTR_DEV_TOUCH,
+ push_pointer(s, primary->surface, YASL_EVENT_POINTER_SCROLL, (struct yasl_pointer_event){
+ .pos = touch_pos(primary),
+ .scroll = {0, -lines},
+ .device = YASL_PTR_DEV_TOUCH,
});
}
} else if (primary && primary->moved && s->touch_pressed) {
- touch_report(s, primary, 0, YASL_PTR_MOTION);
+ touch_report(s, primary, 0, YASL_EVENT_POINTER_MOTION);
}
for (int i = 0; i < SEAT_TOUCH_POINTS; i++) {
struct touch_point *p = &s->touch_points[i];
@@ -622,7 +582,7 @@ static void touch_frame(void *data, struct wl_touch *touch)
active_n--;
if (p == s->touch_primary) {
if (s->touch_pressed)
- touch_report(s, p, 0, YASL_PTR_RELEASE);
+ touch_report(s, p, 0, YASL_EVENT_POINTER_UP);
s->touch_pressed = false;
s->touch_primary = NULL;
}
@@ -640,7 +600,7 @@ static void touch_cancel(void *data, struct wl_touch *touch)
(void)touch;
struct seat *s = data;
if (s->touch_primary && s->touch_pressed)
- touch_report(s, s->touch_primary, 0, YASL_PTR_RELEASE);
+ touch_report(s, s->touch_primary, 0, YASL_EVENT_POINTER_UP);
memset(s->touch_points, 0, sizeof(s->touch_points));
s->touch_primary = NULL;
s->touch_pressed = false;
@@ -658,9 +618,9 @@ static const struct wl_touch_listener touch_listener = {
.frame = touch_frame, .cancel = touch_cancel,
};
-static struct yasl_mouse_event tool_event(const struct seat *s)
+static struct yasl_pointer_event tool_event(const struct seat *s)
{
- return (struct yasl_mouse_event){
+ return (struct yasl_pointer_event){
.device = s->tool && s->tool->eraser ? YASL_PTR_DEV_ERASER : YASL_PTR_DEV_PEN,
.pen = s->pen,
};
@@ -697,11 +657,9 @@ static void tablet_tool_proximity_out(void *data, struct zwp_tablet_tool_v2 *too
if (w) {
press_queue_flush(s, &s->tool_presses, NULL, &s->tool_buttons, tool_event(s));
s->pen.pressure = 0;
- struct yasl_mouse_event ev = tool_event(s);
+ struct yasl_pointer_event ev = tool_event(s);
ev.pos = s->tool_pos;
- ev.button = 3;
- ev.kind = YASL_PTR_LEAVE;
- push_mouse(s, w, ev);
+ push_pointer(s, w, YASL_EVENT_POINTER_LEAVE, ev);
}
s->tool_presses.n = 0;
s->tablet_focus = NULL;
@@ -802,22 +760,19 @@ static void tool_frame(void *d, struct zwp_tablet_tool_v2 *t, uint32_t time)
s->tool_wheel = 0;
return;
}
- struct yasl_mouse_event like = tool_event(s);
+ struct yasl_pointer_event like = tool_event(s);
if (s->tool_motion) {
- struct yasl_mouse_event ev = like;
+ struct yasl_pointer_event ev = like;
ev.pos = s->tool_pos;
- ev.button = motion_button(s->tool_buttons);
- ev.kind = YASL_PTR_MOTION;
- push_mouse(s, w, ev);
+ push_pointer(s, w, YASL_EVENT_POINTER_MOTION, ev);
s->tool_motion = false;
}
press_queue_flush(s, &s->tool_presses, NULL, &s->tool_buttons, like);
if (s->tool_wheel) {
- struct yasl_mouse_event ev = like;
+ struct yasl_pointer_event ev = like;
ev.pos = s->tool_pos;
- ev.kind = YASL_PTR_SCROLL;
ev.scroll.y = s->tool_wheel;
- push_mouse(s, w, ev);
+ push_pointer(s, w, YASL_EVENT_POINTER_SCROLL, ev);
s->tool_wheel = 0;
}
}
@@ -985,17 +940,14 @@ static void clipboard_received(const char *text, size_t len, bool uri_list,
(struct wayland_surface *)wl_surface_get_user_data(on) : NULL;
if (uri_list) w = surface_root(w);
if (!w || w->closed) return;
- struct yasl_input_event ev = {
+ struct yasl_event ev = {
.surface = &w->base,
- .kind = uri_list ? YASL_INPUT_DROP_FILES : YASL_INPUT_PASTE,
+ .type = uri_list ? YASL_EVENT_DROP : YASL_EVENT_PASTE,
+ .text = {
+ .data = text,
+ .len = len,
+ },
};
- if (uri_list) {
- ev.drop_files.files = text;
- ev.drop_files.len = len;
- } else {
- ev.paste.text = text;
- ev.paste.len = len;
- }
input_queue_push(&w->input, &ev);
}
@@ -1214,8 +1166,8 @@ void seat_destroy(struct seat *s)
seat_drop_keyboard(s);
struct wayland_surface *left = s->focus_leaving;
if (left && !conn_keyboard_on(c, left, NULL)) {
- struct yasl_input_event ev = {
- .kind = YASL_INPUT_FOCUS,
+ struct yasl_event ev = {
+ .type = YASL_EVENT_FOCUS,
.surface = &left->base,
.focus = { .focused = false },
};