mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-22 05:33:45 -04:00
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*).
This commit is contained in:
parent
59f0a721c4
commit
b2a29280cb
3 changed files with 55 additions and 51 deletions
46
wayland.c
46
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;
|
||||
|
||||
if (mon->dpi > 1000) {
|
||||
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 is unreasonable, using 96 instead",
|
||||
mon->name, mon->dpi);
|
||||
LOG_WARN("%s: DPI=%f (physical) is unreasonable, using 96 instead",
|
||||
mon->name, mon->dpi.physical);
|
||||
}
|
||||
mon->dpi = 96;
|
||||
mon->dpi.physical = 96;
|
||||
}
|
||||
|
||||
if (mon->dpi.scaled > 1000) {
|
||||
if (mon->name != NULL) {
|
||||
LOG_WARN("%s: DPI=%f (logical) is unreasonable, using 96 instead",
|
||||
mon->name, mon->dpi.scaled);
|
||||
}
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue