input.rs icon indicating copy to clipboard operation
input.rs copied to clipboard

libinput 1.23, Add accel config for pointer acceleration

Open rockerBOO opened this issue 1 year ago • 2 comments

I was wanting to play with pointer acceleration added in 1.23. I gen'd the latest version 1.26.1.

Add AccelProfile::Custom Add AccelType Add AccelConfig

The example I have been testing with:

use std::{
    fs::{File, OpenOptions},
    os::fd::OwnedFd,
    path::Path,
};

use input::{AccelProfile, Libinput, LibinputInterface};

struct Interface;

impl LibinputInterface for Interface {
    fn open_restricted(&mut self, path: &Path, flags: i32) -> Result<OwnedFd, i32> {
        OpenOptions::new()
            .read(true)
            .write(true)
            .open(path)
            .map(|file| file.into())
            .map_err(|err| err.raw_os_error().unwrap())
    }
    fn close_restricted(&mut self, fd: OwnedFd) {
        let _file = File::from(fd);
    }
}

fn main() {
    let device = "/dev/input/event7";
    let mut input = Libinput::new_from_path(Interface);
    let mut device = input.path_add_device(device).expect("to get the device");

    dbg!(&device.name());

    if device.config_accel_is_available() {
        device
            .config_accel_set_profile(AccelProfile::Custom)
            .expect("to set profile to custom");

        let config = input::accel_config::AccelConfig::new(AccelProfile::Custom);

        config
            .set_points(
                input::accel_config::AccelType::Motion,
                0.5,
                4,
                vec![3., 4., 5., 6.],
            )
            .expect("to set points");

        dbg!(device.config_accel_profile().unwrap());

        device.config_accel_apply(config).expect("to apply config");
    }
}

Willing to make some updates of what may be better.

Thanks


Context

  • https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/775

rockerBOO avatar Jul 27 '24 22:07 rockerBOO

Thanks for taking the time to review this code. I will make the marked improvements. I minimally made these changes and wasn't sure if they would be accepted. I can now work to make this acceptable for merging.

Thanks.

rockerBOO avatar Jul 29 '24 17:07 rockerBOO

Is this ready for review? I'd like to see this merged (and am happy to do what I can to keep it going)

TheOnlyMrCat avatar Jan 16 '25 08:01 TheOnlyMrCat