summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorppenguin <hieronymusv@gmail.com>2023-01-15 20:38:58 +0100
committerGitHub <noreply@github.com>2023-01-15 20:38:58 +0100
commit040e99fd174e46614e9dc37a77bad67b930ac5e9 (patch)
tree690a1cfb82422d9ac9d0924c1e3d6b6baee39161
parentb5b436e01ddb5d5200f55be3deed8f4fade0574c (diff)
Add tablets calibration matrix for dynamic rotation with 2-in1/tablet PC usage (#1319)
-rw-r--r--src/config/ConfigManager.cpp9
-rw-r--r--src/managers/input/InputManager.cpp30
-rw-r--r--src/managers/input/InputManager.hpp20
3 files changed, 37 insertions, 22 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index 99101d5a..8e1eb3ad 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -160,6 +160,8 @@ void CConfigManager::setDefaultVars() {
configValues["input:touchpad:scroll_factor"].floatValue = 1.f;
configValues["input:touchdevice:transform"].intValue = 0;
configValues["input:touchdevice:output"].strValue = STRVAL_EMPTY;
+ configValues["input:tablet:transform"].intValue = 0;
+ configValues["input:tablet:output"].strValue = STRVAL_EMPTY;
configValues["binds:pass_mouse_when_bound"].intValue = 0;
configValues["binds:scroll_event_delay"].intValue = 300;
@@ -1340,7 +1342,12 @@ SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, co
if (foundIt == std::string::npos)
continue;
- if (cv.first == "input:" + val || cv.first == "input:touchpad:" + cv.first || cv.first == "input:touchdevice:" + val) {
+ if (cv.first == "input:" + val
+ || cv.first == "input:touchpad:" + cv.first
+ || cv.first == "input:touchdevice:" + val
+ || cv.first == "input:tablet:" + cv.first
+ || cv.first == "input:tablet:" + val
+ ) {
copy = cv.second;
}
}
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index be148e89..d1f24884 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -1144,23 +1144,6 @@ 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`
- 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;
@@ -1186,11 +1169,16 @@ void CInputManager::setTabletConfigs() {
for (auto& t : m_lTablets) {
const auto HASCONFIG = g_pConfigManager->deviceConfigExists(t.name);
- if (HASCONFIG) {
- const auto OUTPUT = g_pConfigManager->getDeviceString(t.name, "output");
- const auto PMONITOR = g_pCompositor->getMonitorFromString(OUTPUT);
+ if (wlr_input_device_is_libinput(t.wlrDevice)) {
+ const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(t.wlrDevice);
- if (PMONITOR) {
+ const int ROTATION = std::clamp(HASCONFIG ? g_pConfigManager->getDeviceInt(t.name, "transform") : g_pConfigManager->getInt("input:tablet:transform"), 0, 7);
+ Debug::log(LOG, "Setting calibration matrix for device %s", t.name);
+ libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]);
+
+ const auto OUTPUT = HASCONFIG ? g_pConfigManager->getDeviceString(t.name, "output") : g_pConfigManager->getString("input:tablet:output");
+ const auto PMONITOR = g_pCompositor->getMonitorFromString(OUTPUT);
+ if (!OUTPUT.empty() && OUTPUT != STRVAL_EMPTY && PMONITOR) {
wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, t.wlrDevice, PMONITOR->output);
wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, nullptr);
}
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index a520ce1c..8e4223eb 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -25,6 +25,26 @@ struct STouchData {
Vector2D touchSurfaceOrigin;
};
+// 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}
+};
+
class CKeybindManager;
class CInputManager {