mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05: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
55
terminal.c
55
terminal.c
|
|
@ -796,41 +796,34 @@ get_font_dpi(const struct terminal *term)
|
|||
* Conceptually, we use the physical monitor specs to calculate
|
||||
* the DPI, and we ignore the output's scaling factor.
|
||||
*
|
||||
* However, to deal with fractional scaling, where we're told to
|
||||
* render at e.g. 2x, but are then downscaled by the compositor to
|
||||
* e.g. 1.25, we use the scaled DPI value multiplied by the scale
|
||||
* factor instead.
|
||||
* However, to deal with legacy fractional scaling, where we're
|
||||
* told to render at e.g. 2x, but are then downscaled by the
|
||||
* compositor to e.g. 1.25, we use the scaled DPI value multiplied
|
||||
* by the scale factor instead.
|
||||
*
|
||||
* For integral scaling factors the resulting DPI is the same as
|
||||
* if we had used the physical DPI.
|
||||
*
|
||||
* For fractional scaling factors we'll get a DPI *larger* than
|
||||
* the physical DPI, that ends up being right when later
|
||||
* For legacy fractional scaling factors we'll get a DPI *larger*
|
||||
* than the physical DPI, that ends up being right when later
|
||||
* downscaled by the compositor.
|
||||
*
|
||||
* With the newer fractional-scale-v1 protocol, we use the
|
||||
* monitor’s real DPI, since we scale everything to the correct
|
||||
* scaling factor (no downscaling done by the compositor).
|
||||
*/
|
||||
|
||||
/* Use highest DPI from outputs we're mapped on */
|
||||
double dpi = 0.0;
|
||||
xassert(term->window != NULL);
|
||||
tll_foreach(term->window->on_outputs, it) {
|
||||
if (it->item->dpi > dpi)
|
||||
dpi = it->item->dpi;
|
||||
}
|
||||
xassert(tll_length(term->wl->monitors) > 0);
|
||||
|
||||
/* If we're not mapped, use DPI from first monitor. Hopefully this is where we'll get mapped later... */
|
||||
if (dpi == 0.) {
|
||||
tll_foreach(term->wl->monitors, it) {
|
||||
dpi = it->item.dpi;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const struct wl_window *win = term->window;
|
||||
const struct monitor *mon = tll_length(win->on_outputs) > 0
|
||||
? tll_back(win->on_outputs)
|
||||
: &tll_front(term->wl->monitors);
|
||||
|
||||
if (dpi == 0) {
|
||||
/* No monitors? */
|
||||
dpi = 96.;
|
||||
}
|
||||
|
||||
return dpi;
|
||||
if (wayl_fractional_scaling(term->wl))
|
||||
return mon->dpi.physical;
|
||||
else
|
||||
return mon->dpi.scaled;
|
||||
}
|
||||
|
||||
static enum fcft_subpixel
|
||||
|
|
@ -1285,11 +1278,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
reaper_add(term->reaper, term->slave, &fdm_client_terminated, term);
|
||||
|
||||
/* Guess scale; we're not mapped yet, so we don't know on which
|
||||
* output we'll be. Pick highest scale we find for now */
|
||||
tll_foreach(term->wl->monitors, it) {
|
||||
if (it->item.scale > term->scale)
|
||||
term->scale = it->item.scale;
|
||||
}
|
||||
* output we'll be. Use scaling factor from first monitor */
|
||||
xassert(tll_length(term->wl->monitors) > 0);
|
||||
term->scale = tll_front(term->wl->monitors).scale;
|
||||
|
||||
memcpy(term->colors.table, term->conf->colors.table, sizeof(term->colors.table));
|
||||
|
||||
|
|
@ -2096,7 +2087,7 @@ term_font_dpi_changed(struct terminal *term, float old_scale)
|
|||
: old_scale != term->scale);
|
||||
|
||||
if (need_font_reload) {
|
||||
LOG_DBG("DPI/scale change: DPI-awareness=%s, "
|
||||
LOG_DBG("DPI/scale change: DPI-aware=%s, "
|
||||
"DPI: %.2f -> %.2f, scale: %.2f -> %.2f, "
|
||||
"sizing font based on monitor's %s",
|
||||
term->conf->dpi_aware ? "yes" : "no",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue