aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-25 13:56:30 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-25 14:48:50 +0000
commit613c61abb44e49236a893376764eb21702c0ef32 (patch)
tree031ba19e912245a263f14cecd3c12db3043284c1 /terminal.c
parentci (sr.ht): alpine no longer allows pip installing to the system installation (diff)
scaling: always round the scaling factor when converting to int
* In all calls to wl_subsurface_set_position() * (wp_viewport_set_destination() already does this) * Whenever we use the scale to calculate margins (search box, scrollback indicator etc) * Since the scaling factor is stored as a float (and not a double), use roundf() instead of round()
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/terminal.c b/terminal.c
index 41dc3305..5736400b 100644
--- a/terminal.c
+++ b/terminal.c
@@ -784,8 +784,8 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4],
/* Use force, since cell-width/height may have changed */
render_resize_force(
term,
- round(term->width / term->scale),
- round(term->height / term->scale));
+ (int)roundf(term->width / term->scale),
+ (int)roundf(term->height / term->scale));
}
return true;
}
@@ -825,7 +825,7 @@ get_font_dpi(const struct terminal *term)
? tll_back(win->on_outputs)
: &tll_front(term->wl->monitors);
- if (wayl_fractional_scaling(term->wl))
+ if (term_fractional_scaling(term))
return mon->dpi.physical;
else
return mon->dpi.scaled;
@@ -880,12 +880,12 @@ int
term_pt_or_px_as_pixels(const struct terminal *term,
const struct pt_or_px *pt_or_px)
{
- double scale = !term->font_is_sized_by_dpi ? term->scale : 1.;
- double dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.;
+ float scale = !term->font_is_sized_by_dpi ? term->scale : 1.;
+ float dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.;
return pt_or_px->px == 0
- ? round(pt_or_px->pt * scale * dpi / 72)
- : pt_or_px->px * scale;
+ ? (int)roundf(pt_or_px->pt * scale * dpi / 72)
+ : (int)roundf(pt_or_px->px * scale);
}
struct font_load_data {
@@ -932,7 +932,7 @@ reload_fonts(struct terminal *term, bool resize_grid)
if (use_px_size)
snprintf(size, sizeof(size), ":pixelsize=%d",
- (int)round(term->font_sizes[i][j].px_size * scale));
+ (int)roundf(term->font_sizes[i][j].px_size * scale));
else
snprintf(size, sizeof(size), ":size=%.2f",
term->font_sizes[i][j].pt_size * scale);
@@ -2078,6 +2078,16 @@ term_font_size_reset(struct terminal *term)
}
bool
+term_fractional_scaling(const struct terminal *term)
+{
+#if defined(HAVE_FRACTIONAL_SCALE)
+ return term->wl->fractional_scale_manager != NULL && term->window->scale > 0.;
+#else
+ return false;
+#endif
+}
+
+bool
term_update_scale(struct terminal *term)
{
const struct wl_window *win = term->window;
@@ -2093,7 +2103,7 @@ term_update_scale(struct terminal *term)
* - if there aren’t any outputs available, use 1.0
*/
const float new_scale =
- (wayl_fractional_scaling(term->wl) && win->scale > 0.
+ (term_fractional_scaling(term)
? win->scale
: (tll_length(win->on_outputs) > 0
? tll_back(win->on_outputs)->scale