aboutsummaryrefslogtreecommitdiff
path: root/wayland.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 /wayland.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 'wayland.c')
-rw-r--r--wayland.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/wayland.c b/wayland.c
index a297c76a..acf078aa 100644
--- a/wayland.c
+++ b/wayland.c
@@ -57,7 +57,7 @@ csd_reload_font(struct wl_window *win, float old_scale)
char pixelsize[32];
snprintf(pixelsize, sizeof(pixelsize), "pixelsize=%u",
- (int)round(conf->csd.title_height * scale * 1 / 2));
+ (int)roundf(conf->csd.title_height * scale * 1 / 2));
LOG_DBG("loading CSD font \"%s:%s\" (old-scale=%.2f, scale=%.2f)",
patterns[0], pixelsize, old_scale, scale);
@@ -416,7 +416,7 @@ update_term_for_output_change(struct terminal *term)
* 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));
+ render_resize_force(term, (int)roundf(logical_width), (int)roundf(logical_height));
}
else if (scale_updated) {
@@ -425,7 +425,7 @@ update_term_for_output_change(struct terminal *term)
* been updated, even though the window logical dimensions
* haven’t changed.
*/
- render_resize(term, round(logical_width), round(logical_height));
+ render_resize(term, (int)roundf(logical_width), (int)roundf(logical_height));
}
}
@@ -1528,7 +1528,7 @@ wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager,
LOG_INFO(
"%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d, DPI=%.2f/%.2f (physical/scaled)",
it->item.name, it->item.dim.px_real.width, it->item.dim.px_real.height,
- it->item.x, it->item.y, (int)round(it->item.refresh),
+ it->item.x, it->item.y, (int)roundf(it->item.refresh),
it->item.model != NULL ? it->item.model : it->item.description,
it->item.inch, it->item.scale,
it->item.dpi.physical, it->item.dpi.scaled);
@@ -1996,24 +1996,12 @@ wayl_roundtrip(struct wayland *wayl)
wayl_flush(wayl);
}
-
-bool
-wayl_fractional_scaling(const struct wayland *wayl)
-{
-#if defined(HAVE_FRACTIONAL_SCALE)
- return wayl->fractional_scale_manager != NULL;
-#else
- return false;
-#endif
-}
-
void
wayl_surface_scale_explicit_width_height(
const struct wl_window *win, const struct wayl_surface *surf,
int width, int height, float scale)
{
-
- if (wayl_fractional_scaling(win->term->wl) && win->scale > 0.) {
+ if (term_fractional_scaling(win->term)) {
#if defined(HAVE_FRACTIONAL_SCALE)
LOG_DBG("scaling by a factor of %.2f using fractional scaling "
"(width=%d, height=%d) ", scale, width, height);
@@ -2021,8 +2009,8 @@ wayl_surface_scale_explicit_width_height(
wl_surface_set_buffer_scale(surf->surf, 1);
wp_viewport_set_destination(
surf->viewport,
- round((float)width / scale),
- round((float)height / scale));
+ (int32_t)roundf((float)width / scale),
+ (int32_t)roundf((float)height / scale));
#else
BUG("wayl_fraction_scaling() returned true, "
"but fractional scaling was not available at compile time");
@@ -2031,9 +2019,9 @@ wayl_surface_scale_explicit_width_height(
LOG_DBG("scaling by a factor of %.2f using legacy mode "
"(width=%d, height=%d)", scale, width, height);
- xassert(scale == floor(scale));
+ xassert(scale == floorf(scale));
- const int iscale = (int)scale;
+ const int iscale = (int)floorf(scale);
xassert(width % iscale == 0);
xassert(height % iscale == 0);