wzrd

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in Rust
git clone git://git.deurzen.net/wzrd
Log | Files | Refs | LICENSE

util.rs (1674B)


      1 use super::super::input::Result;
      2 
      3 use std::collections::HashMap;
      4 use std::process::Command;
      5 
      6 pub type KeyMap = HashMap<String, u8>;
      7 pub type CodeMap = HashMap<u8, String>;
      8 
      9 pub struct Util;
     10 impl Util {
     11     pub fn system_keymap() -> KeyMap {
     12         match Command::new("xmodmap").arg("-pke").output() {
     13             Err(err) => panic!("unable to fetch keycodes via xmodmap: {}", err),
     14             Ok(out) => match String::from_utf8(out.stdout) {
     15                 Err(err) => panic!("invalid UTF8 from xmodmap: {}", err),
     16                 Ok(out) => out
     17                     .lines()
     18                     .flat_map(|l| {
     19                         let mut words = l.split_whitespace();
     20                         let key_code: u8 = words.nth(1).unwrap().parse().unwrap();
     21 
     22                         words.skip(1).map(move |name| (name.into(), key_code))
     23                     })
     24                     .collect::<KeyMap>(),
     25             },
     26         }
     27     }
     28 
     29     pub fn system_codemap() -> CodeMap {
     30         match Command::new("xmodmap").arg("-pke").output() {
     31             Err(err) => panic!("unable to fetch keycodes via xmodmap: {}", err),
     32             Ok(out) => match String::from_utf8(out.stdout) {
     33                 Err(err) => panic!("invalid UTF8 from xmodmap: {}", err),
     34                 Ok(out) => out
     35                     .lines()
     36                     .flat_map(|l| {
     37                         let mut words = l.split_whitespace();
     38                         let key_code: u8 = words.nth(1).unwrap().parse().unwrap();
     39 
     40                         words.skip(1).map(move |name| (key_code, name.into()))
     41                     })
     42                     .collect::<CodeMap>(),
     43             },
     44         }
     45     }
     46 }