From e753bb953bdf2a30d79d637aafa64cf3fdd2f7d4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 12 Apr 2024 15:35:25 +0200 Subject: wayland: remove has_wl_compositor_v6 We deviate slightly from the specification, in that we don't assume a preferred buffer scale of 1. Instead, we "guess" the scale *until we receive a surface_preferred_buffer_scale event. Because of this, we don't need the has_wl_compositor_v6 member, as it's enough to check if we have a non-zero 'preferred buffer scale'. --- terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 3fb918a4..deb9ba81 100644 --- a/terminal.c +++ b/terminal.c @@ -2181,7 +2181,7 @@ term_fractional_scaling(const struct terminal *term) bool term_preferred_buffer_scale(const struct terminal *term) { - return term->wl->has_wl_compositor_v6 && term->window->preferred_buffer_scale > 0; + return term->window->preferred_buffer_scale > 0; } bool -- cgit v1.3 From 71ce17d97795419c3fe5d28132e387f27e2ca958 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 15 Apr 2024 16:03:30 +0200 Subject: term: don't print outside grid when printing multi-column characters When auto-wrap is disabled, a multi-column character may be printed on a line that doesn't fit the entire character. That is, the "spacers" we print, as place holders in the columns after the first one, may reach outside the grid. We did (try to) check for this, but the check was off by one. Meaning, we could, in some cases, print outside the grid. --- CHANGELOG.md | 3 +++ terminal.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'terminal.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3a0179..68b15356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,9 @@ ### Deprecated ### Removed ### Fixed + +* Crash when printing double-width (or longer) characters to, or near, + the last column, when auto-wrap (private mode 7) has been disabled. ### Security ### Contributors diff --git a/terminal.c b/terminal.c index deb9ba81..e747009a 100644 --- a/terminal.c +++ b/terminal.c @@ -3680,11 +3680,13 @@ term_print(struct terminal *term, char32_t wc, int width) grid_row_uri_range_erase(row, col, col + width - 1); /* Advance cursor the 'additional' columns while dirty:ing the cells */ - for (int i = 1; i < width && col < term->cols; i++) { + for (int i = 1; i < width && (col + 1) < term->cols; i++) { col++; print_spacer(term, col, width - i); } + xassert(col < term->cols); + /* Advance cursor */ if (unlikely(++col >= term->cols)) { grid->cursor.lcf = true; @@ -3726,6 +3728,7 @@ ascii_printer_fast(struct terminal *term, char32_t wc) /* Advance cursor */ if (unlikely(++col >= term->cols)) { + xassert(col == term->cols); grid->cursor.lcf = true; col--; } else -- cgit v1.3 From 7c20fb247c977fe545b1ef0ce9d8935b0424bf70 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 17 Apr 2024 08:35:58 +0200 Subject: term: stash last known DPI, and use after a unmapped/mapped sequence A compositor may unmap, and then remap the window, for example when the window is minimized, or if the user switches workspace. With DPI aware rendering, we *need* to know on which output we're mapped, in order to use the correct DPI. This means the first frame we render, before being mapped, always guesses the DPI. In an unmap/map sequence, guessing the wrong DPI means the window will flicker. Fix by stashing the last used DPI value, and use that instead of guessing. This means the *only* time we _actually_ guess the DPI, is the very first frame, when starting up foot. --- CHANGELOG.md | 3 +++ terminal.c | 24 +++++++++++++++++++++--- terminal.h | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'terminal.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index f4276f0a..b4384f0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,9 @@ * Crash when printing double-width (or longer) characters to, or near, the last column, when auto-wrap (private mode 7) has been disabled. * Dynamically sized sixel being trimmed to nothing. +* Flickering with `dpi-aware=yes` and window is unmapped/remapped + (some compositors do this when window is minimized), in a + multi-monitor setup with different monitor DPIs. ### Security diff --git a/terminal.c b/terminal.c index e747009a..c027cfac 100644 --- a/terminal.c +++ b/terminal.c @@ -858,9 +858,25 @@ get_font_dpi(const struct terminal *term) xassert(tll_length(term->wl->monitors) > 0); 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); + const struct monitor *mon = NULL; + + if (tll_length(win->on_outputs) > 0) + mon = tll_back(win->on_outputs); + else { + if (term->font_dpi_before_unmap > 0.) { + /* + * Use last known "good" DPI + * + * This avoids flickering when window is unmapped/mapped + * (some compositors do this when a window is minimized), + * on a multi-monitor setup with different monitor DPIs. + */ + return term->font_dpi_before_unmap; + } + + if (tll_length(term->wl->monitors) > 0) + mon = &tll_front(term->wl->monitors); + } if (term_fractional_scaling(term)) return mon != NULL ? mon->dpi.physical : 96.; @@ -1182,6 +1198,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, xmalloc(sizeof(term->font_sizes[3][0]) * conf->fonts[3].count), }, .font_dpi = 0., + .font_dpi_before_unmap = -1., .font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */ ? FCFT_SUBPIXEL_DEFAULT : FCFT_SUBPIXEL_NONE), @@ -2250,6 +2267,7 @@ term_font_dpi_changed(struct terminal *term, float old_scale) } term->font_dpi = dpi; + term->font_dpi_before_unmap = dpi; term->font_is_sized_by_dpi = will_scale_using_dpi; if (!need_font_reload) diff --git a/terminal.h b/terminal.h index fa80e693..2a0845ef 100644 --- a/terminal.h +++ b/terminal.h @@ -406,6 +406,7 @@ struct terminal { struct config_font *font_sizes[4]; struct pt_or_px font_line_height; float font_dpi; + float font_dpi_before_unmap; bool font_is_sized_by_dpi; int16_t font_x_ofs; int16_t font_y_ofs; -- cgit v1.3