diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
| commit | 537b2d768b31deb0f95c5122e0d562e4406ae9a0 (patch) | |
| tree | cc3e85cb2990672c11b4e35c6dbcfaac733d09f5 /examples/notepad.c | |
| parent | 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (diff) | |
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/yasl.h>: 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 <noreply@anthropic.com>
Diffstat (limited to 'examples/notepad.c')
| -rw-r--r-- | examples/notepad.c | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/examples/notepad.c b/examples/notepad.c index 6fb90e9..ea74a27 100644 --- a/examples/notepad.c +++ b/examples/notepad.c @@ -990,7 +990,7 @@ static void prompt_execute(struct editor *ed) } /* YASL App callbacks */ -static int on_init(void *ud, struct yasl_display *d) +static enum yasl_app_result on_init(void *ud, struct yasl_display *d) { struct editor *ed = ud; ed->display = d; @@ -1021,7 +1021,7 @@ static int on_init(void *ud, struct yasl_display *d) return YASL_APP_CONTINUE; } -static int on_event(void *ud, const struct yasl_event *ev) +static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev) { struct editor *ed = ud; @@ -1029,28 +1029,28 @@ static int on_event(void *ud, const struct yasl_event *ev) case YASL_EVENT_TEXT: if (ed->prompt != PROMPT_NONE) { for (size_t i = 0; i < ev->text.len && ed->prompt_len < (int)sizeof(ed->prompt_buf) - 1; i++) { - if (ev->text.text[i] >= 32 && ev->text.text[i] <= 126) { - ed->prompt_buf[ed->prompt_len++] = ev->text.text[i]; + if (ev->text.data[i] >= 32 && ev->text.data[i] <= 126) { + ed->prompt_buf[ed->prompt_len++] = ev->text.data[i]; ed->prompt_buf[ed->prompt_len] = '\0'; } } } else { - insert_text(ed, ev->text.text, ev->text.len); + insert_text(ed, ev->text.data, ev->text.len); } yasl_surface_request_frame(ed->surface); break; case YASL_EVENT_PASTE: - if (ev->paste.text && ev->paste.len > 0) { - insert_text(ed, ev->paste.text, ev->paste.len); + if (ev->text.data && ev->text.len > 0) { + insert_text(ed, ev->text.data, ev->text.len); yasl_surface_request_frame(ed->surface); } break; - case YASL_EVENT_DROP_FILES: - if (ev->drop_files.files && ev->drop_files.len > 0) { + case YASL_EVENT_DROP: + if (ev->text.data && ev->text.len > 0) { char path[512]; - decode_uri_path(ev->drop_files.files, path, sizeof(path)); + decode_uri_path(ev->text.data, path, sizeof(path)); if (path[0]) { editor_open_file(ed, path); yasl_surface_request_frame(ed->surface); @@ -1287,34 +1287,34 @@ static int on_event(void *ud, const struct yasl_event *ev) } break; - case YASL_EVENT_MOUSE_BUTTON: { - struct yasl_geometry geom = yasl_surface_geometry(ed->surface); - int scale = (geom.scale_120 >= 240 ? 2 : 1) + ed->zoom_offset; - if (scale < 1) scale = 1; - int char_w = 8 * scale; - int line_h = 16 * scale; - int gutter_w = 48 * scale; - int header_h = 24 * scale; - - int row = (ev->mouse_button.pos.y - header_h) / line_h + ed->scroll_y; - int col = (ev->mouse_button.pos.x - gutter_w) / char_w + (ed->word_wrap ? 0 : ed->scroll_x); - if (row < 0) row = 0; - if (row >= ed->line_count) row = ed->line_count - 1; - int len = (int)strlen(ed->lines[row]); - if (col < 0) col = 0; - if (col > len) col = len; - - if (ev->mouse_button.pressed && ev->mouse_button.button == 0) { + case YASL_EVENT_POINTER_DOWN: { + if (ev->pointer.button == YASL_BUTTON_PRIMARY) { + struct yasl_geometry geom = yasl_surface_geometry(ed->surface); + int scale = (geom.scale_120 >= 240 ? 2 : 1) + ed->zoom_offset; + if (scale < 1) scale = 1; + int char_w = 8 * scale; + int line_h = 16 * scale; + int gutter_w = 48 * scale; + int header_h = 24 * scale; + + int row = (ev->pointer.pos.y - header_h) / line_h + ed->scroll_y; + int col = (ev->pointer.pos.x - gutter_w) / char_w + (ed->word_wrap ? 0 : ed->scroll_x); + if (row < 0) row = 0; + if (row >= ed->line_count) row = ed->line_count - 1; + int len = (int)strlen(ed->lines[row]); + if (col < 0) col = 0; + if (col > len) col = len; + uint64_t now = yasl_loop_now_ns(); if (now - ed->last_click_time < 350000000ull && - abs(ev->mouse_button.pos.x - ed->last_click_pos.x) < 8 && - abs(ev->mouse_button.pos.y - ed->last_click_pos.y) < 8) { + abs(ev->pointer.pos.x - ed->last_click_pos.x) < 8 && + abs(ev->pointer.pos.y - ed->last_click_pos.y) < 8) { ed->click_count++; } else { ed->click_count = 1; } ed->last_click_time = now; - ed->last_click_pos = ev->mouse_button.pos; + ed->last_click_pos = ev->pointer.pos; if (ed->click_count == 2) { /* Double click: select word */ @@ -1340,13 +1340,17 @@ static int on_event(void *ud, const struct yasl_event *ev) } ed->caret_visible = true; yasl_surface_request_frame(ed->surface); - } else if (!ev->mouse_button.pressed && ev->mouse_button.button == 0) { - ed->mouse_dragging = false; } break; } - case YASL_EVENT_MOUSE_MOTION: + case YASL_EVENT_POINTER_UP: + if (ev->pointer.button == YASL_BUTTON_PRIMARY) { + ed->mouse_dragging = false; + } + break; + + case YASL_EVENT_POINTER_MOTION: if (ed->mouse_dragging) { struct yasl_geometry geom = yasl_surface_geometry(ed->surface); int scale = (geom.scale_120 >= 240 ? 2 : 1) + ed->zoom_offset; @@ -1356,8 +1360,8 @@ static int on_event(void *ud, const struct yasl_event *ev) int gutter_w = 48 * scale; int header_h = 24 * scale; - int row = (ev->mouse_motion.pos.y - header_h) / line_h + ed->scroll_y; - int col = (ev->mouse_motion.pos.x - gutter_w) / char_w + (ed->word_wrap ? 0 : ed->scroll_x); + int row = (ev->pointer.pos.y - header_h) / line_h + ed->scroll_y; + int col = (ev->pointer.pos.x - gutter_w) / char_w + (ed->word_wrap ? 0 : ed->scroll_x); if (row < 0) row = 0; if (row >= ed->line_count) row = ed->line_count - 1; int len = (int)strlen(ed->lines[row]); @@ -1371,18 +1375,18 @@ static int on_event(void *ud, const struct yasl_event *ev) } break; - case YASL_EVENT_MOUSE_SCROLL: - if (ev->mouse_scroll.mods & (YASL_MOD_CTRL | YASL_MOD_SUPER)) { + case YASL_EVENT_POINTER_SCROLL: + if (ev->pointer.mods & (YASL_MOD_CTRL | YASL_MOD_SUPER)) { /* Ctrl + Wheel = Zoom */ - if (ev->mouse_scroll.scroll.y > 0 && ed->zoom_offset < 2) ed->zoom_offset++; - else if (ev->mouse_scroll.scroll.y < 0 && ed->zoom_offset > -1) ed->zoom_offset--; - } else if (ev->mouse_scroll.mods & YASL_MOD_SHIFT) { + if (ev->pointer.scroll.y > 0 && ed->zoom_offset < 2) ed->zoom_offset++; + else if (ev->pointer.scroll.y < 0 && ed->zoom_offset > -1) ed->zoom_offset--; + } else if (ev->pointer.mods & YASL_MOD_SHIFT) { /* Shift + Wheel = Horizontal scroll */ - ed->scroll_x -= (int)(ev->mouse_scroll.scroll.y * 3.0); + ed->scroll_x -= (int)(ev->pointer.scroll.y * 3.0); if (ed->scroll_x < 0) ed->scroll_x = 0; } else { /* Normal vertical scroll */ - ed->scroll_y -= (int)(ev->mouse_scroll.scroll.y * 3.0); + ed->scroll_y -= (int)(ev->pointer.scroll.y * 3.0); if (ed->scroll_y < 0) ed->scroll_y = 0; if (ed->scroll_y >= ed->line_count) ed->scroll_y = ed->line_count - 1; } @@ -1390,7 +1394,7 @@ static int on_event(void *ud, const struct yasl_event *ev) break; case YASL_EVENT_USER: - if (ev->user.type == MSG_STATS_READY && ev->user.payload) { + if (ev->user.code == MSG_STATS_READY && ev->user.payload) { struct doc_stats *s = (struct doc_stats *)ev->user.payload; ed->stats = *s; free(s); @@ -1398,7 +1402,7 @@ static int on_event(void *ud, const struct yasl_event *ev) } break; - case YASL_EVENT_WINDOW_CLOSE_REQUEST: + case YASL_EVENT_WINDOW_CLOSE: return YASL_APP_QUIT; default: |
