summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 3473bf7ac2e65274af27b4cc113227147e251685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::mapping::*;
use crate::remapper::*;
use anyhow::*;
use std::time::Duration;
use structopt::StructOpt;

mod deviceinfo;
mod mapping;
mod remapper;

#[derive(Debug, StructOpt)]
#[structopt(
    name = "evremap",
    about = "Remap libinput evdev keyboard inputs",
    author = "Wez Furlong"
)]
struct Opt {
    /// Rather than running the remapper, list currently available devices.
    /// This is helpful to check their names when setting up the initial
    /// configuration
    #[structopt(name = "list-devices", long)]
    list_devices: bool,
}

fn main() -> Result<()> {
    pretty_env_logger::init();
    let opt = Opt::from_args();

    if opt.list_devices {
        return deviceinfo::list_devices();
    }

    let mappings = vec![
        Mapping::DualRole {
            input: KeyCode::KEY_CAPSLOCK,
            hold: vec![KeyCode::KEY_LEFTCTRL],
            tap: vec![KeyCode::KEY_ESC],
        },
        Mapping::Remap {
            input: [KeyCode::KEY_F1].into_iter().cloned().collect(),
            output: [KeyCode::KEY_BACK].into_iter().cloned().collect(),
        },
        Mapping::Remap {
            input: [KeyCode::KEY_F8].into_iter().cloned().collect(),
            output: [KeyCode::KEY_MUTE].into_iter().cloned().collect(),
        },
        Mapping::Remap {
            input: [KeyCode::KEY_F5].into_iter().cloned().collect(),
            output: [KeyCode::KEY_BRIGHTNESSDOWN].into_iter().cloned().collect(),
        },
        Mapping::Remap {
            input: [KeyCode::KEY_F6].into_iter().cloned().collect(),
            output: [KeyCode::KEY_BRIGHTNESSUP].into_iter().cloned().collect(),
        },
    ];

    log::error!("Short delay: release any keys now!");
    std::thread::sleep(Duration::new(2, 0));

    let device_info = deviceinfo::DeviceInfo::with_name("AT Translated Set 2 keyboard")?;

    let mut mapper = InputMapper::create_mapper(device_info.path, mappings)?;
    mapper.run_mapper()?;
    Ok(())
}