From 86ef638102a6e03a5f46326162376c964ad353af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 18 Aug 2023 16:39:00 +0200 Subject: [PATCH] term: improve fallback logic when selecting scaling factor while unmapped The foot window may, for various reasons, become completely unmapped (that is, being removed from all outputs) at run time. One example is wlroots based compositors; they unmap all other windows when an opaque window is fullscreened. 21d99f8dced335826964ca96b8ba7ccac059e598 introduced a regression, where instead of picking the scaling factor from one of the available outputs (at random), we started falling back to '1' as soon as we were unmapped. This patch restores the original logic, but also improves upon it. As soon as a scaling factor has been assigned to the window, we store a copy of it in the term struct ('scale_before_unmap'). When unmapped, we check if it has a valid value (the only time it doesn't is before the initial map). If so, we use it. Only if it hasn't been set do we fall back to picking an output at random, and using its scaling factor. Closes #1464 --- CHANGELOG.md | 3 +++ terminal.c | 21 ++++++++++++++------- terminal.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2272050..00d66919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,8 +74,11 @@ * Race condition for systemd units start in GNOME and KDE ([#1436][1436]). +* One frame being rendered at the wrong scale after being hidden by + another opaque, maximized window ([#1464][1464]). [1436]: https://codeberg.org/dnkl/foot/issues/1436 +[1464]: https://codeberg.org/dnkl/foot/issues/1464 ### Security diff --git a/terminal.c b/terminal.c index 2f81adc8..f19da873 100644 --- a/terminal.c +++ b/terminal.c @@ -1161,6 +1161,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .auto_margin = true, .window_title_stack = tll_init(), .scale = 1., + .scale_before_unmap = -1, .flash = {.fd = flash_fd}, .blink = {.fd = -1}, .vt = { @@ -2094,21 +2095,27 @@ term_update_scale(struct terminal *term) * * - “preferred” scale, from the fractional-scale-v1 protocol * - scaling factor of output we most recently were mapped on - * - if we’re not mapped, use the scaling factor from the first - * available output. + * - if we're not mapped, use the last known scaling factor + * - if we're not mapped, and we don't have a last known scaling + * factor, use the scaling factor from the first available + * output. * - if there aren’t any outputs available, use 1.0 */ - const float new_scale = - (term_fractional_scaling(term) - ? win->scale - : (tll_length(win->on_outputs) > 0 + const float new_scale = (term_fractional_scaling(term) + ? win->scale + : tll_length(win->on_outputs) > 0 ? tll_back(win->on_outputs)->scale - : 1.)); + : term->scale_before_unmap > 0. + ? term->scale_before_unmap + : tll_length(term->wl->monitors) > 0 + ? tll_front(term->wl->monitors).scale + : 1.); if (new_scale == term->scale) return false; LOG_DBG("scaling factor changed: %.2f -> %.2f", term->scale, new_scale); + term->scale_before_unmap = new_scale; term->scale = new_scale; return true; } diff --git a/terminal.h b/terminal.h index 25019ecd..0bba6945 100644 --- a/terminal.h +++ b/terminal.h @@ -489,6 +489,7 @@ struct terminal { } blink; float scale; + float scale_before_unmap; /* Last scaling factor used */ int width; /* pixels */ int height; /* pixels */ int stashed_width;