From 537b2d768b31deb0f95c5122e0d562e4406ae9a0 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 15:41:39 +0300 Subject: Unify core and runner events into struct yasl_event The core input queue and the yasl_run() runner each had their own event type, and the runner translated one into the other. Both now share struct yasl_event in : yasl_surface_poll_event() returns the same events the app event callback receives, so the runner forwards them unchanged. Pointer input becomes POINTER_DOWN/UP/MOTION/SCROLL/LEAVE with a named yasl_pointer_button and a motion delta computed in the input queue. TEXT, PASTE and DROP share one text payload, scale changes fold into WINDOW_RESIZE, and every event carries a monotonic time_ns. yasl_surface_set_mouse_mode() is replaced by yasl_surface_set_pointer_mode(); no backend implements relative mode yet. The export check now only counts YASL_API declarations, so function pointer fields returning enum yasl_app_result are not mistaken for exports. Co-Authored-By: Claude Opus 5.5 --- src/platform/wayland/api.h | 2 +- src/platform/wayland/backend.c | 6 +- src/platform/wayland/ime.c | 6 +- src/platform/wayland/keyboard.c | 16 ++--- src/platform/wayland/pointer.c | 154 ++++++++++++++-------------------------- 5 files changed, 68 insertions(+), 116 deletions(-) (limited to 'src/platform/wayland') diff --git a/src/platform/wayland/api.h b/src/platform/wayland/api.h index bbd20df..aabc182 100644 --- a/src/platform/wayland/api.h +++ b/src/platform/wayland/api.h @@ -25,7 +25,7 @@ void wayland_surface_set_callbacks(struct wayland_surface *s, const struct yasl_ void wayland_surface_set_title(struct wayland_surface *s, const char *title); void wayland_surface_schedule_redraw(struct wayland_surface *s); bool wayland_surface_present(struct wayland_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); -bool wayland_surface_input_poll(struct wayland_surface *s, struct yasl_input_event *ev); +bool wayland_surface_poll_event(struct wayland_surface *s, struct yasl_event *ev); struct yasl_geometry wayland_surface_geometry(const struct wayland_surface *s); struct yasl_timing wayland_surface_timing(const struct wayland_surface *s); void wayland_surface_set_cursor(struct wayland_surface *s, enum yasl_cursor cursor); diff --git a/src/platform/wayland/backend.c b/src/platform/wayland/backend.c index cc96934..1d83ec6 100644 --- a/src/platform/wayland/backend.c +++ b/src/platform/wayland/backend.c @@ -101,9 +101,9 @@ static bool impl_surface_present(struct yasl_surface *s, const struct yasl_frame return wayland_surface_present((struct wayland_surface *)s, fb, damage); } -static bool impl_surface_input_poll(struct yasl_surface *s, struct yasl_input_event *ev) +static bool impl_surface_poll_event(struct yasl_surface *s, struct yasl_event *ev) { - return wayland_surface_input_poll((struct wayland_surface *)s, ev); + return wayland_surface_poll_event((struct wayland_surface *)s, ev); } static struct yasl_geometry impl_surface_geometry(const struct yasl_surface *s) @@ -205,7 +205,7 @@ const struct yasl_backend_ops yasl_wayland_backend = { .surface_set_title = impl_surface_set_title, .surface_schedule_redraw = impl_surface_schedule_redraw, .surface_present = impl_surface_present, - .surface_input_poll = impl_surface_input_poll, + .surface_poll_event = impl_surface_poll_event, .surface_geometry = impl_surface_geometry, .surface_timing = impl_surface_timing, .surface_frame_time_ns = impl_surface_frame_time_ns, diff --git a/src/platform/wayland/ime.c b/src/platform/wayland/ime.c index 440b234..f326fa8 100644 --- a/src/platform/wayland/ime.c +++ b/src/platform/wayland/ime.c @@ -129,10 +129,10 @@ static void text_input_done(void *data, struct zwp_text_input_v3 *text_input, struct wayland_surface *w = ((struct seat *)data)->ime_focus; if (!w) return; if (w->ime_commit) { - struct yasl_input_event ev = { - .kind = YASL_INPUT_TEXT, + struct yasl_event ev = { + .type = YASL_EVENT_TEXT, .surface = &w->base, - .text = { .text = w->ime_commit, .len = strlen(w->ime_commit) }, + .text = { .data = w->ime_commit, .len = strlen(w->ime_commit) }, }; input_queue_push(&w->input, &ev); free(w->ime_commit); diff --git a/src/platform/wayland/keyboard.c b/src/platform/wayland/keyboard.c index ebd0fc7..038ba78 100644 --- a/src/platform/wayland/keyboard.c +++ b/src/platform/wayland/keyboard.c @@ -133,8 +133,8 @@ bool conn_keyboard_on(const struct wayland_display *c, const struct wayland_surf static void push_focus(struct wayland_surface *w, bool focused) { - struct yasl_input_event ev = { - .kind = YASL_INPUT_FOCUS, + struct yasl_event ev = { + .type = YASL_EVENT_FOCUS, .surface = &w->base, .focus = { .focused = focused }, }; @@ -278,13 +278,13 @@ static void keyboard_text(struct seat *s, struct wayland_surface *w, uint32_t ke else xkb_state_key_get_utf8(s->xkb_state, code, text, (size_t)len + 1); /* Editing commands belong to key events, not text insertion. */ if ((unsigned char)text[0] >= 0x20 && text[0] != 0x7f) { - struct yasl_input_event ev = {.kind = YASL_INPUT_TEXT, - .surface = &w->base, .text = {text, (size_t)len}}; + struct yasl_event ev = {.type = YASL_EVENT_TEXT, + .surface = &w->base, .text = {.data = text, .len = (size_t)len}}; input_queue_push(&w->input, &ev); } if (text != local) free(text); } else { - struct yasl_input_event ev = {.kind = YASL_INPUT_RESET, .surface = &w->base}; + struct yasl_event ev = {.type = YASL_EVENT_INPUT_RESET, .surface = &w->base}; input_queue_push(&w->input, &ev); } } @@ -297,8 +297,8 @@ static bool keyboard_dispatch_key(struct seat *s, struct wayland_surface *w, uin if (!s->xkb_state || !w->cbs) return false; struct yasl_key_event k = xkb_key_event(s, key, action); - struct yasl_input_event ev = { - .kind = YASL_INPUT_KEY, + struct yasl_event ev = { + .type = YASL_EVENT_KEY, .surface = &w->base, .key = k, }; @@ -448,7 +448,7 @@ void wayland_display_paste(struct wayland_display *c, enum yasl_selection sel, s clipboard_paste(s->clipboard, target->surface); } -bool wayland_surface_input_poll(struct wayland_surface *w, struct yasl_input_event *ev) +bool wayland_surface_poll_event(struct wayland_surface *w, struct yasl_event *ev) { return w && ev && input_queue_pop(&w->input, ev); } 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 }, }; -- cgit v1.2.3