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
use std::collections::HashMap;
use xcb::xkb;
use wm::client::{ClientSet, ScreenSet};
use wm::config::{Mode, IGNORED_MODS_VEC};
use wm::window_system::WmCommand;
#[allow(dead_code)]
pub const NO_MODIFIER: u8 = 0;
pub const SHIFT: u8 = 1;
pub const CTRL: u8 = 4;
#[allow(dead_code)]
pub const ALT: u8 = 8;
#[allow(dead_code)]
pub const MOD4: u8 = 64;
pub const ALTGR: u8 = 136;
pub type KeyCallback = Box<Fn(&mut ClientSet, &mut ScreenSet) -> WmCommand>;
pub type Keybindings = HashMap<KeyPress, KeyCallback>;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct KeyPress {
pub code: u8,
pub mods: u8,
pub mode: Mode,
}
pub fn from_key(event: &xkb::StateNotifyEvent, mode: Mode) -> KeyPress {
let ignore_mask: u8 = !IGNORED_MODS_VEC.iter().fold(0, |a, b| a | *b as u8);
info!("ignore_mask: {}", ignore_mask);
KeyPress {
code: event.xkb_type(),
mods: event.keycode() & ignore_mask,
mode: mode,
}
}