diff -r 24b0f47f619c -r 4df350dac84f src/context.c --- a/src/context.c Sun Jan 25 13:18:26 2026 +0100 +++ b/src/context.c Sun Jan 25 13:49:49 2026 +0100 @@ -34,6 +34,7 @@ #include #include +#include AscContext asc_context; @@ -119,13 +120,29 @@ } } +static AscWindow * asc_window_find(Uint32 sdl_id) { + for (unsigned i = 0 ; i < ASC_MAX_WINDOWS ; i++) { + if (asc_context.windows[i].id == sdl_id) { + return asc_context.windows + i; + } + } + return NULL; +} + static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { - unsigned int i = asc_window_index(id); - if (i < ASC_MAX_WINDOWS) { - asc_context.windows[i].resized = true; - asc_context.windows[i].dimensions.width = (unsigned) width; - asc_context.windows[i].dimensions.height = (unsigned) height; - } + AscWindow *window = asc_window_find(id); + assert(window != NULL); + window->resized = true; + window->rect.size.width = (unsigned) width; + window->rect.size.height = (unsigned) height; +} + +static void asc_event_window_moved(Uint32 id, Sint32 x, Sint32 y) { + AscWindow *window = asc_window_find(id); + assert(window != NULL); + window->moved = true; + window->rect.pos.x = x; + window->rect.pos.y = y; } bool asc_loop_next(void) { @@ -145,6 +162,14 @@ case SDL_EVENT_QUIT: asc_set_flag(asc_context.flags, ASC_FLAG_QUIT); break; + case SDL_EVENT_WINDOW_MOVED: { + asc_event_window_moved( + event.window.windowID, + event.window.data1, + event.window.data2 + ); + break; + } case SDL_EVENT_WINDOW_RESIZED: { asc_event_window_resized( event.window.windowID, @@ -154,13 +179,11 @@ break; } case SDL_EVENT_WINDOW_FOCUS_GAINED: { - unsigned int idx = asc_window_index(event.window.windowID); - asc_context.windows[idx].focused = true; + asc_window_find(event.window.windowID)->focused = true; break; } case SDL_EVENT_WINDOW_FOCUS_LOST: { - unsigned int idx = asc_window_index(event.window.windowID); - asc_context.windows[idx].focused = false; + asc_window_find(event.window.windowID)->focused = false; break; } case SDL_EVENT_MOUSE_MOTION: {