From 247a74810374894a74ca63af4eb86d9614cf6c74 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Tue, 14 May 2024 10:54:47 +0200 Subject: Implement multiple windows --- src/connect.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/connect.c') diff --git a/src/connect.c b/src/connect.c index 79fd2b1..aaced77 100644 --- a/src/connect.c +++ b/src/connect.c @@ -192,7 +192,13 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer xcb_expose_event_t *expose = (xcb_expose_event_t *)xsource->event; log_debug("Processing event 'Expose' [type=%d]", XCB_EXPOSE); - state_request_redraw(xsource->con->state, true); + for (GList *it = xsource->con->states; it != NULL; it = it->next) { + State *state = it->data; + if (state->win->window == expose->window) { + state_request_redraw(state, true); + break; + } + } break; } @@ -214,7 +220,13 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer case XCB_BUTTON_INDEX_2: // left click case XCB_BUTTON_INDEX_1: // right click case XCB_BUTTON_INDEX_3: // middle click - button_action(xsource->con->state, "button release", button->event_x, button->event_y); + for (GList *it = xsource->con->states; it != NULL; it = it->next) { + State *state = it->data; + if (state->win->window == button->event) { + button_action(state, "button release", button->event_x, button->event_y); + break; + } + } break; default: @@ -225,12 +237,12 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer } // TODO: Implement correctly hovering - case XCB_MOTION_NOTIFY: { - xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xsource->event; - log_debug("Processing event 'MotionNotify' [type=%d]", XCB_MOTION_NOTIFY); - button_action(xsource->con->state, "motion notify", motion->event_x, motion->event_y); - break; - } + //case XCB_MOTION_NOTIFY: { + // xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xsource->event; + // log_debug("Processing event 'MotionNotify' [type=%d]", XCB_MOTION_NOTIFY); + // button_action(xsource->con->state, "motion notify", motion->event_x, motion->event_y); + // break; + //} case XCB_PROPERTY_NOTIFY: { xcb_property_notify_event_t *property = (xcb_property_notify_event_t *)xsource->event; @@ -239,7 +251,8 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer if (property->atom == XCB_ATOM_RESOURCE_MANAGER) { update_xrm(xsource->con); update_scale(xsource->con); - state_request_redraw(xsource->con->state, true); + for (GList *it = xsource->con->states; it != NULL; it = it->next) + state_request_redraw(it->data, true); } break; } @@ -371,11 +384,11 @@ void connect_attach_source(Connection *con) log_debug("Xcb event loop attached"); } -void connect_attach_state(Connection *con, State *state) +void connect_add_state(Connection *con, State *state) { g_assert_nonnull(state); - con->state = state; - log_debug("Attached state to event loop"); + con->states = g_list_append(con->states, state); + log_debug("Add state to event loop [state=%p, state=\"%s\"]", state, state->label); } void connect_destroy(Connection *con) -- cgit v1.2.3