wm: add mouse event callbacks to Window

This commit is contained in:
boreddevnl 2026-04-23 00:01:12 +02:00
parent 85d1dc0991
commit 35ee3fec21
2 changed files with 16 additions and 10 deletions

View file

@ -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; active_mouse_capture_win = topmost;
if (my >= topmost->y + 20) int rel_x = mx - topmost->x;
syscall_send_mouse_down_event(topmost, mx - topmost->x, my - topmost->y - 20); 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 { } else {
active_mouse_capture_win = NULL; 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; int rel_y = my - target->y - 20;
// Provide coordinates clamped if escaping bounds slightly on UP? Usually raw is fine. if (target->handle_mouse_up)
syscall_send_mouse_up_event(target, mx - target->x, rel_y); target->handle_mouse_up(target, rel_x, rel_y);
} }
active_mouse_capture_win = NULL; 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; 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(prev_mx, prev_my, CURSOR_W, CURSOR_H);
wm_mark_dirty(mx, 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) { void wm_handle_mouse(int dx, int dy, uint8_t buttons, int dz) {

View file

@ -63,6 +63,9 @@ struct Window {
void (*handle_key)(Window *win, char c, bool pressed); void (*handle_key)(Window *win, char c, bool pressed);
void (*handle_click)(Window *win, int x, int y); void (*handle_click)(Window *win, int x, int y);
void (*handle_right_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_close)(Window *win);
void (*handle_resize)(Window *win, int w, int h); void (*handle_resize)(Window *win, int w, int h);
bool resizable; bool resizable;