From 43b4d4bb41e2b5f1c696f5d8f7178984b04d9f47 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Sat, 18 Mar 2017 13:34:55 +0200 Subject: [PATCH] Add per_monitor_dpi experimental setting Calculating the screen dpi on a per-monitor basis can cause inconsistencies if multiple monitors with slightly different dpis are used and in some cases it might not be the expected behaviour. As such, the per-monitor dpi calculation was changed from a default fallback to an opt in experimental feature and the default value of 96 will be used for the dpi if Xft.dpi is not set. In the future, depending on how we decide to continue, we can either move this setting in the global configuration section and fall back to the X11 display dpi as the default or simply always use the per-monitor dpi calculation. But to preserve backwards compatibility, this decision can wait until the next major release. --- CHANGELOG.md | 2 ++ dunstrc | 7 +++++++ src/settings.c | 6 ++++++ src/settings.h | 1 + src/x11/screen.c | 10 ++++++---- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a027110..5a33acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Support for per-urgency frame colours - `markup` setting for more fine-grained control over how markup is handled - `history_ignore` rule action to exclude a notification from being added to the history +- Support for setting the dpi value dunst will use for font rendering via the `Xft.dpi` X resource +- Experimental support for per-monitor dpi calculation ### Changed - Text and icons are now centred vertically diff --git a/dunstrc b/dunstrc index b7c6f40..8536bc1 100644 --- a/dunstrc +++ b/dunstrc @@ -181,6 +181,13 @@ # Always run rule-defined scripts, even if the notification is suppressed always_run_script = true +# Experimental features that may or may not work correctly. Do not expect them +# to have a consistent behaviour across releases. +[experimental] + # Calculate the dpi to use on a per-monitor basis. + # Please note that this setting will not work if Xft.dpi X resource is set. + per_monitor_dpi = false + [frame] width = 3 color = "#aaaaaa" diff --git a/src/settings.c b/src/settings.c index 9bf3e2b..01016e9 100644 --- a/src/settings.c +++ b/src/settings.c @@ -97,6 +97,12 @@ void load_settings(char *cmdline_config_path) load_ini_file(config_file); #endif + settings.per_monitor_dpi = option_get_bool( + "experimental", + "per_monitor_dpi", NULL, false, + "" + ); + settings.font = option_get_string( "global", "font", "-fn", font, diff --git a/src/settings.h b/src/settings.h index a5097f6..f2d2c93 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,6 +14,7 @@ enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL }; typedef struct _settings { bool print_notifications; + bool per_monitor_dpi; enum markup_mode markup; bool stack_duplicates; bool hide_duplicate_count; diff --git a/src/x11/screen.c b/src/x11/screen.c index 1852bc5..49abb82 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -56,7 +56,6 @@ static double get_xft_dpi_value() } XrmDestroyDatabase(xDB); } - return dpi; } @@ -106,7 +105,7 @@ void x_update_screens() XRRFreeMonitors(m); } -static double autodetect_dpi(screen_info *scr) +static int autodetect_dpi(screen_info *scr) { return (double)scr->dim.h * 25.4 / (double)scr->dim.mmh; } @@ -256,9 +255,12 @@ sc_cleanup: double get_dpi_for_screen(screen_info *scr) { double dpi = 0; - if ((dpi = get_xft_dpi_value()) || (dpi = autodetect_dpi(scr))) + if ((dpi = get_xft_dpi_value())) return dpi; - return 0; + else if (settings.per_monitor_dpi && (dpi = autodetect_dpi(scr))) + return dpi; + else + return 96; } /*