aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--x11.c47
-rw-r--r--x11.h2
2 files changed, 32 insertions, 17 deletions
diff --git a/x11.c b/x11.c
index fb7cddf..df072b9 100644
--- a/x11.c
+++ b/x11.c
@@ -3,13 +3,12 @@
#include <cairo.h>
#include <cairo-xcb.h>
#include <xcb/xcb.h>
-#include <xcb/xcb_aux.h>
#include <xcb/xproto.h>
+#include <xcb/xcb_aux.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_xrm.h>
-#include <xcb/randr.h>
-#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
+#include <xcb/randr.h>
#include "x11.h"
#include "log.h"
@@ -92,6 +91,17 @@ static gboolean xcb_source_dispatch(GSource *source, GSourceFunc callback, gpoin
break;
}
+ case XCB_PROPERTY_NOTIFY: {
+ xcb_property_notify_event_t *property = (xcb_property_notify_event_t *)xsource->event;
+ if (property->atom == XCB_ATOM_RESOURCE_MANAGER) {
+ window_update_scale(data);
+
+ // Redraw
+ callback(data);
+ }
+ break;
+ }
+
default: {
log_debug("Ignoring event '%s' [type %d]",
xcb_event_get_label(xsource->event->response_type),
@@ -185,19 +195,9 @@ Window *window_create(void)
win->database = xcb_xrm_database_from_default(win->connection);
g_assert_nonnull(win->database);
- char *dpi_value;
- if (xcb_xrm_resource_get_string(win->database, "Xft.dpi", "Xft.dpi", &dpi_value) >= 0) {
- log_debug("Xrm query '%s' found '%s'", "Xft.dpi", dpi_value);
- win->dpi = strtod(dpi_value, NULL);
- g_free(dpi_value);
- } else {
- log_debug("Xrm query '%s' not found", "Xft.dpi");
- win->dpi = 96.0;
- //win->dpi = (double)screen_size->height * 25.4 / (double)screen_size->mheight;
- log_debug("Fallback dpi value '%lf'", win->dpi);
- }
- xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(win->screen);
+ window_update_scale(win);
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(win->screen);
while (depth_iter.rem) {
xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
@@ -212,7 +212,6 @@ Window *window_create(void)
}
found_visual:
-
log_debug("Xcb visual type found (id %u)", win->visual_type->visual_id);
const uint32_t value_mask = XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL
@@ -224,7 +223,6 @@ found_visual:
xcb_colormap_t colormap = xcb_generate_id(win->connection);
xcb_create_colormap(win->connection, XCB_COLORMAP_ALLOC_NONE, colormap, win->screen->root, win->visual_type->visual_id);
-
log_debug("Xcb colormap created (id %u)", colormap);
const uint32_t value_list[] = {
@@ -306,6 +304,21 @@ cairo_t *window_get_context(Window *win)
return win->cr;
}
+void window_update_scale(Window *win)
+{
+ char *dpi_value;
+ if (xcb_xrm_resource_get_string(win->database, "Xft.dpi", "Xft.dpi", &dpi_value) >= 0) {
+ log_debug("Xrm query '%s' found '%s'", "Xft.dpi", dpi_value);
+ win->dpi = strtod(dpi_value, NULL);
+ g_free(dpi_value);
+ } else {
+ log_debug("Xrm query '%s' not found", "Xft.dpi");
+ win->dpi = 96.0;
+ //win->dpi = (double)screen_size->height * 25.4 / (double)screen_size->mheight;
+ log_debug("Fallback dpi value '%lf'", win->dpi);
+ }
+}
+
double window_get_scale(Window *win)
{
return MAX(1, win->dpi/96.);
diff --git a/x11.h b/x11.h
index 0d8cd4c..3884485 100644
--- a/x11.h
+++ b/x11.h
@@ -9,6 +9,8 @@ Window *window_create(void);
cairo_t *window_get_context(Window *win);
+void window_update_scale(Window *win);
+
double window_get_scale(Window *win);
void window_get_screen_size(Window *win, int *width, int *height);