use x11::xlib; use crate::errors::{Error, Result}; /// An x11 Event #[derive(Debug)] pub struct Event { inner: xlib::XEvent, kind: EventKind, } /// Type of event #[derive(Debug)] pub enum EventKind { KeyPress(KeyEvent), KeyRelease(KeyEvent), } impl Event { /// Returns the EventKind of this event pub fn kind(&self) -> &EventKind { &self.kind } pub(super) unsafe fn from_raw(event: xlib::XEvent) -> Result { let inner = event; debug!("event type: {:?}", event.type_); let kind = match event.type_ { xlib::KeyPress => EventKind::KeyPress(KeyEvent(event.key)), xlib::KeyRelease => EventKind::KeyRelease(KeyEvent(event.key)), other => return Err(Error::InvalidEventType(other)), }; Ok(Event { inner, kind }) } } #[derive(Debug)] pub struct KeyEvent(xlib::XKeyEvent);