From e955a14dd0bf7ed23a9e42f28a93e3357643300c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 26 Jul 2020 07:41:57 +0200 Subject: [PATCH] wayland: calculate a single, scaled DPI value Previously, we calculated the monitors horizontal and vertical PPI values. For font sizing, we used the vertical PPI value. It seems however, that using the diagonal PPI value, i.e. diagonal_px / diagonal_inch, gives more consistent results. This is still a PPI value, but since it is intended to be used as a FontConfig DPI value, name it 'dpi'. --- wayland.c | 13 +++++++++++-- wayland.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wayland.c b/wayland.c index 70d5e0f1..bb7405a2 100644 --- a/wayland.c +++ b/wayland.c @@ -294,11 +294,18 @@ output_update_ppi(struct monitor *mon) int x_inches = mon->dim.mm.width * 0.03937008; int y_inches = mon->dim.mm.height * 0.03937008; + mon->ppi.real.x = mon->dim.px_real.width / x_inches; mon->ppi.real.y = mon->dim.px_real.height / y_inches; mon->ppi.scaled.x = mon->dim.px_scaled.width / x_inches; mon->ppi.scaled.y = mon->dim.px_scaled.height / y_inches; + + float px_diag = sqrt( + pow(mon->dim.px_scaled.width, 2) + + pow(mon->dim.px_scaled.height, 2)); + + mon->dpi = px_diag / mon->inch * mon->scale; } static void @@ -343,6 +350,7 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct monitor *mon = data; mon->scale = factor; + output_update_ppi(mon); } static const struct wl_output_listener output_listener = { @@ -1029,13 +1037,14 @@ wayl_init(const struct config *conf, struct fdm *fdm) tll_foreach(wayl->monitors, it) { LOG_INFO( - "%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d PPI=%dx%d (physical) PPI=%dx%d (logical)", + "%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d PPI=%dx%d (physical) PPI=%dx%d (logical), DPI=%.2f", it->item.name, it->item.dim.px_real.width, it->item.dim.px_real.height, it->item.x, it->item.y, (int)round(it->item.refresh), it->item.model != NULL ? it->item.model : it->item.description, it->item.inch, it->item.scale, it->item.ppi.real.x, it->item.ppi.real.y, - it->item.ppi.scaled.x, it->item.ppi.scaled.y); + it->item.ppi.scaled.x, it->item.ppi.scaled.y, + it->item.dpi); } wayl->fd = wl_display_get_fd(wayl->display); diff --git a/wayland.h b/wayland.h index dbf63c1b..88be3d71 100644 --- a/wayland.h +++ b/wayland.h @@ -236,6 +236,8 @@ struct monitor { } scaled; } ppi; + float dpi; + int scale; float refresh; enum wl_output_subpixel subpixel;