event.rs

 1use x11rb::protocol::xproto;
 2
 3use crate::{Modifiers, MouseButton, NavigationDirection};
 4
 5pub(crate) fn button_of_key(detail: xproto::Button) -> Option<MouseButton> {
 6    Some(match detail {
 7        1 => MouseButton::Left,
 8        2 => MouseButton::Middle,
 9        3 => MouseButton::Right,
10        8 => MouseButton::Navigate(NavigationDirection::Back),
11        9 => MouseButton::Navigate(NavigationDirection::Forward),
12        _ => return None,
13    })
14}
15
16pub(crate) fn modifiers_from_state(state: xproto::KeyButMask) -> Modifiers {
17    Modifiers {
18        control: state.contains(xproto::KeyButMask::CONTROL),
19        alt: state.contains(xproto::KeyButMask::MOD1),
20        shift: state.contains(xproto::KeyButMask::SHIFT),
21        command: state.contains(xproto::KeyButMask::MOD4),
22        function: false,
23    }
24}
25
26pub(crate) fn button_from_state(state: xproto::KeyButMask) -> Option<MouseButton> {
27    Some(if state.contains(xproto::KeyButMask::BUTTON1) {
28        MouseButton::Left
29    } else if state.contains(xproto::KeyButMask::BUTTON2) {
30        MouseButton::Middle
31    } else if state.contains(xproto::KeyButMask::BUTTON3) {
32        MouseButton::Right
33    } else {
34        return None;
35    })
36}