From fd7ea4f27c8a596d1b72101ab4c0eca5b5b60ed5 Mon Sep 17 00:00:00 2001 From: LivingCodeX <31110030+LivingCodeX@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:31:50 +0000 Subject: [PATCH] constraint: Fix xwl cursor locking for scaled monitors (#5587) * Fix xwl cursor locking for scaled monitors * Add null check for window * Replace m_fLastScale with m_fX11SurfaceScaledBy * Improve code style * Improve code style via clang-format --- src/desktop/Constraint.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/desktop/Constraint.cpp b/src/desktop/Constraint.cpp index dfe8d217..428c8745 100644 --- a/src/desktop/Constraint.cpp +++ b/src/desktop/Constraint.cpp @@ -1,6 +1,7 @@ #include "Constraint.hpp" #include "WLSurface.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" CConstraint::CConstraint(wlr_pointer_constraint_v1* constraint, CWLSurface* owner) : m_pOwner(owner), m_pConstraint(constraint) { RASSERT(!constraint->data, "CConstraint: attempted to duplicate ownership"); @@ -62,8 +63,18 @@ void CConstraint::onCommit() { const auto COMMITTED = m_pConstraint->current.committed; if (COMMITTED & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - m_bHintSet = true; - m_vPositionHint = {m_pConstraint->current.cursor_hint.x, m_pConstraint->current.cursor_hint.y}; + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); + + m_bHintSet = true; + + float scale = 1.f; + const auto PWINDOW = m_pOwner->getWindow(); + if (PWINDOW) { + const auto ISXWL = PWINDOW->m_bIsX11; + scale = ISXWL && *PXWLFORCESCALEZERO ? PWINDOW->m_fX11SurfaceScaledBy : 1.f; + } + + m_vPositionHint = {m_pConstraint->current.cursor_hint.x / scale, m_pConstraint->current.cursor_hint.y / scale}; g_pInputManager->simulateMouseMovement(); }