1
0
forked from Rust/Core

feat: Add event filters (#5)

This commit is contained in:
2024-03-11 23:50:22 +03:00
parent 79a286dd6d
commit ca5ca3c3c6
5 changed files with 31 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
use crate::sys;
use crate::sys::{self, set_event_mask};
pub fn exit() -> ! {
unsafe { sys::exit() }
@@ -6,18 +6,19 @@ pub fn exit() -> ! {
#[non_exhaustive]
pub enum Event {
Redraw,
KeyPress,
BtnPress,
BgRedraw,
Mouse,
IPC,
Network,
Debug,
Redraw = 1 << 0,
KeyPress = 1 << 1,
BtnPress = 1 << 2,
BgRedraw = 1 << 4,
Mouse = 1 << 5,
IPC = 1 << 6,
Network = 1 << 7,
Debug = 1 << 8,
}
pub fn fetch_event() -> Option<Event> {
match unsafe { sys::wait_event() } {
pub fn fetch_event(flags: u32) -> Option<Event> {
let old_mask = unsafe { sys::set_event_mask(flags as u32) };
let e = match unsafe { sys::wait_event() } {
1 => Some(Event::Redraw),
2 => Some(Event::KeyPress),
3 => Some(Event::BtnPress),
@@ -27,5 +28,7 @@ pub fn fetch_event() -> Option<Event> {
8 => Some(Event::Network),
9 => Some(Event::Debug),
_ => None,
}
};
unsafe { set_event_mask(old_mask) };
e
}