diff options
| author | Federico Angelilli <code@fedang.net> | 2023-11-13 16:47:23 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-11-13 16:47:23 +0100 |
| commit | a6fad8924ef8f351d6c77a092afd3e0918e002b1 (patch) | |
| tree | 2fa81303940580626a0f55c76d790fd333f63641 /x11.c | |
| parent | 8174acdccbe039b8cf8cbefce6fbbf24ce0a5eaf (diff) | |
Extract window scale fetching logic
Diffstat (limited to 'x11.c')
| -rw-r--r-- | x11.c | 47 |
1 files changed, 30 insertions, 17 deletions
@@ -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.); |
