aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--terminal.c55
-rw-r--r--wayland.c46
-rw-r--r--wayland.h5
3 files changed, 55 insertions, 51 deletions
diff --git a/terminal.c b/terminal.c
index e15e647e..a557d632 100644
--- a/terminal.c
+++ b/terminal.c
@@ -796,41 +796,34 @@ get_font_dpi(const struct terminal *term)
* Conceptually, we use the physical monitor specs to calculate
* the DPI, and we ignore the output's scaling factor.
*
- * However, to deal with fractional scaling, where we're told to
- * render at e.g. 2x, but are then downscaled by the compositor to
- * e.g. 1.25, we use the scaled DPI value multiplied by the scale
- * factor instead.
+ * However, to deal with legacy fractional scaling, where we're
+ * told to render at e.g. 2x, but are then downscaled by the
+ * compositor to e.g. 1.25, we use the scaled DPI value multiplied
+ * by the scale factor instead.
*
* For integral scaling factors the resulting DPI is the same as
* if we had used the physical DPI.
*
- * For fractional scaling factors we'll get a DPI *larger* than
- * the physical DPI, that ends up being right when later
+ * For legacy fractional scaling factors we'll get a DPI *larger*
+ * than the physical DPI, that ends up being right when later
* downscaled by the compositor.
+ *
+ * With the newer fractional-scale-v1 protocol, we use the
+ * monitor’s real DPI, since we scale everything to the correct
+ * scaling factor (no downscaling done by the compositor).
*/
- /* Use highest DPI from outputs we're mapped on */
- double dpi = 0.0;
- xassert(term->window != NULL);
- tll_foreach(term->window->on_outputs, it) {
- if (it->item->dpi > dpi)
- dpi = it->item->dpi;
- }
+ xassert(tll_length(term->wl->monitors) > 0);
- /* If we're not mapped, use DPI from first monitor. Hopefully this is where we'll get mapped later... */
- if (dpi == 0.) {
- tll_foreach(term->wl->monitors, it) {
- dpi = it->item.dpi;
- break;
- }
- }
+ const struct wl_window *win = term->window;
+ const struct monitor *mon = tll_length(win->on_outputs) > 0
+ ? tll_back(win->on_outputs)
+ : &tll_front(term->wl->monitors);
- if (dpi == 0) {
- /* No monitors? */
- dpi = 96.;
- }
-
- return dpi;
+ if (wayl_fractional_scaling(term->wl))
+ return mon->dpi.physical;
+ else
+ return mon->dpi.scaled;
}
static enum fcft_subpixel
@@ -1285,11 +1278,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
reaper_add(term->reaper, term->slave, &fdm_client_terminated, term);
/* Guess scale; we're not mapped yet, so we don't know on which
- * output we'll be. Pick highest scale we find for now */
- tll_foreach(term->wl->monitors, it) {
- if (it->item.scale > term->scale)
- term->scale = it->item.scale;
- }
+ * output we'll be. Use scaling factor from first monitor */
+ xassert(tll_length(term->wl->monitors) > 0);
+ term->scale = tll_front(term->wl->monitors).scale;
memcpy(term->colors.table, term->conf->colors.table, sizeof(term->colors.table));
@@ -2096,7 +2087,7 @@ term_font_dpi_changed(struct terminal *term, float old_scale)
: old_scale != term->scale);
if (need_font_reload) {
- LOG_DBG("DPI/scale change: DPI-awareness=%s, "
+ LOG_DBG("DPI/scale change: DPI-aware=%s, "
"DPI: %.2f -> %.2f, scale: %.2f -> %.2f, "
"sizing font based on monitor's %s",
term->conf->dpi_aware ? "yes" : "no",
diff --git a/wayland.c b/wayland.c
index f6ded585..c4f9e402 100644
--- a/wayland.c
+++ b/wayland.c
@@ -435,6 +435,9 @@ output_update_ppi(struct monitor *mon)
double x_inches = mon->dim.mm.width * 0.03937008;
double y_inches = mon->dim.mm.height * 0.03937008;
+ const int width = mon->dim.px_real.width;
+ const int height = mon->dim.px_real.height;
+
mon->ppi.real.x = mon->dim.px_real.width / x_inches;
mon->ppi.real.y = mon->dim.px_real.height / y_inches;
@@ -457,27 +460,36 @@ output_update_ppi(struct monitor *mon)
break;
}
- int scaled_width = mon->dim.px_scaled.width;
- int scaled_height = mon->dim.px_scaled.height;
-
- 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;
- }
+ const int scaled_width = mon->dim.px_scaled.width;
+ const int scaled_height = mon->dim.px_scaled.height;
mon->ppi.scaled.x = scaled_width / x_inches;
mon->ppi.scaled.y = scaled_height / y_inches;
- double px_diag = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
- mon->dpi = px_diag / mon->inch * mon->scale;
+ const double px_diag_physical = sqrt(pow(width, 2) + pow(height, 2));
+ mon->dpi.physical = width == 0 && height == 0
+ ? 96.
+ : px_diag_physical / mon->inch;
+
+ const double px_diag_scaled = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
+ mon->dpi.scaled = scaled_width == 0 && scaled_height == 0
+ ? 96.
+ : px_diag_scaled / mon->inch * mon->scale;
+
+ if (mon->dpi.physical > 1000) {
+ if (mon->name != NULL) {
+ LOG_WARN("%s: DPI=%f (physical) is unreasonable, using 96 instead",
+ mon->name, mon->dpi.physical);
+ }
+ mon->dpi.physical = 96;
+ }
- if (mon->dpi > 1000) {
+ if (mon->dpi.scaled > 1000) {
if (mon->name != NULL) {
- LOG_WARN("%s: DPI=%f is unreasonable, using 96 instead",
- mon->name, mon->dpi);
+ LOG_WARN("%s: DPI=%f (logical) is unreasonable, using 96 instead",
+ mon->name, mon->dpi.scaled);
}
- mon->dpi = 96;
+ mon->dpi.scaled = 96;
}
}
@@ -1487,14 +1499,12 @@ wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager,
tll_foreach(wayl->monitors, it) {
LOG_INFO(
- "%s: %dx%d+%dx%d@%dHz %s %.2f\" scale=%d PPI=%dx%d (physical) PPI=%dx%d (logical), DPI=%.2f",
+ "%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.model != NULL ? it->item.model : it->item.description,
it->item.inch, it->item.scale,
- it->item.ppi.real.x, it->item.ppi.real.y,
- it->item.ppi.scaled.x, it->item.ppi.scaled.y,
- it->item.dpi);
+ it->item.dpi.physical, it->item.dpi.scaled);
}
wayl->fd = wl_display_get_fd(wayl->display);
diff --git a/wayland.h b/wayland.h
index 9e581b20..275338a8 100644
--- a/wayland.h
+++ b/wayland.h
@@ -315,7 +315,10 @@ struct monitor {
} scaled;
} ppi;
- float dpi;
+ struct {
+ float scaled;
+ float physical;
+ } dpi;
int scale;
float refresh;