mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
filter key presses through the video layer
the video layer is the "traffic cop" managing when modals get focus. This patch creates a feed from the video layer that listers to subscribe to that filters out key presses destined for modals.
This commit is contained in:
parent
738797754b
commit
106f7153a1
3 changed files with 62 additions and 13 deletions
|
|
@ -96,6 +96,8 @@ pub enum GfxOpcode {
|
|||
ReleaseModal,
|
||||
/// V2 API for fast drawing of multiple objects
|
||||
UnclippedObjectList,
|
||||
/// V2 API for getting filtered keyboard events
|
||||
FilteredKeyboardListener,
|
||||
|
||||
#[cfg(feature = "board-baosec")]
|
||||
AcquireQr,
|
||||
|
|
@ -134,3 +136,10 @@ pub struct QrAcquisition {
|
|||
pub content: Option<String>,
|
||||
pub meta: Option<String>,
|
||||
}
|
||||
|
||||
// this structure is used to register a keyboard listener.
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
||||
pub struct KeyboardRegistration {
|
||||
pub server_name: String,
|
||||
pub listener_op_id: usize,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -744,6 +744,14 @@ impl Gfx {
|
|||
// just return some dummy data
|
||||
Ok(QrAcquisition { content: Some(dummy), meta: None })
|
||||
}
|
||||
|
||||
pub fn register_listener(&self, server_name: &str, action_opcode: usize) {
|
||||
let kr =
|
||||
KeyboardRegistration { server_name: String::from(server_name), listener_op_id: action_opcode };
|
||||
let buf = Buffer::into_buf(kr).unwrap();
|
||||
buf.lend(self.conn, GfxOpcode::FilteredKeyboardListener.to_u32().unwrap())
|
||||
.expect("couldn't register listener");
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ use num_traits::*;
|
|||
use utralib::utra;
|
||||
use ux_api::minigfx::{self, FrameBuffer};
|
||||
use ux_api::service::api::*;
|
||||
use xous::sender::Sender;
|
||||
use xous::{CID, sender::Sender};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
// Scope of this crate: *No calls to modals* this can create dependency lockups.
|
||||
//
|
||||
|
|
@ -339,6 +340,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
testing::tests();
|
||||
let mut bw_thresh: u8 = 128;
|
||||
let mut qr_request: Option<xous::MessageEnvelope> = None;
|
||||
let mut kbd_listeners: Vec<(CID, usize)> = Vec::new();
|
||||
loop {
|
||||
if !is_panic.load(Ordering::Relaxed) {
|
||||
xous::reply_and_receive_next(sid, &mut msg_opt).unwrap();
|
||||
|
|
@ -391,18 +393,35 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
}
|
||||
#[cfg(not(feature = "hosted-baosec"))]
|
||||
GfxOpcode::KeyPress => {
|
||||
// any key press will abort QR acquisition by taking the qr_request. If it's already None,
|
||||
// the keypress is just ignored.
|
||||
if let Some(mut envelope) = qr_request.take() {
|
||||
let acquisition = QrAcquisition { content: None, meta: None };
|
||||
let mut response = unsafe {
|
||||
xous_ipc::Buffer::from_memory_message_mut(
|
||||
envelope.body.memory_message_mut().unwrap(),
|
||||
)
|
||||
};
|
||||
response.replace(acquisition).unwrap();
|
||||
display.pop();
|
||||
hal.set_preemption(true);
|
||||
if let Some(scalar) = msg.body.scalar_message() {
|
||||
// any key press will abort QR acquisition by taking the qr_request.
|
||||
if let Some(mut envelope) = qr_request.take() {
|
||||
let acquisition = QrAcquisition { content: None, meta: None };
|
||||
let mut response = unsafe {
|
||||
xous_ipc::Buffer::from_memory_message_mut(
|
||||
envelope.body.memory_message_mut().unwrap(),
|
||||
)
|
||||
};
|
||||
response.replace(acquisition).unwrap();
|
||||
display.pop();
|
||||
hal.set_preemption(true);
|
||||
}
|
||||
// forward messages on to listeners iff we don't have an active modal
|
||||
if modal_queue.len() == 0 {
|
||||
for &(listener_conn, listener_op) in kbd_listeners.iter() {
|
||||
xous::try_send_message(
|
||||
listener_conn,
|
||||
xous::Message::new_scalar(
|
||||
listener_op,
|
||||
scalar.arg1,
|
||||
scalar.arg2,
|
||||
scalar.arg3,
|
||||
scalar.arg4,
|
||||
),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GfxOpcode::CamIrq => {
|
||||
|
|
@ -575,6 +594,19 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
}
|
||||
}
|
||||
}
|
||||
GfxOpcode::FilteredKeyboardListener => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let kr = buffer.as_flat::<KeyboardRegistration, _>().unwrap();
|
||||
match xns.request_connection_blocking(kr.server_name.as_str()) {
|
||||
Ok(cid) => {
|
||||
kbd_listeners
|
||||
.push((cid, <u32 as From<u32>>::from(kr.listener_op_id.into()) as usize));
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't connect to listener: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- "regular" graphics API
|
||||
GfxOpcode::DrawClipObject => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue