From 0c10b8ab2dad9851b00c0e99bb1fde3f01d5478c Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 10 Dec 2023 18:30:08 +0200 Subject: [PATCH] input: Add scroll_points option for device (#4101) --- src/config/ConfigManager.cpp | 2 ++ src/managers/input/InputManager.cpp | 31 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index e5eb4cdb..5eb26efc 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -236,6 +236,7 @@ void CConfigManager::setDefaultVars() { configValues["input:scroll_method"].strValue = STRVAL_EMPTY; configValues["input:scroll_button"].intValue = 0; configValues["input:scroll_button_lock"].intValue = 0; + configValues["input:scroll_points"].strValue = STRVAL_EMPTY; configValues["input:touchpad:natural_scroll"].intValue = 0; configValues["input:touchpad:disable_while_typing"].intValue = 1; configValues["input:touchpad:clickfinger_behavior"].intValue = 0; @@ -307,6 +308,7 @@ void CConfigManager::setDeviceDefaultVars(const std::string& dev) { cfgValues["scroll_method"].strValue = STRVAL_EMPTY; cfgValues["scroll_button"].intValue = 0; cfgValues["scroll_button_lock"].intValue = 0; + cfgValues["scroll_points"].strValue = STRVAL_EMPTY; cfgValues["transform"].intValue = 0; cfgValues["output"].strValue = STRVAL_EMPTY; cfgValues["enabled"].intValue = 1; // only for mice / touchpads diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 21c9435d..284b4da6 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1066,23 +1066,40 @@ void CInputManager::setPointerConfigs() { libinput_device_config_accel_set_speed(LIBINPUTDEV, LIBINPUTSENS); const auto ACCELPROFILE = g_pConfigManager->getDeviceString(devname, "accel_profile", "input:accel_profile"); + const auto SCROLLPOINTS = g_pConfigManager->getDeviceString(devname, "scroll_points", "input:scroll_points"); - if (ACCELPROFILE == "") { + if (ACCELPROFILE.empty()) { libinput_device_config_accel_set_profile(LIBINPUTDEV, libinput_device_config_accel_get_default_profile(LIBINPUTDEV)); } else if (ACCELPROFILE == "adaptive") { libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); } else if (ACCELPROFILE == "flat") { libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } else if (ACCELPROFILE.starts_with("custom")) { - CVarList args = {ACCELPROFILE, 0, ' '}; + CVarList accelValues = {ACCELPROFILE, 0, ' '}; + try { - double step = std::stod(args[1]); - std::vector points; - for (size_t i = 2; i < args.size(); ++i) - points.push_back(std::stod(args[i])); + double accelStep = std::stod(accelValues[1]); + std::vector accelPoints; + for (size_t i = 2; i < accelValues.size(); ++i) { + accelPoints.push_back(std::stod(accelValues[i])); + } const auto CONFIG = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); - libinput_config_accel_set_points(CONFIG, LIBINPUT_ACCEL_TYPE_MOTION, step, points.size(), points.data()); + + if (!SCROLLPOINTS.empty()) { + CVarList scrollValues = {SCROLLPOINTS, 0, ' '}; + try { + double scrollStep = std::stod(scrollValues[0]); + std::vector scrollPoints; + for (size_t i = 1; i < scrollValues.size(); ++i) { + scrollPoints.push_back(std::stod(scrollValues[i])); + } + + libinput_config_accel_set_points(CONFIG, LIBINPUT_ACCEL_TYPE_SCROLL, scrollStep, scrollPoints.size(), scrollPoints.data()); + } catch (std::exception& e) { Debug::log(ERR, "Invalid values in scroll_points"); } + } + + libinput_config_accel_set_points(CONFIG, LIBINPUT_ACCEL_TYPE_MOTION, accelStep, accelPoints.size(), accelPoints.data()); libinput_device_config_accel_apply(LIBINPUTDEV, CONFIG); libinput_config_accel_destroy(CONFIG); } catch (std::exception& e) { Debug::log(ERR, "Invalid values in custom accel profile"); }