aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-15 23:53:55 +0100
committerFederico Angelilli <code@fedang.net>2023-11-15 23:53:55 +0100
commite4b9aed49eb5464c631960627b63ef703e6e20a4 (patch)
tree7e5c073b600f3b0b927a397d1bd6349d29a207ec
parent6ebf2ef9b1c0e08b2b1b3fec18839295014dd688 (diff)
Refine connection event dispatcher
-rw-r--r--connection.c67
-rw-r--r--connection.h5
-rw-r--r--draw.c6
3 files changed, 52 insertions, 26 deletions
diff --git a/connection.c b/connection.c
index 5a869c4..0c07c70 100644
--- a/connection.c
+++ b/connection.c
@@ -8,6 +8,34 @@
#include "log.h"
#include "connection.h"
+static bool query_xrm(Connection *con, const char *res, char **value)
+{
+ if (xcb_xrm_resource_get_string(con->database, res, res, value) >= 0) {
+ log_debug("Xrm query '%s' found '%s'", res, *value);
+ return true;
+ }
+
+ log_debug("Xrm query '%s' not found", res);
+ return false;
+}
+
+static void update_xrm(Connection *con)
+{
+ // TODO
+}
+
+static void update_scale(Connection *con)
+{
+ char *dpi_value;
+ if (query_xrm(con, "Xft.dpi", &dpi_value)) {
+ con->screen_dpi = strtod(dpi_value, NULL);
+ g_free(dpi_value);
+ } else {
+ con->screen_dpi = (double)con->screen_size->height * 25.4 / (double)con->screen_size->mheight;
+ log_debug("Fallback dpi value '%.2lf'", con->screen_dpi);
+ }
+}
+
typedef struct {
GSource source;
Connection *con;
@@ -65,8 +93,19 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
break;
}
+ case XCB_CREATE_NOTIFY: {
+ xcb_create_notify_event_t *create = (xcb_create_notify_event_t *)xsource->event;
+ log_debug("Processing event 'CreateNotify' [type=%d]", XCB_CREATE_NOTIFY);
+
+ // TODO: Circulate top the window if override_redirect == 0
+
+ break;
+ }
+
case XCB_BUTTON_RELEASE: {
log_debug("Mouse event");
+
+ // TODO: Handle click generically by translating the button code
break;
}
@@ -75,7 +114,8 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
log_debug("Processing event 'PropertyNotify' [type=%d]", XCB_PROPERTY_NOTIFY);
if (property->atom == XCB_ATOM_RESOURCE_MANAGER) {
- //window_update_scale(data);
+ update_xrm(xsource->con);
+ update_scale(xsource->con);
// Redraw
//callback(data);
@@ -87,6 +127,8 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer
const char *extension;
const char *name = xcb_errors_get_name_for_xcb_event(xsource->con->errors, xsource->event, &extension);
+ // TODO: Handle XCB_RANDR_SCREEN_CHANGE_NOTIFY
+
log_debug("Ignoring event '%s' [type=%d, extension=%s]",
name,
xsource->event->response_type & 0x7f,
@@ -121,29 +163,6 @@ static void attach_source(Connection *con)
g_source_attach(con->source, NULL);
}
-static bool query_xrm(Connection *con, const char *res, char **value)
-{
- if (xcb_xrm_resource_get_string(con->database, res, res, value) >= 0) {
- log_debug("Xrm query '%s' found '%s'", res, *value);
- return true;
- }
-
- log_debug("Xrm query '%s' not found", res);
- return false;
-}
-
-static void update_scale(Connection *con)
-{
- char *dpi_value;
- if (query_xrm(con, "Xft.dpi", &dpi_value)) {
- con->screen_dpi = strtod(dpi_value, NULL);
- g_free(dpi_value);
- } else {
- con->screen_dpi = (double)con->screen_size->height * 25.4 / (double)con->screen_size->mheight;
- log_debug("Fallback dpi value '%.2lf'", con->screen_dpi);
- }
-}
-
Connection *connection_create()
{
Connection *con = g_malloc0(sizeof(Connection));
diff --git a/connection.h b/connection.h
index 6d0a0cf..1cb0160 100644
--- a/connection.h
+++ b/connection.h
@@ -8,9 +8,10 @@
#include <xcb/xcb_errors.h>
#include <xcb/randr.h>
+typedef struct Connection Connection;
// TODO: Make this opaque
-typedef struct {
+struct Connection {
xcb_connection_t *connection;
xcb_screen_t *screen;
xcb_randr_screen_size_t *screen_size;
@@ -21,7 +22,7 @@ typedef struct {
xcb_errors_context_t *errors;
xcb_ewmh_connection_t ewmh;
GSource *source;
-} Connection;
+};
Connection *connection_create();
diff --git a/draw.c b/draw.c
index 7f77927..ebaf004 100644
--- a/draw.c
+++ b/draw.c
@@ -6,6 +6,12 @@
#include "draw.h"
#include "log.h"
+// Idea: Either make a to_draw queue where we put things we schedule to redraw
+// (this will also work for animations in the future)
+// or use some flags to trigger drawing
+//
+// Anyway, a drawing context struct is required
+
// Make this a state passed to draw
int draw_height, draw_x_padding, draw_y_padding;
PangoFontDescription *desc;