safex11/src/xlib/event.rs
2023-08-20 04:50:59 -05:00

38 lines
836 B
Rust

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<Self> {
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);