From ad7dec31d5785ce9006bbb8498529bead652d19c Mon Sep 17 00:00:00 2001 From: mihaicmn Date: Sat, 12 Nov 2016 16:34:54 +0200 Subject: [PATCH] Use the DPI setting within the i3bar (#2556) --- i3bar/src/main.c | 2 ++ include/libi3.h | 6 ++++++ libi3/dpi.c | 8 ++++++++ libi3/font.c | 14 +------------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/i3bar/src/main.c b/i3bar/src/main.c index be684fc5..910e9524 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -149,6 +149,8 @@ int main(int argc, char **argv) { socket_path = expand_path(i3_default_sock_path); } + init_dpi(); + init_outputs(); if (init_connection(socket_path)) { /* Request the bar configuration. When it arrives, we fill the config array. */ diff --git a/include/libi3.h b/include/libi3.h index 11ca3127..94e1d78b 100644 --- a/include/libi3.h +++ b/include/libi3.h @@ -473,6 +473,12 @@ char *get_exe_path(const char *argv0); */ void init_dpi(void); +/** + * This function returns the value of the DPI setting. + * + */ +long get_dpi_value(void); + /** * Convert a logical amount of pixels (e.g. 2 pixels on a “standard” 96 DPI * screen) to a corresponding amount of physical pixels on a standard or retina diff --git a/libi3/dpi.c b/libi3/dpi.c index a832a689..d0d1bc68 100644 --- a/libi3/dpi.c +++ b/libi3/dpi.c @@ -64,6 +64,14 @@ init_dpi_end: } } +/* + * This function returns the value of the DPI setting. + * + */ +long get_dpi_value(void) { + return dpi; +} + /* * Convert a logical amount of pixels (e.g. 2 pixels on a “standard” 96 DPI * screen) to a corresponding amount of physical pixels on a standard or retina diff --git a/libi3/font.c b/libi3/font.c index fa848481..81091ea7 100644 --- a/libi3/font.c +++ b/libi3/font.c @@ -24,24 +24,12 @@ static double pango_font_red; static double pango_font_green; static double pango_font_blue; -/* Necessary to track whether the dpi changes and trigger a LOG() message, - * which is more easily visible to users. */ -static double logged_dpi = 0.0; - static PangoLayout *create_layout_with_dpi(cairo_t *cr) { PangoLayout *layout; PangoContext *context; context = pango_cairo_create_context(cr); - const double dpi = (double)root_screen->height_in_pixels * 25.4 / - (double)root_screen->height_in_millimeters; - if (logged_dpi != dpi) { - logged_dpi = dpi; - LOG("X11 root window dictates %f DPI\n", dpi); - } else { - DLOG("X11 root window dictates %f DPI\n", dpi); - } - pango_cairo_context_set_resolution(context, dpi); + pango_cairo_context_set_resolution(context, get_dpi_value()); layout = pango_layout_new(context); g_object_unref(context); -- 2.39.2