From 32ae0c51f006cbcf41cfae3cff4d3f63ba91cccd Mon Sep 17 00:00:00 2001 From: Histausse Date: Fri, 7 Oct 2022 16:03:52 +0200 Subject: [PATCH 1/4] Add input:touchdevice:td_rotation config Add support for touch device roation. The rotation is set globally with `input:touchdevice:td_rotation config` and by device with `td_rotation` in a device block. --- src/config/ConfigManager.cpp | 4 +++ src/debug/HyprCtl.cpp | 1 + src/helpers/WLClasses.hpp | 2 ++ src/managers/input/InputManager.cpp | 51 +++++++++++++++++++++++++++++ src/managers/input/InputManager.hpp | 1 + 5 files changed, 59 insertions(+) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1d8dbd2d..7679c3a4 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -147,6 +147,7 @@ void CConfigManager::setDefaultVars() { configValues["input:touchpad:tap-to-click"].intValue = 1; configValues["input:touchpad:drag_lock"].intValue = 0; configValues["input:touchpad:scroll_factor"].floatValue = 1.f; + configValues["input:touchdevice:td_rotation"].intValue = 0; configValues["binds:pass_mouse_when_bound"].intValue = 0; configValues["binds:scroll_event_delay"].intValue = 300; @@ -187,6 +188,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) { cfgValues["drag_lock"].intValue = 0; cfgValues["left_handed"].intValue = 0; cfgValues["scroll_method"].strValue = STRVAL_EMPTY; + cfgValues["td_rotation"].intValue = 0; } void CConfigManager::setDefaultAnimationVars() { @@ -1139,6 +1141,7 @@ void CConfigManager::loadConfigLoadVars() { if (!isFirstLaunch) { g_pInputManager->setKeyboardLayout(); g_pInputManager->setPointerConfigs(); + g_pInputManager->setTouchDeviceConfigs(); } // Calculate the internal vars @@ -1424,6 +1427,7 @@ void CConfigManager::dispatchExecOnce() { // set input, fixes some certain issues g_pInputManager->setKeyboardLayout(); g_pInputManager->setPointerConfigs(); + g_pInputManager->setTouchDeviceConfigs(); // set ws names again for (auto& ws : g_pCompositor->m_vWorkspaces) { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index c602ab31..8a4a27ab 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -562,6 +562,7 @@ std::string dispatchKeyword(std::string in) { if (COMMAND.contains("input") || COMMAND.contains("device:")) { g_pInputManager->setKeyboardLayout(); // update kb layout g_pInputManager->setPointerConfigs(); // update mouse cfgs + g_pInputManager->setTouchDeviceConfigs(); // update touch device cfgs } if (COMMAND.contains("general:layout")) diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index e66f1b52..a6751cd9 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -326,6 +326,8 @@ struct SIMEPopup { struct STouchDevice { wlr_input_device* pWlrDevice = nullptr; + std::string name = ""; + DYNLISTENER(destroy); bool operator==(const STouchDevice& other) { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 6060a9cf..f024dc94 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1027,6 +1027,13 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) { const auto PNEWDEV = &m_lTouchDevices.emplace_back(); PNEWDEV->pWlrDevice = pDevice; + try { + PNEWDEV->name = std::string(pDevice->name); + } catch(std::exception& e) { + Debug::log(ERR, "Touch Device had no name???"); // logic error + } + + setTouchDeviceConfigs(); wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, pDevice); Debug::log(LOG, "New touch device added at %x", PNEWDEV); @@ -1036,6 +1043,50 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) { }, PNEWDEV, "TouchDevice"); } +void CInputManager::setTouchDeviceConfigs() { + // The rotation matrices. + // The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix` + const float MATRICES[4][6] = { + { + 1, 0, 0, + 0, 1, 0 + }, + { + 0, -1, 1, + 1, 0, 0 + }, + { + -1, 0, 1, + 0, -1, 1 + }, + { + 0, 1, 0, + -1, 0, 1 + } + }; + const int NB_MATRICES = 4; + for (auto& m : m_lTouchDevices) { + const auto PTOUCHDEV = &m; + + auto devname = PTOUCHDEV->name; + transform(devname.begin(), devname.end(), devname.begin(), ::tolower); + + const auto HASCONFIG = g_pConfigManager->deviceConfigExists(devname); + + if (HASCONFIG) + Debug::log(LOG, "Touch Screen %s has config", devname.c_str()); + else + Debug::log(LOG, "Touch Screen %s has no config", devname.c_str()); + + if (wlr_input_device_is_libinput(m.pWlrDevice)) { + const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(m.pWlrDevice); + + const int ROTATION = ((HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "td_rotation") : g_pConfigManager->getInt("input:touchdevice:td_rotation")) % NB_MATRICES + NB_MATRICES) % NB_MATRICES; + libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + } + } +} + void CInputManager::destroyTouchDevice(STouchDevice* pDevice) { Debug::log(LOG, "Touch device at %x removed", pDevice); diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index a8c83df8..8e94a5d6 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -53,6 +53,7 @@ public: void setKeyboardLayout(); void setPointerConfigs(); + void setTouchDeviceConfigs(); void updateDragIcon(); void updateCapabilities(wlr_input_device*); From 406b2fe6dc5e5911436b9fa030e4be69fd544515 Mon Sep 17 00:00:00 2001 From: Histausse Date: Sat, 8 Oct 2022 19:55:07 +0200 Subject: [PATCH 2/4] Add additionnal matrices and rename config var --- src/config/ConfigManager.cpp | 4 ++-- src/managers/input/InputManager.cpp | 35 ++++++++++++++++++----------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7679c3a4..e38ac19c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -147,7 +147,7 @@ void CConfigManager::setDefaultVars() { configValues["input:touchpad:tap-to-click"].intValue = 1; configValues["input:touchpad:drag_lock"].intValue = 0; configValues["input:touchpad:scroll_factor"].floatValue = 1.f; - configValues["input:touchdevice:td_rotation"].intValue = 0; + configValues["input:touchdevice:transform"].intValue = 0; configValues["binds:pass_mouse_when_bound"].intValue = 0; configValues["binds:scroll_event_delay"].intValue = 300; @@ -188,7 +188,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) { cfgValues["drag_lock"].intValue = 0; cfgValues["left_handed"].intValue = 0; cfgValues["scroll_method"].strValue = STRVAL_EMPTY; - cfgValues["td_rotation"].intValue = 0; + cfgValues["transform"].intValue = 0; } void CConfigManager::setDefaultAnimationVars() { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index f024dc94..bdfa06de 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1044,27 +1044,41 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) { } void CInputManager::setTouchDeviceConfigs() { - // The rotation matrices. // The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix` - const float MATRICES[4][6] = { - { + const float MATRICES[8][6] = { + { // normal 1, 0, 0, 0, 1, 0 }, - { + { // rotation 90° 0, -1, 1, 1, 0, 0 }, - { + { // rotation 180° -1, 0, 1, 0, -1, 1 }, - { + { // rotation 270° 0, 1, 0, -1, 0, 1 + }, + { // flipped + -1, 0, 1, + 0, 1, 0 + }, + { // flipped + rotation 90° + 0, 1, 0, + 1, 0, 0 + }, + { // flipped + rotation 180° + 1, 0, 0, + 0, -1, 1 + }, + { // flipped + rotation 270° + 0, -1, 1, + -1, 0, 1 } }; - const int NB_MATRICES = 4; for (auto& m : m_lTouchDevices) { const auto PTOUCHDEV = &m; @@ -1073,15 +1087,10 @@ void CInputManager::setTouchDeviceConfigs() { const auto HASCONFIG = g_pConfigManager->deviceConfigExists(devname); - if (HASCONFIG) - Debug::log(LOG, "Touch Screen %s has config", devname.c_str()); - else - Debug::log(LOG, "Touch Screen %s has no config", devname.c_str()); - if (wlr_input_device_is_libinput(m.pWlrDevice)) { const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(m.pWlrDevice); - const int ROTATION = ((HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "td_rotation") : g_pConfigManager->getInt("input:touchdevice:td_rotation")) % NB_MATRICES + NB_MATRICES) % NB_MATRICES; + const int ROTATION = std::clamp(HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "transform") : g_pConfigManager->getInt("input:touchdevice:transform"), 0, 7); libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); } } From 6287f2b71b5b3bd97688db2563a9255c2b98533e Mon Sep 17 00:00:00 2001 From: Histausse Date: Mon, 10 Oct 2022 12:29:03 +0200 Subject: [PATCH 3/4] use static for transformation matrices --- src/managers/input/InputManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index bdfa06de..e78ddda2 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1045,7 +1045,7 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) { void CInputManager::setTouchDeviceConfigs() { // The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix` - const float MATRICES[8][6] = { + static const float MATRICES[8][6] = { { // normal 1, 0, 0, 0, 1, 0 From df9409b8a2bef8936b3e3aa86c42cc4fc084dc2b Mon Sep 17 00:00:00 2001 From: vaxerski Date: Fri, 14 Oct 2022 12:23:11 +0100 Subject: [PATCH 4/4] rename transform in DC to touch_transform --- src/config/ConfigManager.cpp | 2 +- src/managers/input/InputManager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index e38ac19c..10840a65 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -188,7 +188,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) { cfgValues["drag_lock"].intValue = 0; cfgValues["left_handed"].intValue = 0; cfgValues["scroll_method"].strValue = STRVAL_EMPTY; - cfgValues["transform"].intValue = 0; + cfgValues["touch_transform"].intValue = 0; } void CConfigManager::setDefaultAnimationVars() { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index e78ddda2..dc85735b 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1090,7 +1090,7 @@ void CInputManager::setTouchDeviceConfigs() { if (wlr_input_device_is_libinput(m.pWlrDevice)) { const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(m.pWlrDevice); - const int ROTATION = std::clamp(HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "transform") : g_pConfigManager->getInt("input:touchdevice:transform"), 0, 7); + const int ROTATION = std::clamp(HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "touch_transform") : g_pConfigManager->getInt("input:touchdevice:transform"), 0, 7); libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); } }