terminal: break out scaling factor updating, and reduce number of calls to render_resize()

Break out the logic that updates the terminal’s scaling factor value,
from render_resize(), to a new function, term_update_scale(). This
allows us to update the scaling factor without a full grid resize.

We also change how we pick the scaling factor (when fractional scaling
is not in use). Before, we’d use the highest scaling factor from all
monitors we were mapped on. Now, we use the scaling factor from the
monitor we were *last* mapped on.

Then, add a boolean parameter to term_set_fonts(), and when
false, *don’t* call render_resize_force().

Also change term_font_dpi_changed() to only return true if the font
was changed in any way.

Finally, rewrite update_term_for_output_change() to:

* Call term_update_scale() before doing anything else
* Call render_resize{,_force} *last*, and *only* if either the scale
  or the fonts were updated.

This fixes several things:

* A bug where we failed to update the fonts when fractional scaling
  was in use, and we guessed the initial scale/DPI wrong. The bug
  happened because updated the internal "preferred" scale value, and a
  later call to render_resize() updated the terminal’s scale value,
  but since that code path didn’t call term_font_dpi_changed() (and it
  shouldn’t), the fonts weren’t resized properly.

* It ensures we only resize the grid *once* when the scaling factor,
  or DPI is changed. Before this, we’d resize it twice. And this
  happened when e.g. dragging the window between monitors.
This commit is contained in:
Daniel Eklöf 2023-07-17 16:21:16 +02:00
parent c96863b188
commit 21d99f8dce
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 84 additions and 45 deletions

View file

@ -3841,21 +3841,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
if (term->cell_width == 0 && term->cell_height == 0)
return false;
float scale = -1;
if (wayl_fractional_scaling(term->wl)) {
scale = term->window->scale;
} else {
tll_foreach(term->window->on_outputs, it) {
if (it->item->scale > scale)
scale = it->item->scale;
}
}
if (scale < 0.) {
/* Haven't 'entered' an output yet? */
scale = term->scale;
}
const float scale = term->scale;
width = round(width * scale);
height = round(height * scale);
@ -3942,9 +3928,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
/* Drop out of URL mode */
urls_reset(term);
LOG_DBG("resized: size=%dx%d (scale=%.2f)", width, height, term->scale);
term->width = width;
term->height = height;
term->scale = scale;
const uint32_t scrollback_lines = term->render.scrollback_lines;
@ -4148,12 +4134,11 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
sixel_reflow(term);
#if defined(_DEBUG) && LOG_ENABLE_DBG
LOG_DBG("resize: %dx%d, grid: cols=%d, rows=%d "
LOG_DBG("resized: grid: cols=%d, rows=%d "
"(left-margin=%d, right-margin=%d, top-margin=%d, bottom-margin=%d)",
term->width, term->height, term->cols, term->rows,
term->margins.left, term->margins.right, term->margins.top, term->margins.bottom);
#endif
term->cols, term->rows,
term->margins.left, term->margins.right,
term->margins.top, term->margins.bottom);
if (term->scroll_region.start >= term->rows)
term->scroll_region.start = 0;
@ -4295,7 +4280,7 @@ render_xcursor_update(struct seat *seat)
#endif
LOG_DBG("setting %scursor shape using a client-side cursor surface",
shape == CURSOR_SHAPE_CUSTOM ? "custom " : "");
seat->pointer.shape == CURSOR_SHAPE_CUSTOM ? "custom " : "");
const float scale = seat->pointer.scale;
struct wl_cursor_image *image = seat->pointer.cursor->images[0];