safex11/src/xlib/event.rs

39 lines
896 B
Rust
Raw Normal View History

2020-06-28 09:43:22 +00:00
use x11::xlib;
use crate::errors::{Error, Result};
/// An x11 Event
#[derive(Debug)]
pub struct Event {
2020-06-29 05:22:13 +00:00
inner: xlib::XEvent,
2020-06-28 09:43:22 +00:00
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
}
2020-06-29 05:22:13 +00:00
pub(super) unsafe fn from_raw(event: xlib::XEvent) -> Result<Self> {
2020-06-28 09:43:22 +00:00
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);