summaryrefslogtreecommitdiffstats
path: root/rsnix/src/tty.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--rsnix/src/tty.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/rsnix/src/tty.rs b/rsnix/src/tty.rs
index 0783521..6102fb5 100644
--- a/rsnix/src/tty.rs
+++ b/rsnix/src/tty.rs
@@ -41,14 +41,31 @@ static mut RAW_LEN: usize = 0;
41/// Combined blocking key poll: USB HID keyboard first (polled UHCI), then 41/// Combined blocking key poll: USB HID keyboard first (polled UHCI), then
42/// the PS/2 path (which parks via `hlt` until an IRQ-fed scancode lands). 42/// the PS/2 path (which parks via `hlt` until an IRQ-fed scancode lands).
43fn poll_key() -> KeyEvent { 43fn poll_key() -> KeyEvent {
44 if let Some(ev) = crate::uhci::try_poll_key() { 44 loop {
45 return ev; 45 // A GUI window has focus: the keyboard pump owns the keys. Park so
46 // the shell/editor don't steal input from the focused app.
47 if crate::wm::focused().is_some() {
48 crate::sched::sleep_ms(5);
49 continue;
50 }
51 if let Some(ev) = crate::uhci::try_poll_key() {
52 return ev;
53 }
54 if let Some(ev) = ps2::try_poll_key() {
55 return ev;
56 }
57 // No key ready: park briefly, then re-check focus (so a focus change
58 // to a GUI window is noticed instead of blocking on a stolen key).
59 crate::sched::sleep_ms(5);
46 } 60 }
47 ps2::poll_key()
48} 61}
49 62
50/// Combined non-blocking key poll (USB first, then PS/2). 63/// Combined non-blocking key poll (USB first, then PS/2). Returns `None`
64/// while a GUI window is focused (the keyboard pump owns the keys).
51fn try_poll_key() -> Option<KeyEvent> { 65fn try_poll_key() -> Option<KeyEvent> {
66 if crate::wm::focused().is_some() {
67 return None;
68 }
52 crate::uhci::try_poll_key().or_else(ps2::try_poll_key) 69 crate::uhci::try_poll_key().or_else(ps2::try_poll_key)
53} 70}
54 71