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() {
|
fn kol_main() {
|
||||||
let mut c = 0;
|
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 {
|
match ev {
|
||||||
Event::Redraw => draw_window(c),
|
Event::Redraw => draw_window(c),
|
||||||
Event::KeyPress => drop(fetch_key()),
|
Event::KeyPress => drop(fetch_key()),
|
||||||
|
@ -12,6 +12,7 @@ SF_REDRAW = 12
|
|||||||
SF_GET_BUTTON = 17
|
SF_GET_BUTTON = 17
|
||||||
SF_SYSTEM_GET = 26
|
SF_SYSTEM_GET = 26
|
||||||
SSF_SYS_LANG = 5
|
SSF_SYS_LANG = 5
|
||||||
|
SF_SET_EVENTS_MASK = 40
|
||||||
SF_BOARD = 63
|
SF_BOARD = 63
|
||||||
SSF_DEBUG_WRITE = 1
|
SSF_DEBUG_WRITE = 1
|
||||||
SF_SYS_MISC = 68
|
SF_SYS_MISC = 68
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::sys;
|
use crate::sys::{self, set_event_mask};
|
||||||
|
|
||||||
pub fn exit() -> ! {
|
pub fn exit() -> ! {
|
||||||
unsafe { sys::exit() }
|
unsafe { sys::exit() }
|
||||||
@ -6,18 +6,19 @@ pub fn exit() -> ! {
|
|||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Redraw,
|
Redraw = 1 << 0,
|
||||||
KeyPress,
|
KeyPress = 1 << 1,
|
||||||
BtnPress,
|
BtnPress = 1 << 2,
|
||||||
BgRedraw,
|
BgRedraw = 1 << 4,
|
||||||
Mouse,
|
Mouse = 1 << 5,
|
||||||
IPC,
|
IPC = 1 << 6,
|
||||||
Network,
|
Network = 1 << 7,
|
||||||
Debug,
|
Debug = 1 << 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_event() -> Option<Event> {
|
pub fn fetch_event(flags: u32) -> Option<Event> {
|
||||||
match unsafe { sys::wait_event() } {
|
let old_mask = unsafe { sys::set_event_mask(flags as u32) };
|
||||||
|
let e = match unsafe { sys::wait_event() } {
|
||||||
1 => Some(Event::Redraw),
|
1 => Some(Event::Redraw),
|
||||||
2 => Some(Event::KeyPress),
|
2 => Some(Event::KeyPress),
|
||||||
3 => Some(Event::BtnPress),
|
3 => Some(Event::BtnPress),
|
||||||
@ -27,5 +28,7 @@ pub fn fetch_event() -> Option<Event> {
|
|||||||
8 => Some(Event::Network),
|
8 => Some(Event::Network),
|
||||||
9 => Some(Event::Debug),
|
9 => Some(Event::Debug),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
};
|
||||||
|
unsafe { set_event_mask(old_mask) };
|
||||||
|
e
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,10 @@ extern "C" {
|
|||||||
#[link_name = "_get_lang"]
|
#[link_name = "_get_lang"]
|
||||||
pub fn get_lang() -> u32;
|
pub fn get_lang() -> u32;
|
||||||
|
|
||||||
|
// 40
|
||||||
|
#[link_name = "_set_event_mask"]
|
||||||
|
pub fn set_event_mask(mask: u32) -> u32;
|
||||||
|
|
||||||
// 63.1
|
// 63.1
|
||||||
#[link_name = "_debug_write"]
|
#[link_name = "_debug_write"]
|
||||||
pub fn _debug_write(cl: u8);
|
pub fn _debug_write(cl: u8);
|
||||||
|
@ -18,6 +18,7 @@ section '.text'
|
|||||||
public _free
|
public _free
|
||||||
public _get_lang
|
public _get_lang
|
||||||
public _load_dll
|
public _load_dll
|
||||||
|
public _set_event_mask
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
mov eax, SF_TERMINATE_PROCESS
|
mov eax, SF_TERMINATE_PROCESS
|
||||||
@ -126,3 +127,10 @@ _load_dll:
|
|||||||
mov ecx, [esp + 4 * 1]
|
mov ecx, [esp + 4 * 1]
|
||||||
int 0x40
|
int 0x40
|
||||||
ret
|
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