aboutsummaryrefslogtreecommitdiff
path: root/connection.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-17 15:07:14 +0100
committerFederico Angelilli <code@fedang.net>2023-11-17 15:07:14 +0100
commitf8363e89257e8b0a4ff71accbd7b6be22935274f (patch)
tree62e6b17d11b174f6683bf090ed678dddd7a263d4 /connection.c
parent41729222431449a81535b28ad27ce2620cb5819b (diff)
Attach state to the event loop
Diffstat (limited to 'connection.c')
-rw-r--r--connection.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/connection.c b/connection.c
index 1ee29bc..d3eedda 100644
--- a/connection.c
+++ b/connection.c
@@ -8,6 +8,7 @@
#include "log.h"
#include "connection.h"
+#include "state.h"
static bool query_xrm(Connection *con, const char *res, char **value)
{
@@ -69,6 +70,20 @@ static gboolean source_check(GSource *source)
return xsource->event != NULL;
}
+static void redraw_window(Connection *con, xcb_window_t id)
+{
+ for (int i = 0; i < con->states->len; ++i) {
+ State *state = con->states->pdata[i];
+
+ // Redraw matching window
+ if (state->win->window == id) {
+ log_debug("Redrawing window [id=%d]", id);
+ draw_paint(state->draw, state->win);
+ break;
+ }
+ }
+}
+
static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer data)
{
EventSource *xsource = (EventSource *)source;
@@ -98,9 +113,7 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
case XCB_EXPOSE: {
xcb_expose_event_t *expose = (xcb_expose_event_t *)xsource->event;
log_debug("Processing event 'Expose' [type=%d]", XCB_EXPOSE);
-
- // Redraw
- //callback(data);
+ redraw_window(xsource->con, expose->window);
break;
}
@@ -127,9 +140,7 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
if (property->atom == XCB_ATOM_RESOURCE_MANAGER) {
update_xrm(xsource->con);
update_scale(xsource->con);
-
- // Redraw
- //callback(data);
+ redraw_window(xsource->con, property->window);
}
break;
}
@@ -168,9 +179,6 @@ static void attach_source(Connection *con)
source->event = NULL;
source->fd_tag = g_source_add_unix_fd(con->source, xcb_get_file_descriptor(con->connection), G_IO_IN | G_IO_HUP | G_IO_ERR);
- // TODO: Draw should be decoupled from this file
- //g_source_set_callback(con->source, G_SOURCE_FUNC(draw), win, NULL);
-
g_source_attach(con->source, NULL);
}
@@ -251,14 +259,31 @@ Connection *connection_create()
xcb_flush(con->connection);
log_debug("Xcb set up");
+ con->states = g_ptr_array_new();
+ g_assert_nonnull(con->states);
+
+ return con;
+}
+
+void connection_attach_source(Connection *con)
+{
+ g_assert_null(con->source);
+
attach_source(con);
log_debug("Xcb event loop attached");
+}
- return con;
+void connection_attach_state(Connection *con, State *state)
+{
+ g_assert_nonnull(state);
+ g_ptr_array_add(con->states, state);
+ log_debug("Attached state to event loop");
}
void connection_destroy(Connection *con)
{
+ g_ptr_array_free(con->states, true);
+
g_source_destroy(con->source);
g_source_unref(con->source);