From 0c10b8ab2dad9851b00c0e99bb1fde3f01d5478c Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 10 Dec 2023 18:30:08 +0200 Subject: input: Add scroll_points option for device (#4101) --- src/managers/input/InputManager.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/managers/input/InputManager.cpp') 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"); } -- cgit v1.2.3