From bda9c359af714cc465ef40bc9649b845ade80b7a Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 7 Nov 2018 10:13:24 +0100 Subject: [PATCH] wayland/output: Rotate physical dimensions as well For Wayland outputs, we do not expose the actual transformation because mutter does not support wl_surface.set_buffer_transform yet, instead we swap the logical width and height when the output is rotated. However, a client wishing to use the physical size would get confused, so if the output is rotated, rotate the physical dimensions as well for consistency. Closes: https://gitlab.gnome.org/GNOME/mutter/issues/369 --- src/wayland/meta-wayland-outputs.c | 38 ++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/wayland/meta-wayland-outputs.c b/src/wayland/meta-wayland-outputs.c index e1e72814a..cb393ddf5 100644 --- a/src/wayland/meta-wayland-outputs.c +++ b/src/wayland/meta-wayland-outputs.c @@ -131,6 +131,39 @@ calculate_wayland_output_scale (MetaLogicalMonitor *logical_monitor) return ceilf (scale); } +static void +get_rotated_physical_dimensions (MetaMonitor *monitor, + int *width_mm, + int *height_mm) +{ + int monitor_width_mm, monitor_height_mm; + MetaLogicalMonitor *logical_monitor; + + meta_monitor_get_physical_dimensions (monitor, + &monitor_width_mm, + &monitor_height_mm); + logical_monitor = meta_monitor_get_logical_monitor (monitor); + + if (meta_monitor_transform_is_rotated (logical_monitor->transform)) + { + *width_mm = monitor_height_mm; + *height_mm = monitor_width_mm; + } + else + { + *width_mm = monitor_width_mm; + *height_mm = monitor_height_mm; + } +} + +static gboolean +is_different_rotation (MetaLogicalMonitor *a, + MetaLogicalMonitor *b) +{ + return (meta_monitor_transform_is_rotated (a->transform) != + meta_monitor_transform_is_rotated (b->transform)); +} + static void send_output_events (struct wl_resource *resource, MetaWaylandOutput *wayland_output, @@ -163,7 +196,8 @@ send_output_events (struct wl_resource *resource, if (need_all_events || old_logical_monitor->rect.x != logical_monitor->rect.x || - old_logical_monitor->rect.y != logical_monitor->rect.y) + old_logical_monitor->rect.y != logical_monitor->rect.y || + is_different_rotation (old_logical_monitor, logical_monitor)) { int width_mm, height_mm; const char *vendor; @@ -178,7 +212,7 @@ send_output_events (struct wl_resource *resource, * Arbitrarily use whatever monitor is the first in the logical monitor * and use that for these details. */ - meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); + get_rotated_physical_dimensions (monitor, &width_mm, &height_mm); vendor = meta_monitor_get_vendor (monitor); product = meta_monitor_get_product (monitor);