wzrd

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

input.rs (2339B)


      1 use super::super::input::Result;
      2 pub use super::super::input::*;
      3 
      4 use crate::geometry::Pos;
      5 use crate::window::Window;
      6 
      7 use std::collections::HashMap;
      8 use std::convert::TryFrom;
      9 use std::vec::Vec;
     10 
     11 use anyhow::anyhow;
     12 use strum::EnumIter;
     13 use strum::IntoEnumIterator;
     14 
     15 use x11rb::protocol::xproto::ButtonPressEvent;
     16 use x11rb::protocol::xproto::ButtonReleaseEvent;
     17 use x11rb::protocol::xproto::KeyPressEvent;
     18 use x11rb::protocol::xproto::ModMask;
     19 use x11rb::protocol::xproto::MotionNotifyEvent;
     20 
     21 impl From<Modifier> for u16 {
     22     fn from(modifier: Modifier) -> u16 {
     23         u16::from(match modifier {
     24             Modifier::Ctrl => ModMask::CONTROL,
     25             Modifier::Shift => ModMask::SHIFT,
     26             Modifier::Alt => ModMask::M1,
     27             Modifier::Super => ModMask::M4,
     28             Modifier::AltGr => ModMask::M3,
     29             Modifier::NumLock => ModMask::M2,
     30             Modifier::ScrollLock => ModMask::M5,
     31         })
     32     }
     33 }
     34 
     35 impl TryFrom<ModMask> for Modifier {
     36     type Error = anyhow::Error;
     37 
     38     fn try_from(val: ModMask) -> Result<Self> {
     39         match val {
     40             ModMask::CONTROL => Ok(Modifier::Ctrl),
     41             ModMask::SHIFT => Ok(Modifier::Shift),
     42             ModMask::M1 => Ok(Modifier::Alt),
     43             ModMask::M4 => Ok(Modifier::Super),
     44             ModMask::M3 => Ok(Modifier::AltGr),
     45             ModMask::M2 => Ok(Modifier::NumLock),
     46             ModMask::M5 => Ok(Modifier::ScrollLock),
     47             _ => Err(anyhow!("no matching modifier for value {}", u16::from(val))),
     48         }
     49     }
     50 }
     51 
     52 impl From<Button> for u8 {
     53     fn from(button: Button) -> u8 {
     54         match button {
     55             Button::Left => 1,
     56             Button::Middle => 2,
     57             Button::Right => 3,
     58             Button::ScrollUp => 4,
     59             Button::ScrollDown => 5,
     60             Button::Backward => 8,
     61             Button::Forward => 9,
     62         }
     63     }
     64 }
     65 
     66 impl TryFrom<u8> for Button {
     67     type Error = anyhow::Error;
     68 
     69     fn try_from(val: u8) -> Result<Self> {
     70         match val {
     71             1 => Ok(Self::Left),
     72             2 => Ok(Self::Middle),
     73             3 => Ok(Self::Right),
     74             4 => Ok(Self::ScrollUp),
     75             5 => Ok(Self::ScrollDown),
     76             8 => Ok(Self::Backward),
     77             9 => Ok(Self::Forward),
     78             _ => Err(anyhow!("no matching button for value {}", val)),
     79         }
     80     }
     81 }