input: Add scroll_points option for device (#4101)

This commit is contained in:
Mihai Fufezan 2023-12-10 18:30:08 +02:00 committed by GitHub
parent 9f5b9053c6
commit 0c10b8ab2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -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<double> 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<double> 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<double> 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"); }