mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-27 00:45:58 +01:00
Add tablets calibration matrix for dynamic rotation with 2-in1/tablet PC usage (#1319)
This commit is contained in:
parent
b5b436e01d
commit
040e99fd17
3 changed files with 37 additions and 22 deletions
|
@ -160,6 +160,8 @@ void CConfigManager::setDefaultVars() {
|
||||||
configValues["input:touchpad:scroll_factor"].floatValue = 1.f;
|
configValues["input:touchpad:scroll_factor"].floatValue = 1.f;
|
||||||
configValues["input:touchdevice:transform"].intValue = 0;
|
configValues["input:touchdevice:transform"].intValue = 0;
|
||||||
configValues["input:touchdevice:output"].strValue = STRVAL_EMPTY;
|
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:pass_mouse_when_bound"].intValue = 0;
|
||||||
configValues["binds:scroll_event_delay"].intValue = 300;
|
configValues["binds:scroll_event_delay"].intValue = 300;
|
||||||
|
@ -1340,7 +1342,12 @@ SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, co
|
||||||
if (foundIt == std::string::npos)
|
if (foundIt == std::string::npos)
|
||||||
continue;
|
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;
|
copy = cv.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1144,23 +1144,6 @@ void CInputManager::newTouchDevice(wlr_input_device* pDevice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::setTouchDeviceConfigs() {
|
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) {
|
for (auto& m : m_lTouchDevices) {
|
||||||
const auto PTOUCHDEV = &m;
|
const auto PTOUCHDEV = &m;
|
||||||
|
|
||||||
|
@ -1186,11 +1169,16 @@ void CInputManager::setTabletConfigs() {
|
||||||
for (auto& t : m_lTablets) {
|
for (auto& t : m_lTablets) {
|
||||||
const auto HASCONFIG = g_pConfigManager->deviceConfigExists(t.name);
|
const auto HASCONFIG = g_pConfigManager->deviceConfigExists(t.name);
|
||||||
|
|
||||||
if (HASCONFIG) {
|
if (wlr_input_device_is_libinput(t.wlrDevice)) {
|
||||||
const auto OUTPUT = g_pConfigManager->getDeviceString(t.name, "output");
|
const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(t.wlrDevice);
|
||||||
const auto PMONITOR = g_pCompositor->getMonitorFromString(OUTPUT);
|
|
||||||
|
|
||||||
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_output(g_pCompositor->m_sWLRCursor, t.wlrDevice, PMONITOR->output);
|
||||||
wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, nullptr);
|
wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,26 @@ struct STouchData {
|
||||||
Vector2D touchSurfaceOrigin;
|
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 CKeybindManager;
|
||||||
|
|
||||||
class CInputManager {
|
class CInputManager {
|
||||||
|
|
Loading…
Reference in a new issue