diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index 4e91e0691..c3eeebe4a 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -169,6 +169,8 @@ pub(crate) enum Opcode { /// used to turn keyboard vibrate on and off Vibe, + /// used to toggle menu mode behavior for the prediction area (default: false) + ToggleMenuMode, /// called by a context when it's done with taking the screen; requests the GAM to revert focus to the last-focused app RevertFocus, diff --git a/services/gam/src/contexts.rs b/services/gam/src/contexts.rs index 0d71b6e72..b1d88a852 100644 --- a/services/gam/src/contexts.rs +++ b/services/gam/src/contexts.rs @@ -73,6 +73,8 @@ pub(crate) struct UxContext { pub audioframe_id: Option, /// opcode ID for focus change pub focuschange_id: Option, + /// sets the behavior of the IMEF + pub imef_menu_mode: bool, } pub(crate) const BOOT_CONTEXT_TRUSTLEVEL: u8 = 254; @@ -154,6 +156,7 @@ impl ContextManager { focuschange_id: registration.focuschange_id, rawkeys_id: None, vibe: false, + imef_menu_mode: false, }; self.contexts.insert(token, ux_context); }, @@ -175,6 +178,7 @@ impl ContextManager { focuschange_id: registration.focuschange_id, rawkeys_id: registration.rawkeys_id, vibe: false, + imef_menu_mode: false, }; if registration.app_name.as_str().unwrap() == MAIN_MENU_NAME { @@ -202,6 +206,7 @@ impl ContextManager { focuschange_id: registration.focuschange_id, rawkeys_id: registration.rawkeys_id, vibe: false, + imef_menu_mode: false, }; self.contexts.insert(token, ux_context); // this check gives permissions to password boxes to render inverted text @@ -229,6 +234,7 @@ impl ContextManager { focuschange_id: registration.focuschange_id, rawkeys_id: registration.rawkeys_id, vibe: false, + imef_menu_mode: false, }; self.contexts.insert(token, ux_context); } @@ -425,6 +431,7 @@ impl ContextManager { // revert the keyboard vibe state self.kbd.set_vibe(context.vibe).expect("couldn't restore keyboard vibe"); + self.imef.set_menu_mode(context.imef_menu_mode).expect("couldn't set menu mode"); log::trace!("raised focus to: {:?}", context); let last_token = context.app_token; @@ -586,6 +593,12 @@ impl ContextManager { (*context).vibe = set_vibe; } } + pub(crate) fn toggle_menu_mode(&mut self, token: [u32; 4]) { + if let Some(context) = self.contexts.get_mut(&token) { + context.imef_menu_mode = !context.imef_menu_mode; + log::info!("menu mode for token {:?} is now {}", token, context.imef_menu_mode); + } + } pub(crate) fn raise_menu(&mut self, name: &str, gfx: &graphics_server::Gfx, diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index 42a3f80d6..1a934bca5 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -327,6 +327,16 @@ impl Gam { ena, 0, 0, 0,) ).map(|_| ()) } + pub fn toggle_menu_mode(&self, token: [u32; 4]) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::ToggleMenuMode.to_usize().unwrap(), + token[0] as usize, + token[1] as usize, + token[2] as usize, + token[3] as usize, + ) + ).map(|_| ()) + } /// this indicates to the GAM that the currently running app no longer wants to be the focus of attention /// we might respect that. or maybe not. depends on the GAM's policies. pub fn relinquish_focus(&self) -> Result<(), xous::Error> { diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index d39beb28b..b4c511cb2 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -512,6 +512,10 @@ fn wrapped_main() -> ! { if ena != 0 { context_mgr.vibe(true) } else { context_mgr.vibe(false) } }), + Some(Opcode::ToggleMenuMode) => msg_scalar_unpack!(msg, t1, t2, t3, t4, { + let token = [t1 as u32, t2 as u32, t3 as u32, t4 as u32]; + context_mgr.toggle_menu_mode(token); + }), Some(Opcode::RevertFocus) => { match context_mgr.revert_focus(&gfx, &mut canvases) { Ok(_) => xous::return_scalar(msg.sender, 0).expect("couldn't unblock caller"), diff --git a/services/ime-frontend/src/main.rs b/services/ime-frontend/src/main.rs index 1f3235fd8..b6cdb0c5f 100644 --- a/services/ime-frontend/src/main.rs +++ b/services/ime-frontend/src/main.rs @@ -63,6 +63,9 @@ struct InputTracker { /// keep track if our box was grown was_grown: bool, + /// if set to true, the F1-F4 keys work as menu selects, and not as predictive inputs + menu_mode: bool, + /// render the predictions. Slightly awkward because this code comes from before we had libstd pred_options: [Option; MAX_PREDICTION_OPTIONS], #[cfg(feature = "tts")] @@ -88,6 +91,7 @@ impl InputTracker { last_height: 0, was_grown: false, pred_options: Default::default(), + menu_mode: false, #[cfg(feature="tts")] tts: TtsFrontend::new(xns).unwrap(), } @@ -119,6 +123,9 @@ impl InputTracker { pub fn activate_emoji(&self) { self.gam.raise_menu(gam::EMOJI_MENU_NAME).expect("couldn't activate emoji menu"); } + pub fn set_menu_mode(&mut self, mode: bool) { + self.menu_mode = mode; + } pub fn clear_area(&mut self) -> Result<(), xous::Error> { if let Some(pc) = self.pred_canvas { @@ -292,20 +299,37 @@ impl InputTracker { self.last_trigger_char = Some(self.characters); } '\u{0011}' => { // F1 - self.insert_prediction(0); - do_redraw = true; + if !self.menu_mode { + self.insert_prediction(0); + do_redraw = true; + } else { + log::info!("menu mode return"); + return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0011}"))); + } } '\u{0012}' => { // F2 - self.insert_prediction(1); - do_redraw = true; + if !self.menu_mode { + self.insert_prediction(1); + do_redraw = true; + } else { + return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0012}"))); + } } '\u{0013}' => { // F3 - self.insert_prediction(2); - do_redraw = true; + if !self.menu_mode { + self.insert_prediction(2); + do_redraw = true; + } else { + return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0013}"))); + } } '\u{0014}' => { // F4 - self.insert_prediction(3); - do_redraw = true; + if !self.menu_mode { + self.insert_prediction(3); + do_redraw = true; + } else { + return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0014}"))); + } } '\u{0008}' => { // backspace #[cfg(feature="tts")] @@ -566,7 +590,7 @@ impl InputTracker { } let debug_canvas = false; - if valid_predictions == 0 { + if valid_predictions == 0 && !self.menu_mode { let mut empty_tv = TextView::new(pc, TextBounds::BoundingBox(Rectangle::new(Point::new(0, 1), pc_bounds))); empty_tv.draw_border = false; @@ -575,7 +599,7 @@ impl InputTracker { write!(empty_tv.text, "{}", t!("input.greeting", xous::LANG)).expect("couldn't set up empty TextView"); if debug_canvas { info!("pc canvas {:?}", pc) } self.gam.post_textview(&mut empty_tv).expect("can't draw prediction TextView"); - } else if update_predictor || force_redraw { + } else if update_predictor || force_redraw || self.menu_mode { // alright, first, let's clear the area self.gam.draw_rectangle(pc, pc_clip).expect("couldn't clear predictor area"); @@ -749,6 +773,13 @@ fn main() -> ! { // ignore keyboard events until we've fully initialized } }), + Some(ImefOpcode::SetMenuMode) => msg_scalar_unpack!(msg, arg, _, _, _, { + if arg == 1 { + tracker.set_menu_mode(true); + } else { + tracker.set_menu_mode(false); + } + }), Some(ImefOpcode::Quit) => {log::error!("recevied quit, goodbye!"); break;} None => {log::error!("couldn't convert opcode");} } diff --git a/services/ime-plugin-api/src/lib.rs b/services/ime-plugin-api/src/lib.rs index 965ce1a05..f854899b2 100644 --- a/services/ime-plugin-api/src/lib.rs +++ b/services/ime-plugin-api/src/lib.rs @@ -205,6 +205,9 @@ pub enum ImefOpcode { /// internal use for passing keyboard events from the keyboard callback ProcessKeys, + /// set menu mode -- this turns the predictor area into a menu buttons-like behavior + SetMenuMode, + /// force a redraw of the UI Redraw, @@ -231,6 +234,7 @@ pub trait ImeFrontEndApi { fn send_keyevent(&self, keys: [char; 4]) -> Result<(), xous::Error>; fn conn(&self) -> xous::CID; fn getop_process_keys(&self) -> u32; + fn set_menu_mode(&self, mode: bool) -> Result<(), xous::Error>; } pub const SERVER_NAME_IME_FRONT: &str = "_IME front end_"; @@ -309,6 +313,20 @@ impl ImeFrontEndApi for ImeFrontEnd { .map(|_| ()) } + fn set_menu_mode(&self, mode: bool) -> Result<(), xous::Error> { + xous::send_message( + self.cid, + xous::Message::new_scalar( + ImefOpcode::SetMenuMode.to_usize().unwrap(), + if mode { 1 } else { 0 }, + 0, + 0, + 0, + ), + ) + .map(|_| ()) + } + fn hook_listener_callback(&mut self, cb: fn(String<4000>)) -> Result<(), xous::Error> { if unsafe { INPUT_CB }.is_some() { return Err(xous::Error::MemoryInUse); // can't hook it twice