#![allow(dead_code)] //use x11::xlib::Window; use super::keycodes::{MouseButton, VirtualKeyCode}; #[derive(Debug)] pub enum WindowEvent { KeyEvent(KeyEvent), ButtonEvent(ButtonEvent), MotionEvent(MotionEvent), MapRequestEvent(MapEvent), MapEvent(MapEvent), UnmapEvent(UnmapEvent), CreateEvent(CreateEvent), DestroyEvent(DestroyEvent), EnterEvent(EnterEvent), ConfigureEvent(ConfigureEvent), FullscreenEvent(FullscreenEvent), //1 { window: Window, event: 1 }, } #[derive(Debug)] pub enum KeyState { Pressed, Released, } #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] #[repr(u8)] pub enum ModifierKey { Shift, ShiftLock, Control, Alt, AltGr, /// Windows key on most keyboards Super, NumLock, } #[derive(Default, Debug, Clone)] pub struct ModifierState { modifiers: std::collections::HashSet, } impl ModifierState { pub fn new() -> Self { Self::default() } pub fn set_modifier(&mut self, modifier: ModifierKey) { self.modifiers.insert(modifier); } pub fn unset_modifier(&mut self, modifier: ModifierKey) { self.modifiers.remove(&modifier); } pub fn get_modifier(&mut self, modifier: ModifierKey) -> bool { self.modifiers.contains(&modifier) } } #[derive(Debug)] pub struct KeyEvent { pub window: Window, pub state: KeyState, pub keycode: VirtualKeyCode, pub modifierstate: ModifierState, } impl KeyEvent { pub fn new( window: Window, state: KeyState, keycode: VirtualKeyCode, modifierstate: ModifierState, ) -> Self { Self { window, state, keycode, modifierstate, } } } #[derive(Debug)] pub struct ButtonEvent { pub window: Window, pub state: KeyState, pub keycode: MouseButton, pub modifierstate: ModifierState, } impl ButtonEvent { pub fn new( window: Window, state: KeyState, keycode: MouseButton, modifierstate: ModifierState, ) -> Self { Self { window, state, keycode, modifierstate, } } } #[derive(Debug)] pub struct MotionEvent { pub position: [i32; 2], pub window: Window, } impl MotionEvent { pub fn new(position: [i32; 2], window: Window) -> Self { Self { position, window } } } #[derive(Debug)] pub struct MapEvent { pub window: Window, } #[derive(Debug)] pub struct UnmapEvent { pub window: Window, } #[derive(Debug)] pub struct EnterEvent { pub window: Window, } #[derive(Debug)] pub struct DestroyEvent { pub window: Window, } impl DestroyEvent { pub fn new(window: Window) -> Self { Self { window } } } #[derive(Debug)] pub struct CreateEvent { pub window: Window, pub position: [i32; 2], pub size: [i32; 2], } impl CreateEvent { pub fn new(window: Window, position: [i32; 2], size: [i32; 2]) -> Self { Self { window, position, size, } } } #[derive(Debug)] pub struct ConfigureEvent { pub window: Window, pub position: [i32; 2], pub size: [i32; 2], } impl ConfigureEvent { pub fn new(window: Window, position: [i32; 2], size: [i32; 2]) -> Self { Self { window, position, size, } } } #[derive(Debug)] pub struct FullscreenEvent { window: Window, new_fullscreen: bool, } impl FullscreenEvent { pub fn new(window: Window, new_fullscreen: bool) -> Self { Self { window, new_fullscreen, } } } pub struct KeyBind { key: VirtualKeyCode, modifiers: ModifierState, } pub struct MouseBind { button: MouseButton, modifiers: ModifierState, }