diff -r 0b96fe6d6b5e -r 823c03733e42 src/context.c --- a/src/context.c Sun Aug 11 15:43:01 2024 +0200 +++ b/src/context.c Sun Aug 11 16:11:30 2024 +0200 @@ -118,13 +118,11 @@ } static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { - for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { - if (asc_context.windows[i].id == id) { - asc_vec2i dimensions = (asc_vec2i) {width, height}; - asc_context.windows[i].resized = true; - asc_context.windows[i].dimensions = dimensions; - return; - } + unsigned int i = asc_window_index(id); + if (i < ASC_MAX_WINDOWS) { + asc_vec2i dimensions = (asc_vec2i) {width, height}; + asc_context.windows[i].resized = true; + asc_context.windows[i].dimensions = dimensions; } } @@ -141,12 +139,19 @@ asc_set_flag(asc_context.flags, ASC_FLAG_QUIT); break; case SDL_WINDOWEVENT: { - if (event.window.event == SDL_WINDOWEVENT_RESIZED) + if (event.window.event == SDL_WINDOWEVENT_RESIZED) { asc_event_window_resized( event.window.windowID, event.window.data1, event.window.data2 ); + } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + unsigned int idx = asc_window_index(event.window.windowID); + asc_context.windows[idx].focused = true; + } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { + unsigned int idx = asc_window_index(event.window.windowID); + asc_context.windows[idx].focused = false; + } break; } case SDL_MOUSEMOTION: { @@ -156,6 +161,9 @@ // update absolute position asc_context.input.mouse_x = event.motion.x; asc_context.input.mouse_y = event.motion.y; + // update which window the mouse was seen in + asc_context.input.mouse_window = + asc_window_index(event.motion.windowID); break; } case SDL_KEYDOWN: