aboutsummaryrefslogtreecommitdiff
path: root/wayland.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-17 14:21:16 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-18 03:48:01 +0000
commit21d99f8dced335826964ca96b8ba7ccac059e598 (patch)
treee32037a800cc50d0d079a84434339e3bdd19fa24 /wayland.c
parentwayland: error out if there aren’t any monitors available (diff)
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.
Diffstat (limited to 'wayland.c')
-rw-r--r--wayland.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/wayland.c b/wayland.c
index 85140d6f..354a0e78 100644
--- a/wayland.c
+++ b/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;
-
- float old_scale = term->scale;
+ const float old_scale = term->scale;
+ const float logical_width = term->width / term->scale;
+ const float logical_height = term->height / 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