aboutsummaryrefslogtreecommitdiff
path: root/wayland.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-07-29 07:10:56 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-07-29 07:10:56 +0000
commit05131a9b0c38ca973623c78cc266546b9a6de360 (patch)
treedcf2250bc0a918bdd7189ee5783147e0559112fb /wayland.c
parentwayland: don't try to use a non-existing viewporter interface (diff)
parentchangelog: CSDs with fractional scaling (diff)
Merge branch 'csd-fractional-scaling'
Closes #1441
Diffstat (limited to 'wayland.c')
-rw-r--r--wayland.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/wayland.c b/wayland.c
index 9a6609f4..c338bef8 100644
--- a/wayland.c
+++ b/wayland.c
@@ -2000,21 +2000,35 @@ wayl_roundtrip(struct wayland *wayl)
wayl_flush(wayl);
}
-void
-wayl_surface_scale_explicit_width_height(
+static void
+surface_scale_explicit_width_height(
const struct wl_window *win, const struct wayl_surface *surf,
- int width, int height, float scale)
+ int width, int height, float scale, bool verify)
{
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);
+ if (verify) {
+ if ((int)roundf(scale * (int)roundf(width / scale)) != width) {
+ BUG("width=%d is not valid with scaling factor %.2f (%d != %d)",
+ width, scale,
+ (int)roundf(scale * (int)roundf(width / scale)),
+ width);
+ }
+
+ if ((int)roundf(scale * (int)roundf(height / scale)) != height) {
+ BUG("height=%d is not valid with scaling factor %.2f (%d != %d)",
+ height, scale,
+ (int)roundf(scale * (int)roundf(height / scale)),
+ height);
+ }
+ }
+
wl_surface_set_buffer_scale(surf->surf, 1);
wp_viewport_set_destination(
- surf->viewport,
- (int32_t)roundf((float)width / scale),
- (int32_t)roundf((float)height / scale));
+ surf->viewport, roundf(width / scale), roundf(height / scale));
#else
BUG("wayl_fraction_scaling() returned true, "
"but fractional scaling was not available at compile time");
@@ -2034,11 +2048,19 @@ wayl_surface_scale_explicit_width_height(
}
void
+wayl_surface_scale_explicit_width_height(
+ const struct wl_window *win, const struct wayl_surface *surf,
+ int width, int height, float scale)
+{
+ surface_scale_explicit_width_height(win, surf, width, height, scale, false);
+}
+
+void
wayl_surface_scale(const struct wl_window *win, const struct wayl_surface *surf,
const struct buffer *buf, float scale)
{
- wayl_surface_scale_explicit_width_height(
- win, surf, buf->width, buf->height, scale);
+ surface_scale_explicit_width_height(
+ win, surf, buf->width, buf->height, scale, true);
}
void