aboutsummaryrefslogtreecommitdiff
path: root/x11.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-11-02 20:23:03 +0100
committerFederico Angelilli <code@fedang.net>2023-11-02 20:23:03 +0100
commit185af2377c283f3e660cf9383018df70712e9a26 (patch)
tree1b89278710db020ae611851002be38150abcbeb4 /x11.c
parentc2ef5b291c1ef9120ac9d5c29b378317ab189212 (diff)
Add xrdb and dpi query
Diffstat (limited to 'x11.c')
-rw-r--r--x11.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/x11.c b/x11.c
index 1cf4393..f95d4f5 100644
--- a/x11.c
+++ b/x11.c
@@ -1,4 +1,5 @@
#include <stdbool.h>
+#include <assert.h>
#include <glib.h>
#include <math.h>
#include <cairo.h>
@@ -14,10 +15,12 @@
struct Window {
xcb_screen_t *screen;
xcb_connection_t *connection;
+ xcb_xrm_database_t *database;
xcb_drawable_t window;
xcb_visualtype_t *visual_type;
cairo_surface_t *surface;
cairo_t *cr;
+ double dpi;
};
Window *window_create(void)
@@ -26,6 +29,19 @@ Window *window_create(void)
int preferred_screen = 0;
win->connection = xcb_connect(NULL, &preferred_screen);
+ assert(win->connection != NULL && !xcb_connection_has_error(win->connection));
+
+ win->database = xcb_xrm_database_from_default(win->connection);
+ assert(win->database != NULL);
+
+ char *dpi_value;
+ if (xcb_xrm_resource_get_string(win->database, "Xft.dpi", "Xft.dpi", &dpi_value) >= 0) {
+ win->dpi = strtod(dpi_value, NULL);
+ g_free(dpi_value);
+ } else {
+ // TODO: Calculate automatically somehow
+ win->dpi = 96.0;
+ }
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(win->connection));
@@ -35,7 +51,6 @@ Window *window_create(void)
}
win->screen = iter.data;
-
win->window = xcb_generate_id(win->connection);
int y = 0, x = 0, h = 300, w = 400;
@@ -84,8 +99,7 @@ cairo_t *window_get_context(Window *win)
double window_get_scale(Window *win)
{
- // TODO
- return 1;
+ return MAX(1, win->dpi/96.);
}
void window_paint_surface(Window *win, cairo_surface_t *surface, int width, int height)
@@ -107,6 +121,7 @@ void window_destroy(Window *win)
{
cairo_destroy(win->cr);
cairo_surface_destroy(win->surface);
+ xcb_xrm_database_free(win->database);
xcb_disconnect(win->connection);
g_free(win);
}