Skip to content

Commit

Permalink
Merge pull request #3050 from MirServer/fix_clamping
Browse files Browse the repository at this point in the history
[Xwayland] Fix broken rescaling
  • Loading branch information
AlanGriffiths authored Sep 22, 2023
2 parents 23f7023 + 2862dfc commit ced58f3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/server/frontend_xwayland/xwayland_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = typename std::remove_reference<decltype(optional_prop.value())>::type;
using UnderlyingType = typename ValueType::ValueType;
auto constexpr raw_max = std::numeric_limits<UnderlyingType>::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
Expand Down

0 comments on commit ced58f3

Please sign in to comment.