aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-14 14:10:03 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-14 14:10:03 +0000
commit3e5a9aa904ddd6ba78e1e319426859a0c2e78ab4 (patch)
tree376bada3d107fc60ab34b6a83e1365884230d1fd
parentinput: kitty: return the result of term_to_slave() (diff)
parentwayland: add wl_output.name() and wl_output.description() (diff)
Merge branch 'wl-output-name-description'
-rw-r--r--wayland.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/wayland.c b/wayland.c
index dd313813..61e2dfdf 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;
}
@@ -446,11 +452,38 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor)
output_update_ppi(mon);
}
+#if defined(WL_OUTPUT_NAME_SINCE_VERSION)
+static void
+output_name(void *data, struct wl_output *wl_output, const char *name)
+{
+ struct monitor *mon = data;
+ free(mon->name);
+ mon->name = name != NULL ? xstrdup(name) : NULL;
+}
+#endif
+
+#if defined(WL_OUTPUT_DESCRIPTION_SINCE_VERSION)
+static void
+output_description(void *data, struct wl_output *wl_output,
+ const char *description)
+{
+ struct monitor *mon = data;
+ free(mon->description);
+ mon->description = description != NULL ? xstrdup(description) : NULL;
+}
+#endif
+
static const struct wl_output_listener output_listener = {
.geometry = &output_geometry,
.mode = &output_mode,
.done = &output_done,
.scale = &output_scale,
+#if defined(WL_OUTPUT_NAME_SINCE_VERSION)
+ .name = &output_name,
+#endif
+#if defined(WL_OUTPUT_DESCRIPTION_SINCE_VERSION)
+ .description = &output_description,
+#endif
};
static void
@@ -964,7 +997,7 @@ handle_global(void *data, struct wl_registry *registry,
return;
struct wl_output *output = wl_registry_bind(
- wayl->registry, name, &wl_output_interface, min(version, 3));
+ wayl->registry, name, &wl_output_interface, min(version, 4));
tll_push_back(
wayl->monitors,