From 446858b12ec198df62154cf50e6e3d9aebd46b2b Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Fri, 22 Sep 2023 11:10:10 +0100 Subject: [PATCH 1/2] Rewrite broken scaling conversion --- .../frontend_xwayland/xwayland_surface.cpp | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/server/frontend_xwayland/xwayland_surface.cpp b/src/server/frontend_xwayland/xwayland_surface.cpp index f332b6130ec..536e80af450 100644 --- a/src/server/frontend_xwayland/xwayland_surface.cpp +++ b/src/server/frontend_xwayland/xwayland_surface.cpp @@ -1221,20 +1221,25 @@ void mf::XWaylandSurface::prep_surface_spec(ProofOfMutexLock const&, msh::Surfac } } -#define SCALE_SIZE(type, prop) \ - if (mods.prop) \ - { \ - mods.prop = std::max(geom::type{1}, mods.prop.value() * inv_scale); \ - } + auto scale_size_clamped = [inv_scale](auto& optional_prop) + { + if (optional_prop) + { + using ValueType = std::remove_reference::type; + using UnderlyingType = ValueType::ValueType; + auto constexpr raw_max = std::numeric_limits::max(); - SCALE_SIZE(Width, width); - SCALE_SIZE(Height, height); - SCALE_SIZE(Width, min_width); - SCALE_SIZE(Height, min_height); - SCALE_SIZE(Width, max_width); - SCALE_SIZE(Height, max_height); + double const double_value = optional_prop.value().as_value() * inv_scale; + optional_prop = std::max(ValueType{1}, ValueType{std::min(double_value, double{raw_max})}); + } + }; -#undef SCALE_SIZE + scale_size_clamped(mods.width); + scale_size_clamped(mods.height); + scale_size_clamped(mods.min_width); + scale_size_clamped(mods.min_height); + scale_size_clamped(mods.max_width); + scale_size_clamped(mods.max_height); // NOTE: exclusive rect not checked because it is not used by XWayland surfaces // NOTE: aux rect related properties not checks because they are only set in this method From 2862dfc03196bd6612545214994bff2ef1a59e92 Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Fri, 22 Sep 2023 12:34:44 +0100 Subject: [PATCH 2/2] Scatter `typename` liberally (like in the good old days) --- src/server/frontend_xwayland/xwayland_surface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/frontend_xwayland/xwayland_surface.cpp b/src/server/frontend_xwayland/xwayland_surface.cpp index 536e80af450..e211e59348b 100644 --- a/src/server/frontend_xwayland/xwayland_surface.cpp +++ b/src/server/frontend_xwayland/xwayland_surface.cpp @@ -1225,8 +1225,8 @@ void mf::XWaylandSurface::prep_surface_spec(ProofOfMutexLock const&, msh::Surfac { if (optional_prop) { - using ValueType = std::remove_reference::type; - using UnderlyingType = ValueType::ValueType; + using ValueType = typename std::remove_reference::type; + using UnderlyingType = typename ValueType::ValueType; auto constexpr raw_max = std::numeric_limits::max(); double const double_value = optional_prop.value().as_value() * inv_scale;