add "menu mode" option to the IMEF

in "menu mode" the predictive area functions as four menu
option keys instead of dynamic prediction updates.

this patch is mostly working but we need to figure out how to
force a redraw of the predction area when the app is raised,
because we get a stale image from the previous app on context
switch.
This commit is contained in:
bunnie 2022-06-17 12:40:44 +08:00
parent 4c18662430
commit 6e0d025dea
6 changed files with 88 additions and 10 deletions

View file

@ -169,6 +169,8 @@ pub(crate) enum Opcode {
/// used to turn keyboard vibrate on and off /// used to turn keyboard vibrate on and off
Vibe, 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 /// called by a context when it's done with taking the screen; requests the GAM to revert focus to the last-focused app
RevertFocus, RevertFocus,

View file

@ -73,6 +73,8 @@ pub(crate) struct UxContext {
pub audioframe_id: Option<u32>, pub audioframe_id: Option<u32>,
/// opcode ID for focus change /// opcode ID for focus change
pub focuschange_id: Option<u32>, pub focuschange_id: Option<u32>,
/// sets the behavior of the IMEF
pub imef_menu_mode: bool,
} }
pub(crate) const BOOT_CONTEXT_TRUSTLEVEL: u8 = 254; pub(crate) const BOOT_CONTEXT_TRUSTLEVEL: u8 = 254;
@ -154,6 +156,7 @@ impl ContextManager {
focuschange_id: registration.focuschange_id, focuschange_id: registration.focuschange_id,
rawkeys_id: None, rawkeys_id: None,
vibe: false, vibe: false,
imef_menu_mode: false,
}; };
self.contexts.insert(token, ux_context); self.contexts.insert(token, ux_context);
}, },
@ -175,6 +178,7 @@ impl ContextManager {
focuschange_id: registration.focuschange_id, focuschange_id: registration.focuschange_id,
rawkeys_id: registration.rawkeys_id, rawkeys_id: registration.rawkeys_id,
vibe: false, vibe: false,
imef_menu_mode: false,
}; };
if registration.app_name.as_str().unwrap() == MAIN_MENU_NAME { if registration.app_name.as_str().unwrap() == MAIN_MENU_NAME {
@ -202,6 +206,7 @@ impl ContextManager {
focuschange_id: registration.focuschange_id, focuschange_id: registration.focuschange_id,
rawkeys_id: registration.rawkeys_id, rawkeys_id: registration.rawkeys_id,
vibe: false, vibe: false,
imef_menu_mode: false,
}; };
self.contexts.insert(token, ux_context); self.contexts.insert(token, ux_context);
// this check gives permissions to password boxes to render inverted text // this check gives permissions to password boxes to render inverted text
@ -229,6 +234,7 @@ impl ContextManager {
focuschange_id: registration.focuschange_id, focuschange_id: registration.focuschange_id,
rawkeys_id: registration.rawkeys_id, rawkeys_id: registration.rawkeys_id,
vibe: false, vibe: false,
imef_menu_mode: false,
}; };
self.contexts.insert(token, ux_context); self.contexts.insert(token, ux_context);
} }
@ -425,6 +431,7 @@ impl ContextManager {
// revert the keyboard vibe state // revert the keyboard vibe state
self.kbd.set_vibe(context.vibe).expect("couldn't restore keyboard vibe"); 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); log::trace!("raised focus to: {:?}", context);
let last_token = context.app_token; let last_token = context.app_token;
@ -586,6 +593,12 @@ impl ContextManager {
(*context).vibe = set_vibe; (*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, pub(crate) fn raise_menu(&mut self,
name: &str, name: &str,
gfx: &graphics_server::Gfx, gfx: &graphics_server::Gfx,

View file

@ -327,6 +327,16 @@ impl Gam {
ena, 0, 0, 0,) ena, 0, 0, 0,)
).map(|_| ()) ).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 /// 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. /// we might respect that. or maybe not. depends on the GAM's policies.
pub fn relinquish_focus(&self) -> Result<(), xous::Error> { pub fn relinquish_focus(&self) -> Result<(), xous::Error> {

View file

@ -512,6 +512,10 @@ fn wrapped_main() -> ! {
if ena != 0 { context_mgr.vibe(true) } if ena != 0 { context_mgr.vibe(true) }
else { context_mgr.vibe(false) } 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) => { Some(Opcode::RevertFocus) => {
match context_mgr.revert_focus(&gfx, &mut canvases) { match context_mgr.revert_focus(&gfx, &mut canvases) {
Ok(_) => xous::return_scalar(msg.sender, 0).expect("couldn't unblock caller"), Ok(_) => xous::return_scalar(msg.sender, 0).expect("couldn't unblock caller"),

View file

@ -63,6 +63,9 @@ struct InputTracker {
/// keep track if our box was grown /// keep track if our box was grown
was_grown: bool, 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 /// render the predictions. Slightly awkward because this code comes from before we had libstd
pred_options: [Option<String>; MAX_PREDICTION_OPTIONS], pred_options: [Option<String>; MAX_PREDICTION_OPTIONS],
#[cfg(feature = "tts")] #[cfg(feature = "tts")]
@ -88,6 +91,7 @@ impl InputTracker {
last_height: 0, last_height: 0,
was_grown: false, was_grown: false,
pred_options: Default::default(), pred_options: Default::default(),
menu_mode: false,
#[cfg(feature="tts")] #[cfg(feature="tts")]
tts: TtsFrontend::new(xns).unwrap(), tts: TtsFrontend::new(xns).unwrap(),
} }
@ -119,6 +123,9 @@ impl InputTracker {
pub fn activate_emoji(&self) { pub fn activate_emoji(&self) {
self.gam.raise_menu(gam::EMOJI_MENU_NAME).expect("couldn't activate emoji menu"); 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> { pub fn clear_area(&mut self) -> Result<(), xous::Error> {
if let Some(pc) = self.pred_canvas { if let Some(pc) = self.pred_canvas {
@ -292,20 +299,37 @@ impl InputTracker {
self.last_trigger_char = Some(self.characters); self.last_trigger_char = Some(self.characters);
} }
'\u{0011}' => { // F1 '\u{0011}' => { // F1
self.insert_prediction(0); if !self.menu_mode {
do_redraw = true; 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 '\u{0012}' => { // F2
self.insert_prediction(1); if !self.menu_mode {
do_redraw = true; self.insert_prediction(1);
do_redraw = true;
} else {
return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0012}")));
}
} }
'\u{0013}' => { // F3 '\u{0013}' => { // F3
self.insert_prediction(2); if !self.menu_mode {
do_redraw = true; self.insert_prediction(2);
do_redraw = true;
} else {
return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0013}")));
}
} }
'\u{0014}' => { // F4 '\u{0014}' => { // F4
self.insert_prediction(3); if !self.menu_mode {
do_redraw = true; self.insert_prediction(3);
do_redraw = true;
} else {
return Ok(Some(xous_ipc::String::<4000>::from_str("\u{0014}")));
}
} }
'\u{0008}' => { // backspace '\u{0008}' => { // backspace
#[cfg(feature="tts")] #[cfg(feature="tts")]
@ -566,7 +590,7 @@ impl InputTracker {
} }
let debug_canvas = false; let debug_canvas = false;
if valid_predictions == 0 { if valid_predictions == 0 && !self.menu_mode {
let mut empty_tv = TextView::new(pc, let mut empty_tv = TextView::new(pc,
TextBounds::BoundingBox(Rectangle::new(Point::new(0, 1), pc_bounds))); TextBounds::BoundingBox(Rectangle::new(Point::new(0, 1), pc_bounds)));
empty_tv.draw_border = false; 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"); write!(empty_tv.text, "{}", t!("input.greeting", xous::LANG)).expect("couldn't set up empty TextView");
if debug_canvas { info!("pc canvas {:?}", pc) } if debug_canvas { info!("pc canvas {:?}", pc) }
self.gam.post_textview(&mut empty_tv).expect("can't draw prediction TextView"); 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 // alright, first, let's clear the area
self.gam.draw_rectangle(pc, pc_clip).expect("couldn't clear predictor 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 // 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;} Some(ImefOpcode::Quit) => {log::error!("recevied quit, goodbye!"); break;}
None => {log::error!("couldn't convert opcode");} None => {log::error!("couldn't convert opcode");}
} }

View file

@ -205,6 +205,9 @@ pub enum ImefOpcode {
/// internal use for passing keyboard events from the keyboard callback /// internal use for passing keyboard events from the keyboard callback
ProcessKeys, ProcessKeys,
/// set menu mode -- this turns the predictor area into a menu buttons-like behavior
SetMenuMode,
/// force a redraw of the UI /// force a redraw of the UI
Redraw, Redraw,
@ -231,6 +234,7 @@ pub trait ImeFrontEndApi {
fn send_keyevent(&self, keys: [char; 4]) -> Result<(), xous::Error>; fn send_keyevent(&self, keys: [char; 4]) -> Result<(), xous::Error>;
fn conn(&self) -> xous::CID; fn conn(&self) -> xous::CID;
fn getop_process_keys(&self) -> u32; 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_"; pub const SERVER_NAME_IME_FRONT: &str = "_IME front end_";
@ -309,6 +313,20 @@ impl ImeFrontEndApi for ImeFrontEnd {
.map(|_| ()) .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> { fn hook_listener_callback(&mut self, cb: fn(String<4000>)) -> Result<(), xous::Error> {
if unsafe { INPUT_CB }.is_some() { if unsafe { INPUT_CB }.is_some() {
return Err(xous::Error::MemoryInUse); // can't hook it twice return Err(xous::Error::MemoryInUse); // can't hook it twice