Only handle events from the active window

This commit is contained in:
Abdelrahman Said 2024-01-17 23:40:02 +00:00
parent 718e7eec21
commit aac10f24d1

View File

@ -19,6 +19,7 @@
typedef struct compositor compositor_t;
struct compositor {
window_t windows[MAX_WINDOWS];
u32 active_window;
SDL_Event event;
bool running;
u64 mouse_x;
@ -77,9 +78,8 @@ i32 run_main_loop(void) {
while (comp.running) {
while (SDL_PollEvent(&(comp.event))) {
for (u64 i = 0; i < MAX_WINDOWS; ++i) {
handle_ui_events(&(comp.windows[i]), &(comp.ctx), &(comp.event));
}
handle_ui_events(&(comp.windows[comp.active_window - 1]), &(comp.ctx),
&(comp.event));
switch (comp.event.type) {
case SDL_QUIT:
@ -98,6 +98,7 @@ i32 run_main_loop(void) {
window_t *window = &(comp.windows[i]);
if (id == window->id) {
comp.active_window = id;
wnd = window;
break;
}