From acecab1c8bcb414521867fce46d238ad48f4b621 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 11 Mar 2020 16:10:55 +0100 Subject: term: use logical DPI+scale factor when scaling fonts This fixes an issue where the fonts were rendered too small when the output had fractional scaling. For integral scaling, using the logical (scaled) DPI multiplied with the scaling factor results in the same final DPI value as if we had used the physical DPI. But for fractional scaling, this works around the fact that the compositor downscales the surface after we've rendered it. Closes #5 --- wayland.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 322188ae..f915673e 100644 --- a/wayland.c +++ b/wayland.c @@ -169,10 +169,16 @@ update_terms_on_monitor(struct monitor *mon) static void output_update_ppi(struct monitor *mon) { - int x_inches = mon->width_mm * 0.03937008; - int y_inches = mon->height_mm * 0.03937008; - mon->x_ppi = mon->width_px / x_inches; - mon->y_ppi = mon->height_px / y_inches; + if (mon->dim.mm.width == 0 || mon->dim.mm.height == 0) + return; + + 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; } static void @@ -182,9 +188,9 @@ output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t transform) { struct monitor *mon = data; - mon->width_mm = physical_width; - mon->height_mm = physical_height; - mon->inch = sqrt(pow(mon->width_mm, 2) + pow(mon->height_mm, 2)) * 0.03937008; + mon->dim.mm.width = physical_width; + mon->dim.mm.height = physical_height; + mon->inch = sqrt(pow(mon->dim.mm.width, 2) + pow(mon->dim.mm.height, 2)) * 0.03937008; mon->make = make != NULL ? strdup(make) : NULL; mon->model = model != NULL ? strdup(model) : NULL; output_update_ppi(mon); @@ -199,8 +205,8 @@ output_mode(void *data, struct wl_output *wl_output, uint32_t flags, struct monitor *mon = data; mon->refresh = (float)refresh / 1000; - mon->width_px = width; - mon->height_px = height; + mon->dim.px_real.width = width; + mon->dim.px_real.height = height; output_update_ppi(mon); } @@ -238,6 +244,10 @@ static void xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) { + struct monitor *mon = data; + mon->dim.px_scaled.width = width; + mon->dim.px_scaled.height = height; + output_update_ppi(mon); } static void @@ -786,11 +796,12 @@ wayl_init(const struct config *conf, struct fdm *fdm) tll_foreach(wayl->monitors, it) { LOG_INFO( - "%s: %dx%d+%dx%d@%dHz %s (%.2f\", PPI=%dx%d, scale=%d)", - it->item.name, it->item.width_px, it->item.height_px, - it->item.x, it->item.y, (int)round(it->item.refresh), it->item.model, it->item.inch, - it->item.x_ppi, it->item.y_ppi, - it->item.scale); + "%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d PPI=%dx%d (physical) PPI=%dx%d (logical)", + 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, 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); } /* Clipboard */ -- cgit v1.3