From adbf7c8663cfbc91fca78d3504fa8f73ce4bd23a Mon Sep 17 00:00:00 2001 From: Stanislav Senotrusov Date: Sat, 13 Sep 2025 01:11:30 +0200 Subject: [PATCH] input: handle tablet active area scaling when axes swap due to rotation (#11661) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some tablet rotation modes (90°, 270°, and flipped variants) swap the X and Y axes. This change adjusts the effective physical size based on axis orientation to ensure tablet active area coordinates are normalized correctly. --- src/managers/input/InputManager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index fa6acf15..ea164842 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1787,8 +1787,13 @@ void CInputManager::setTabletConfigs() { const auto ACTIVE_AREA_SIZE = g_pConfigManager->getDeviceVec(NAME, "active_area_size", "input:tablet:active_area_size"); const auto ACTIVE_AREA_POS = g_pConfigManager->getDeviceVec(NAME, "active_area_position", "input:tablet:active_area_position"); if (ACTIVE_AREA_SIZE.x != 0 || ACTIVE_AREA_SIZE.y != 0) { - t->m_activeArea = CBox{ACTIVE_AREA_POS.x / t->aq()->physicalSize.x, ACTIVE_AREA_POS.y / t->aq()->physicalSize.y, - (ACTIVE_AREA_POS.x + ACTIVE_AREA_SIZE.x) / t->aq()->physicalSize.x, (ACTIVE_AREA_POS.y + ACTIVE_AREA_SIZE.y) / t->aq()->physicalSize.y}; + // Rotations with an odd index (90 and 270 degrees, and their flipped variants) swap the X and Y axes. + // Use swapped dimensions when the axes are rotated, otherwise keep the original ones. + const Vector2D effectivePhysicalSize = (ROTATION % 2) ? Vector2D{t->aq()->physicalSize.y, t->aq()->physicalSize.x} : t->aq()->physicalSize; + + // Scale the active area coordinates into normalized space (0–1) using the effective dimensions. + t->m_activeArea = CBox{ACTIVE_AREA_POS.x / effectivePhysicalSize.x, ACTIVE_AREA_POS.y / effectivePhysicalSize.y, + (ACTIVE_AREA_POS.x + ACTIVE_AREA_SIZE.x) / effectivePhysicalSize.x, (ACTIVE_AREA_POS.y + ACTIVE_AREA_SIZE.y) / effectivePhysicalSize.y}; } } }