feat: Add event filters (#5)
This commit is contained in:
parent
79a286dd6d
commit
ca5ca3c3c6
@ -94,7 +94,9 @@ fn button_handler(c: &mut usize) {
|
||||
fn kol_main() {
|
||||
let mut c = 0;
|
||||
|
||||
while let Some(ev) = fetch_event() {
|
||||
while let Some(ev) =
|
||||
fetch_event((Event::Redraw as u32) | (Event::KeyPress as u32) | (Event::BtnPress as u32))
|
||||
{
|
||||
match ev {
|
||||
Event::Redraw => draw_window(c),
|
||||
Event::KeyPress => drop(fetch_key()),
|
||||
|
@ -12,6 +12,7 @@ SF_REDRAW = 12
|
||||
SF_GET_BUTTON = 17
|
||||
SF_SYSTEM_GET = 26
|
||||
SSF_SYS_LANG = 5
|
||||
SF_SET_EVENTS_MASK = 40
|
||||
SF_BOARD = 63
|
||||
SSF_DEBUG_WRITE = 1
|
||||
SF_SYS_MISC = 68
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -40,6 +40,10 @@ extern "C" {
|
||||
#[link_name = "_get_lang"]
|
||||
pub fn get_lang() -> u32;
|
||||
|
||||
// 40
|
||||
#[link_name = "_set_event_mask"]
|
||||
pub fn set_event_mask(mask: u32) -> u32;
|
||||
|
||||
// 63.1
|
||||
#[link_name = "_debug_write"]
|
||||
pub fn _debug_write(cl: u8);
|
||||
|
@ -18,6 +18,7 @@ section '.text'
|
||||
public _free
|
||||
public _get_lang
|
||||
public _load_dll
|
||||
public _set_event_mask
|
||||
|
||||
_exit:
|
||||
mov eax, SF_TERMINATE_PROCESS
|
||||
@ -126,3 +127,10 @@ _load_dll:
|
||||
mov ecx, [esp + 4 * 1]
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
_set_event_mask:
|
||||
mov eax, SF_SET_EVENTS_MASK
|
||||
mov ebx, [esp + 4 * 1]
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user