diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2022-10-14 12:26:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-14 12:26:31 +0100 |
| commit | cee0645fd1e8f84438635483fd17007c077812fe (patch) | |
| tree | b76f8a06c85a8e2c74c8e097ece035b4eaa0f6d0 /src/managers/input/InputManager.cpp | |
| parent | f274a70edf835a64c236a5d59f26e025f508379a (diff) | |
| parent | df9409b8a2bef8936b3e3aa86c42cc4fc084dc2b (diff) | |
Merge pull request #813 from histausse/touch_dev_rotation
Add input:touchdevice:transform config
Diffstat (limited to 'src/managers/input/InputManager.cpp')
| -rw-r--r-- | src/managers/input/InputManager.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 6060a9cf..dc85735b 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,59 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) { }, PNEWDEV, "TouchDevice"); } +void CInputManager::setTouchDeviceConfigs() { + // The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix` + static 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 + } + }; + 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 (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, "touch_transform") : g_pConfigManager->getInt("input:touchdevice:transform"), 0, 7); + libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + } + } +} + void CInputManager::destroyTouchDevice(STouchDevice* pDevice) { Debug::log(LOG, "Touch device at %x removed", pDevice); |
