aboutsummaryrefslogtreecommitdiff
path: root/wayland.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-17 14:19:14 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-18 03:48:01 +0000
commitb2a29280cbd3fcd825123e7636d511a06b2df242 (patch)
treef2facf782cef35842aca61021e0b3f34d635f518 /wayland.c
parentwayland: fractional_scale_preferred_scale(): only push update if scale has changed (diff)
wayland: use physical DPI on fractional-scale capable compositors
With legacy scaling, we need to use a "scaled", or "logical" DPI value, that is basically the real DPI value scaled by the monitor’s scaling factor. This is necessary to compensate for the compositor downscaling the surface, for "fake" fractional scaling. But with true fractional scaling, *we* scale the surface to the final size. This means we should *not* use the scaled DPI, but the monitor’s actual DPI. To facilitate this, store both the scaled and the unscaled DPI value in the monitor struct. This patch also changes how we pick the DPI value. Before, we would use the highest DPI value from all the monitors we were mapped on. Now, we use the DPI value from the monitor we were *last* mapped on (typically the window we’re dragging the window *to*).
Diffstat (limited to 'wayland.c')
-rw-r--r--wayland.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/wayland.c b/wayland.c
index f6ded585..c4f9e402 100644
--- a/wayland.c
+++ b/wayland.c
@@ -435,6 +435,9 @@ output_update_ppi(struct monitor *mon)
double x_inches = mon->dim.mm.width * 0.03937008;
double y_inches = mon->dim.mm.height * 0.03937008;
+ const int width = mon->dim.px_real.width;
+ const int height = mon->dim.px_real.height;
+
mon->ppi.real.x = mon->dim.px_real.width / x_inches;
mon->ppi.real.y = mon->dim.px_real.height / y_inches;
@@ -457,27 +460,36 @@ output_update_ppi(struct monitor *mon)
break;
}
- int scaled_width = mon->dim.px_scaled.width;
- int scaled_height = mon->dim.px_scaled.height;
-
- if (scaled_width == 0 && scaled_height == 0 && mon->scale > 0) {
- /* Estimate scaled width/height if none has been provided */
- scaled_width = mon->dim.px_real.width / mon->scale;
- scaled_height = mon->dim.px_real.height / mon->scale;
- }
+ const int scaled_width = mon->dim.px_scaled.width;
+ const int scaled_height = mon->dim.px_scaled.height;
mon->ppi.scaled.x = scaled_width / x_inches;
mon->ppi.scaled.y = scaled_height / y_inches;
- double px_diag = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
- mon->dpi = px_diag / mon->inch * mon->scale;
+ const double px_diag_physical = sqrt(pow(width, 2) + pow(height, 2));
+ mon->dpi.physical = width == 0 && height == 0
+ ? 96.
+ : px_diag_physical / mon->inch;
+
+ const double px_diag_scaled = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
+ mon->dpi.scaled = scaled_width == 0 && scaled_height == 0
+ ? 96.
+ : px_diag_scaled / mon->inch * mon->scale;
+
+ if (mon->dpi.physical > 1000) {
+ if (mon->name != NULL) {
+ LOG_WARN("%s: DPI=%f (physical) is unreasonable, using 96 instead",
+ mon->name, mon->dpi.physical);
+ }
+ mon->dpi.physical = 96;
+ }
- if (mon->dpi > 1000) {
+ if (mon->dpi.scaled > 1000) {
if (mon->name != NULL) {
- LOG_WARN("%s: DPI=%f is unreasonable, using 96 instead",
- mon->name, mon->dpi);
+ LOG_WARN("%s: DPI=%f (logical) is unreasonable, using 96 instead",
+ mon->name, mon->dpi.scaled);
}
- mon->dpi = 96;
+ mon->dpi.scaled = 96;
}
}
@@ -1487,14 +1499,12 @@ wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager,
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), DPI=%.2f",
+ "%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d, DPI=%.2f/%.2f (physical/scaled)",
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.dpi);
+ it->item.dpi.physical, it->item.dpi.scaled);
}
wayl->fd = wl_display_get_fd(wayl->display);