Set relative axes

This commit is contained in:
Takashi Kokubun 2021-12-13 22:07:47 -08:00
parent 06b2d04a89
commit 4b33dee052
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD
2 changed files with 13 additions and 5 deletions

View File

@ -11,9 +11,10 @@ fn event_loop(input_device: &mut Device) -> Result<(), Box<dyn Error>> {
if !select::is_readable(input_device) { continue } if !select::is_readable(input_device) { continue }
for event in input_device.fetch_events().unwrap() { for event in input_device.fetch_events().unwrap() {
if event.event_type() == EventType::KEY { println!("event: {:?}", event);
println!("event: {:?}", event); //if event.event_type() == EventType::KEY {
} // println!("event: {:?}", event);
//}
output_device.emit(&[event]).unwrap(); output_device.emit(&[event]).unwrap();
} }
} }

View File

@ -1,13 +1,20 @@
use std::error::Error; use std::error::Error;
use evdev::{Device}; use evdev::{AttributeSet, Device, RelativeAxisType};
use evdev::uinput::{VirtualDevice, VirtualDeviceBuilder}; use evdev::uinput::{VirtualDevice, VirtualDeviceBuilder};
pub fn build_device(base_device: &Device) -> Result<VirtualDevice, Box<dyn Error>> { pub fn build_device(base_device: &Device) -> Result<VirtualDevice, Box<dyn Error>> {
let mut rel_axes = AttributeSet::<RelativeAxisType>::new();
rel_axes.insert(evdev::RelativeAxisType::REL_X);
rel_axes.insert(evdev::RelativeAxisType::REL_Y);
rel_axes.insert(evdev::RelativeAxisType::REL_HWHEEL);
rel_axes.insert(evdev::RelativeAxisType::REL_WHEEL);
rel_axes.insert(evdev::RelativeAxisType::REL_MISC);
let device = VirtualDeviceBuilder::new()? let device = VirtualDeviceBuilder::new()?
.name("xremap") .name("xremap")
.with_keys(base_device.supported_keys().unwrap())? .with_keys(base_device.supported_keys().unwrap())?
.with_relative_axes(&rel_axes)?
.build() .build()
.unwrap(); .unwrap();
Ok(device) Ok(device)
} }