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.
This commit is contained in:
Histausse 2022-10-07 16:03:52 +02:00
parent fe4a97f245
commit 32ae0c51f0
No known key found for this signature in database
GPG key ID: 67486F107F62E9E9
5 changed files with 59 additions and 0 deletions

View file

@ -147,6 +147,7 @@ void CConfigManager::setDefaultVars() {
configValues["input:touchpad:tap-to-click"].intValue = 1; configValues["input:touchpad:tap-to-click"].intValue = 1;
configValues["input:touchpad:drag_lock"].intValue = 0; configValues["input:touchpad:drag_lock"].intValue = 0;
configValues["input:touchpad:scroll_factor"].floatValue = 1.f; 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:pass_mouse_when_bound"].intValue = 0;
configValues["binds:scroll_event_delay"].intValue = 300; configValues["binds:scroll_event_delay"].intValue = 300;
@ -187,6 +188,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) {
cfgValues["drag_lock"].intValue = 0; cfgValues["drag_lock"].intValue = 0;
cfgValues["left_handed"].intValue = 0; cfgValues["left_handed"].intValue = 0;
cfgValues["scroll_method"].strValue = STRVAL_EMPTY; cfgValues["scroll_method"].strValue = STRVAL_EMPTY;
cfgValues["td_rotation"].intValue = 0;
} }
void CConfigManager::setDefaultAnimationVars() { void CConfigManager::setDefaultAnimationVars() {
@ -1139,6 +1141,7 @@ void CConfigManager::loadConfigLoadVars() {
if (!isFirstLaunch) { if (!isFirstLaunch) {
g_pInputManager->setKeyboardLayout(); g_pInputManager->setKeyboardLayout();
g_pInputManager->setPointerConfigs(); g_pInputManager->setPointerConfigs();
g_pInputManager->setTouchDeviceConfigs();
} }
// Calculate the internal vars // Calculate the internal vars
@ -1424,6 +1427,7 @@ void CConfigManager::dispatchExecOnce() {
// set input, fixes some certain issues // set input, fixes some certain issues
g_pInputManager->setKeyboardLayout(); g_pInputManager->setKeyboardLayout();
g_pInputManager->setPointerConfigs(); g_pInputManager->setPointerConfigs();
g_pInputManager->setTouchDeviceConfigs();
// set ws names again // set ws names again
for (auto& ws : g_pCompositor->m_vWorkspaces) { for (auto& ws : g_pCompositor->m_vWorkspaces) {

View file

@ -562,6 +562,7 @@ std::string dispatchKeyword(std::string in) {
if (COMMAND.contains("input") || COMMAND.contains("device:")) { if (COMMAND.contains("input") || COMMAND.contains("device:")) {
g_pInputManager->setKeyboardLayout(); // update kb layout g_pInputManager->setKeyboardLayout(); // update kb layout
g_pInputManager->setPointerConfigs(); // update mouse cfgs g_pInputManager->setPointerConfigs(); // update mouse cfgs
g_pInputManager->setTouchDeviceConfigs(); // update touch device cfgs
} }
if (COMMAND.contains("general:layout")) if (COMMAND.contains("general:layout"))

View file

@ -326,6 +326,8 @@ struct SIMEPopup {
struct STouchDevice { struct STouchDevice {
wlr_input_device* pWlrDevice = nullptr; wlr_input_device* pWlrDevice = nullptr;
std::string name = "";
DYNLISTENER(destroy); DYNLISTENER(destroy);
bool operator==(const STouchDevice& other) { bool operator==(const STouchDevice& other) {

View file

@ -1027,6 +1027,13 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) {
const auto PNEWDEV = &m_lTouchDevices.emplace_back(); const auto PNEWDEV = &m_lTouchDevices.emplace_back();
PNEWDEV->pWlrDevice = pDevice; 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); wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, pDevice);
Debug::log(LOG, "New touch device added at %x", PNEWDEV); Debug::log(LOG, "New touch device added at %x", PNEWDEV);
@ -1036,6 +1043,50 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) {
}, PNEWDEV, "TouchDevice"); }, 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) { void CInputManager::destroyTouchDevice(STouchDevice* pDevice) {
Debug::log(LOG, "Touch device at %x removed", pDevice); Debug::log(LOG, "Touch device at %x removed", pDevice);

View file

@ -53,6 +53,7 @@ public:
void setKeyboardLayout(); void setKeyboardLayout();
void setPointerConfigs(); void setPointerConfigs();
void setTouchDeviceConfigs();
void updateDragIcon(); void updateDragIcon();
void updateCapabilities(wlr_input_device*); void updateCapabilities(wlr_input_device*);