aboutsummaryrefslogtreecommitdiff
path: root/terminal.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 /terminal.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 'terminal.c')
-rw-r--r--terminal.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/terminal.c b/terminal.c
index a557d632..86cb365a 100644
--- a/terminal.c
+++ b/terminal.c
@@ -733,7 +733,8 @@ term_line_height_update(struct terminal *term)
}
static bool
-term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
+term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4],
+ bool resize_grid)
{
for (size_t i = 0; i < 4; i++) {
xassert(fonts[i] != NULL);
@@ -777,11 +778,15 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
sixel_cell_size_changed(term);
- /* Use force, since cell-width/height may have changed */
- render_resize_force(
- term,
- round(term->width / term->scale),
- round(term->height / term->scale));
+ /* Optimization - some code paths (are forced to) call
+ * render_resize() after this function */
+ if (resize_grid) {
+ /* Use force, since cell-width/height may have changed */
+ render_resize_force(
+ term,
+ round(term->width / term->scale),
+ round(term->height / term->scale));
+ }
return true;
}
@@ -899,7 +904,7 @@ font_loader_thread(void *_data)
}
static bool
-reload_fonts(struct terminal *term)
+reload_fonts(struct terminal *term, bool resize_grid)
{
const struct config *conf = term->conf;
@@ -1026,7 +1031,7 @@ reload_fonts(struct terminal *term)
}
}
- return success ? term_set_fonts(term, fonts) : success;
+ return success ? term_set_fonts(term, fonts, resize_grid) : success;
}
static bool
@@ -1044,7 +1049,7 @@ load_fonts_from_conf(struct terminal *term)
}
}
- return reload_fonts(term);
+ return reload_fonts(term, true);
}
static void fdm_client_terminated(
@@ -1987,7 +1992,7 @@ term_font_size_adjust_by_points(struct terminal *term, float amount)
}
}
- return reload_fonts(term);
+ return reload_fonts(term, true);
}
static bool
@@ -2010,7 +2015,7 @@ term_font_size_adjust_by_pixels(struct terminal *term, int amount)
}
}
- return reload_fonts(term);
+ return reload_fonts(term, true);
}
static bool
@@ -2034,7 +2039,7 @@ term_font_size_adjust_by_percent(struct terminal *term, bool increment, float pe
}
}
- return reload_fonts(term);
+ return reload_fonts(term, true);
}
bool
@@ -2072,6 +2077,36 @@ term_font_size_reset(struct terminal *term)
}
bool
+term_update_scale(struct terminal *term)
+{
+ const struct wl_window *win = term->window;
+
+ /*
+ * We have a number of “sources” we can use as scale. We choose
+ * the scale in the following order:
+ *
+ * - “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 there aren’t any outputs available, use 1.0
+ */
+ const float new_scale =
+ (wayl_fractional_scaling(term->wl) && win->scale > 0.
+ ? win->scale
+ : (tll_length(win->on_outputs) > 0
+ ? tll_back(win->on_outputs)->scale
+ : 1.));
+
+ if (new_scale == term->scale)
+ return false;
+
+ LOG_DBG("scaling factor changed: %.2f -> %.2f", term->scale, new_scale);
+ term->scale = new_scale;
+ return true;
+}
+
+bool
term_font_dpi_changed(struct terminal *term, float old_scale)
{
float dpi = get_font_dpi(term);
@@ -2099,9 +2134,9 @@ term_font_dpi_changed(struct terminal *term, float old_scale)
term->font_is_sized_by_dpi = will_scale_using_dpi;
if (!need_font_reload)
- return true;
+ return false;
- return reload_fonts(term);
+ return reload_fonts(term, false);
}
void
@@ -3500,7 +3535,7 @@ term_update_ascii_printer(struct terminal *term)
#if defined(_DEBUG) && LOG_ENABLE_DBG
if (term->ascii_printer != new_printer) {
- LOG_DBG("§switching ASCII printer %s -> %s",
+ LOG_DBG("switching ASCII printer %s -> %s",
term->ascii_printer == &ascii_printer_fast ? "fast" : "generic",
new_printer == &ascii_printer_fast ? "fast" : "generic");
}