mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
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:
parent
c96863b188
commit
21d99f8dce
4 changed files with 84 additions and 45 deletions
34
wayland.c
34
wayland.c
|
|
@ -396,17 +396,35 @@ static const struct wl_seat_listener seat_listener = {
|
|||
static void
|
||||
update_term_for_output_change(struct terminal *term)
|
||||
{
|
||||
if (tll_length(term->window->on_outputs) == 0)
|
||||
return;
|
||||
const float old_scale = term->scale;
|
||||
const float logical_width = term->width / term->scale;
|
||||
const float logical_height = term->height / term->scale;
|
||||
|
||||
float old_scale = term->scale;
|
||||
|
||||
render_resize(term,
|
||||
round(term->width / term->scale),
|
||||
round(term->height / term->scale));
|
||||
term_font_dpi_changed(term, old_scale);
|
||||
/* Note: order matters! term_update_scale() must come first */
|
||||
bool scale_updated = term_update_scale(term);
|
||||
bool fonts_updated = term_font_dpi_changed(term, old_scale);
|
||||
term_font_subpixel_changed(term);
|
||||
|
||||
csd_reload_font(term->window, old_scale);
|
||||
|
||||
if (fonts_updated) {
|
||||
/*
|
||||
* If the fonts have been updated, the cell dimensions have
|
||||
* changed. This requires a “forced” resize, since the surface
|
||||
* buffer dimensions may not have been updated (in which case
|
||||
* render_size() normally shortcuts and returns early).
|
||||
*/
|
||||
render_resize_force(term, round(logical_width), round(logical_height));
|
||||
}
|
||||
|
||||
else if (scale_updated) {
|
||||
/*
|
||||
* A scale update means the surface buffer dimensions have
|
||||
* been updated, even though the window logical dimensions
|
||||
* haven’t changed.
|
||||
*/
|
||||
render_resize(term, round(logical_width), round(logical_height));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue