mirror of
https://github.com/k0kubun/xremap
synced 2024-11-02 03:40:25 +00:00
Implement global modmap
This commit is contained in:
parent
4061f77694
commit
9cc6bb0006
@ -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();
|
||||
|
@ -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
13
src/transform.rs
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user