aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-13 18:15:17 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-13 18:15:17 +0000
commit97174913e09db464d3020c50cbf223d2fe823d3d (patch)
treecb33fde7043746f2b408f4b7d39cab0663eda6de
parentinput: kitty: return the result of term_to_slave() (diff)
wayland: estimate scaled (logical) width/height, if not provided
This makes us slightly more resilient against a missing XDG output interface. We use the “real” (the physical) dimensions, combined with the scaling factor, to estimate the logical dimensions. This works out correctly with non-fractional scaling, but not otherwise.
-rw-r--r--wayland.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/wayland.c b/wayland.c
index dd313813..85f00b98 100644
--- a/wayland.c
+++ b/wayland.c
@@ -385,13 +385,19 @@ output_update_ppi(struct monitor *mon)
break;
}
- mon->ppi.scaled.x = mon->dim.px_scaled.width / x_inches;
- mon->ppi.scaled.y = mon->dim.px_scaled.height / y_inches;
+ int scaled_width = mon->dim.px_scaled.width;
+ int scaled_height = mon->dim.px_scaled.height;
- float px_diag = sqrt(
- pow(mon->dim.px_scaled.width, 2) +
- pow(mon->dim.px_scaled.height, 2));
+ if (scaled_width == 0 && scaled_height == 0 && mon->scale > 0) {
+ /* Estimate scaled width/height if none has been provided */
+ scaled_width = mon->dim.px_real.width / mon->scale;
+ scaled_height = mon->dim.px_real.height / mon->scale;
+ }
+
+ mon->ppi.scaled.x = scaled_width / x_inches;
+ mon->ppi.scaled.y = scaled_height / y_inches;
+ float px_diag = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
mon->dpi = px_diag / mon->inch * mon->scale;
}