Filter events by window ID

This commit is contained in:
Abdelrahman Said 2024-01-15 20:18:41 +00:00
parent 10ff46cfe4
commit 81fbff96b8

View File

@ -26,7 +26,8 @@ struct compositor {
bool move_node;
};
void add_node(compositor_t *comp, const char *path, i32 x, i32 y);
void add_node(compositor_t *comp, node_type_t type, node_data_t data, i32 x,
i32 y);
i32 run_main_loop(void) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
@ -57,16 +58,19 @@ i32 run_main_loop(void) {
comp.running = false;
break;
case SDL_MOUSEBUTTONDOWN:
if (comp.event.button.windowID == main_window->id) {
if (comp.node_hovered != -1) {
comp.move_node = true;
}
break;
}
case SDL_MOUSEBUTTONUP:
comp.move_node = false;
break;
case SDL_MOUSEMOTION:
if (comp.event.motion.windowID == main_window->id) {
comp.mouse_x = comp.event.motion.x;
comp.mouse_y = comp.event.motion.y;
@ -92,11 +96,17 @@ i32 run_main_loop(void) {
}
break;
}
case SDL_DROPFILE:
add_node(&comp, comp.event.drop.file, comp.mouse_x, comp.mouse_y);
if (comp.event.drop.windowID == main_window->id) {
node_data_t data = (node_data_t){.path = comp.event.drop.file};
add_node(&comp, NODE_TYPE_IO, data, comp.mouse_x, comp.mouse_y);
break;
}
}
}
clear_window(main_window, bg_colour);
@ -113,7 +123,8 @@ i32 run_main_loop(void) {
return EXIT_SUCCESS;
}
void add_node(compositor_t *comp, const char *path, i32 x, i32 y) {
void add_node(compositor_t *comp, node_type_t type, node_data_t data, i32 x,
i32 y) {
if (comp->count + 1 >= MAX_NODES) {
return;
}
@ -126,6 +137,7 @@ void add_node(compositor_t *comp, const char *path, i32 x, i32 y) {
.w = NODE_WIDTH,
.h = NODE_HEIGHT,
},
.path = path,
.type = type,
.data.path = data.path,
};
}