From b21edb1a9753ba8c236302c1d6dba9ea2418b1d3 Mon Sep 17 00:00:00 2001 From: "Khalid J." Date: Thu, 6 Mar 2025 14:24:36 +0300 Subject: [PATCH] input: fix touch calibration matrix overriding make the default behavior non-overriding to avoid overriding user-set values elswehere. --- src/config/ConfigManager.cpp | 4 ++-- src/managers/input/InputManager.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f0383d50b..6f879820c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -606,7 +606,7 @@ CConfigManager::CConfigManager() { registerConfigVar("input:touchpad:scroll_factor", {1.f}); registerConfigVar("input:touchpad:flip_x", Hyprlang::INT{0}); registerConfigVar("input:touchpad:flip_y", Hyprlang::INT{0}); - registerConfigVar("input:touchdevice:transform", Hyprlang::INT{0}); + registerConfigVar("input:touchdevice:transform", Hyprlang::INT{-1}); registerConfigVar("input:touchdevice:output", {"[[Auto]]"}); registerConfigVar("input:touchdevice:enabled", Hyprlang::INT{1}); registerConfigVar("input:tablet:transform", Hyprlang::INT{0}); @@ -725,7 +725,7 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "scroll_button", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "scroll_button_lock", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "scroll_points", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "transform", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "transform", Hyprlang::INT{-1}); m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY}); m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index eb72c7b4b..04f2ae3e9 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1578,10 +1578,13 @@ void CInputManager::setTouchDeviceConfigs(SP dev) { if (libinput_device_config_send_events_get_mode(LIBINPUTDEV) != mode) libinput_device_config_send_events_set_mode(LIBINPUTDEV, mode); - const int ROTATION = std::clamp(g_pConfigManager->getDeviceInt(PTOUCHDEV->hlName, "transform", "input:touchdevice:transform"), 0, 7); - Debug::log(LOG, "Setting calibration matrix for device {}", PTOUCHDEV->hlName); - if (libinput_device_config_calibration_has_matrix(LIBINPUTDEV)) - libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + if (libinput_device_config_calibration_has_matrix(LIBINPUTDEV)) { + Debug::log(LOG, "Setting calibration matrix for device {}", PTOUCHDEV->hlName); + // default value of transform being -1 means it's unset. + const int ROTATION = std::clamp(g_pConfigManager->getDeviceInt(PTOUCHDEV->hlName, "transform", "input:touchdevice:transform"), -1, 7); + if (ROTATION > -1) + libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + } auto output = g_pConfigManager->getDeviceString(PTOUCHDEV->hlName, "output", "input:touchdevice:output"); bool bound = !output.empty() && output != STRVAL_EMPTY; @@ -1623,9 +1626,10 @@ void CInputManager::setTabletConfigs() { const auto RELINPUT = g_pConfigManager->getDeviceInt(NAME, "relative_input", "input:tablet:relative_input"); t->relativeInput = RELINPUT; - const int ROTATION = std::clamp(g_pConfigManager->getDeviceInt(NAME, "transform", "input:tablet:transform"), 0, 7); + const int ROTATION = std::clamp(g_pConfigManager->getDeviceInt(NAME, "transform", "input:tablet:transform"), -1, 7); Debug::log(LOG, "Setting calibration matrix for device {}", NAME); - libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + if (ROTATION > -1) + libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); if (g_pConfigManager->getDeviceInt(NAME, "left_handed", "input:tablet:left_handed") == 0) libinput_device_config_left_handed_set(LIBINPUTDEV, 0);