From 35ee3fec212a67e05988bfe0f9ec9b17156a0905 Mon Sep 17 00:00:00 2001 From: boreddevnl Date: Thu, 23 Apr 2026 00:01:12 +0200 Subject: [PATCH] wm: add mouse event callbacks to Window --- src/wm/wm.c | 23 +++++++++++++---------- src/wm/wm.h | 3 +++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/wm/wm.c b/src/wm/wm.c index a29419a..e6613ad 100644 --- a/src/wm/wm.c +++ b/src/wm/wm.c @@ -3573,10 +3573,12 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) { } } } - if (topmost && topmost->data) { + if (topmost) { active_mouse_capture_win = topmost; - if (my >= topmost->y + 20) - syscall_send_mouse_down_event(topmost, mx - topmost->x, my - topmost->y - 20); + int rel_x = mx - topmost->x; + int rel_y = my - topmost->y - 20; + if (rel_y >= 0 && topmost->handle_mouse_down) + topmost->handle_mouse_down(topmost, rel_x, rel_y); } else { active_mouse_capture_win = NULL; } @@ -3598,10 +3600,11 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) { } } - if (target && target->data) { + if (target) { + int rel_x = mx - target->x; int rel_y = my - target->y - 20; - // Provide coordinates clamped if escaping bounds slightly on UP? Usually raw is fine. - syscall_send_mouse_up_event(target, mx - target->x, rel_y); + if (target->handle_mouse_up) + target->handle_mouse_up(target, rel_x, rel_y); } active_mouse_capture_win = NULL; } @@ -3622,9 +3625,11 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) { } } - if (target && target->data) { + if (target) { + int rel_x = mx - target->x; int rel_y = my - target->y - 20; - syscall_send_mouse_move_event(target, mx - target->x, rel_y, buttons); + if (target->handle_mouse_move) + target->handle_mouse_move(target, rel_x, rel_y, buttons); } } @@ -3636,8 +3641,6 @@ static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) { wm_mark_dirty(prev_mx, prev_my, CURSOR_W, CURSOR_H); wm_mark_dirty(mx, my, CURSOR_W, CURSOR_H); } - - prev_left = left; } void wm_handle_mouse(int dx, int dy, uint8_t buttons, int dz) { diff --git a/src/wm/wm.h b/src/wm/wm.h index c4a2398..1b8ada3 100644 --- a/src/wm/wm.h +++ b/src/wm/wm.h @@ -63,6 +63,9 @@ struct Window { void (*handle_key)(Window *win, char c, bool pressed); void (*handle_click)(Window *win, int x, int y); void (*handle_right_click)(Window *win, int x, int y); + void (*handle_mouse_down)(Window *win, int x, int y); + void (*handle_mouse_up)(Window *win, int x, int y); + void (*handle_mouse_move)(Window *win, int x, int y, uint8_t buttons); void (*handle_close)(Window *win); void (*handle_resize)(Window *win, int w, int h); bool resizable;