Implement global modmap

This commit is contained in:
Takashi Kokubun 2021-12-13 23:23:16 -08:00
parent 4061f77694
commit 9cc6bb0006
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD
3 changed files with 17 additions and 3 deletions

View File

@ -4,6 +4,7 @@ use std::error::Error;
mod input;
mod output;
mod select;
mod transform;
fn event_loop(input_device: &mut Device) -> Result<(), Box<dyn Error>> {
let mut output_device = output::build_device(input_device).unwrap();
@ -14,12 +15,13 @@ fn event_loop(input_device: &mut Device) -> Result<(), Box<dyn Error>> {
for event in input_device.fetch_events().unwrap() {
if event.event_type() == EventType::KEY {
println!("event: {:?}", event);
}
transform::on_event(event, &mut output_device);
} else {
output_device.emit(&[event]).unwrap();
}
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
let mut device = input::select_device();

View File

@ -8,6 +8,5 @@ pub fn build_device(base_device: &Device) -> Result<VirtualDevice, Box<dyn Error
.with_keys(base_device.supported_keys().unwrap())?
.build()
.unwrap();
Ok(device)
}

13
src/transform.rs Normal file
View File

@ -0,0 +1,13 @@
use evdev::{EventType, InputEvent, InputEventKind};
use evdev::uinput::VirtualDevice;
pub fn on_event(event: InputEvent, device: &mut VirtualDevice) {
println!("event: {:?}", event);
if event.kind() == InputEventKind::Key(evdev::Key::KEY_A) {
device.emit(&[
InputEvent::new(EventType::KEY, evdev::Key::KEY_B.code(), event.value())
]).unwrap();
} else {
device.emit(&[event]).unwrap();
}
}