fix hub home launch input arming
This commit is contained in:
parent
8f74bd2b22
commit
2e214b544b
@ -416,12 +416,24 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hub_home_launches_shell_a_as_native_shell_task_window() {
|
fn hub_home_does_not_launch_shell_before_home_input_is_armed() {
|
||||||
let (mut firmware, mut hardware) = hub_home_firmware();
|
let (mut firmware, mut hardware) = hub_home_firmware();
|
||||||
let signals = InputSignals { a_signal: true, ..Default::default() };
|
let signals = InputSignals { f_signal: true, x_pos: 112, y_pos: 108, ..Default::default() };
|
||||||
|
|
||||||
firmware.tick(&signals, &mut hardware);
|
firmware.tick(&signals, &mut hardware);
|
||||||
|
|
||||||
|
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||||
|
assert_eq!(firmware.os.windows().window_count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hub_home_click_launches_shell_a_as_native_shell_task_window() {
|
||||||
|
let (mut firmware, mut hardware) = hub_home_firmware();
|
||||||
|
firmware.tick(&InputSignals::default(), &mut hardware);
|
||||||
|
|
||||||
|
let signals = InputSignals { f_signal: true, x_pos: 112, y_pos: 108, ..Default::default() };
|
||||||
|
firmware.tick(&signals, &mut hardware);
|
||||||
|
|
||||||
let task_id = match &firmware.state {
|
let task_id = match &firmware.state {
|
||||||
FirmwareState::ShellRunning(step) => step.task_id,
|
FirmwareState::ShellRunning(step) => step.task_id,
|
||||||
other => panic!("expected ShellRunning state, got {:?}", other),
|
other => panic!("expected ShellRunning state, got {:?}", other),
|
||||||
@ -438,26 +450,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hub_home_click_launches_shell_a_as_native_shell_task_window() {
|
fn hub_home_click_launches_shell_b_as_native_shell_task_window() {
|
||||||
let (mut firmware, mut hardware) = hub_home_firmware();
|
let (mut firmware, mut hardware) = hub_home_firmware();
|
||||||
let signals = InputSignals { f_signal: true, x_pos: 112, y_pos: 108, ..Default::default() };
|
firmware.tick(&InputSignals::default(), &mut hardware);
|
||||||
|
|
||||||
firmware.tick(&signals, &mut hardware);
|
|
||||||
|
|
||||||
let task_id = match &firmware.state {
|
|
||||||
FirmwareState::ShellRunning(step) => step.task_id,
|
|
||||||
other => panic!("expected ShellRunning state, got {:?}", other),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert!(firmware.os.windows().focused_window_belongs_to_task(task_id));
|
|
||||||
assert_eq!(firmware.os.windows().windows()[0].title, "ShellA");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn hub_home_launches_shell_b_as_native_shell_task_window() {
|
|
||||||
let (mut firmware, mut hardware) = hub_home_firmware();
|
|
||||||
let signals = InputSignals { b_signal: true, ..Default::default() };
|
|
||||||
|
|
||||||
|
let signals = InputSignals { f_signal: true, x_pos: 256, y_pos: 108, ..Default::default() };
|
||||||
firmware.tick(&signals, &mut hardware);
|
firmware.tick(&signals, &mut hardware);
|
||||||
|
|
||||||
let task_id = match &firmware.state {
|
let task_id = match &firmware.state {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ pub struct HubHomeStep;
|
|||||||
impl HubHomeStep {
|
impl HubHomeStep {
|
||||||
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
||||||
ctx.os.log(LogLevel::Info, LogSource::Hub, 0, "Entering HubHome".to_string());
|
ctx.os.log(LogLevel::Info, LogSource::Hub, 0, "Entering HubHome".to_string());
|
||||||
|
ctx.hub.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
||||||
|
|||||||
@ -25,7 +25,9 @@ const COLOR_BUTTON: Color = Color::rgb(45, 59, 82);
|
|||||||
const COLOR_BUTTON_ACTIVE: Color = Color::rgb(72, 91, 122);
|
const COLOR_BUTTON_ACTIVE: Color = Color::rgb(72, 91, 122);
|
||||||
|
|
||||||
/// PrometeuHub: Launcher and system UI environment.
|
/// PrometeuHub: Launcher and system UI environment.
|
||||||
pub struct PrometeuHub;
|
pub struct PrometeuHub {
|
||||||
|
home_input_armed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum NativeShellApp {
|
pub enum NativeShellApp {
|
||||||
@ -87,11 +89,11 @@ impl Default for PrometeuHub {
|
|||||||
|
|
||||||
impl PrometeuHub {
|
impl PrometeuHub {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self
|
Self { home_input_armed: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
// Initializes the Window System and lists apps
|
self.home_input_armed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gui_update(
|
pub fn gui_update(
|
||||||
@ -102,19 +104,23 @@ impl PrometeuHub {
|
|||||||
hw.gfx_mut().clear(Color::BLACK);
|
hw.gfx_mut().clear(Color::BLACK);
|
||||||
|
|
||||||
let in_shell = os.windows().focused_window().is_some();
|
let in_shell = os.windows().focused_window().is_some();
|
||||||
|
|
||||||
|
if !in_shell {
|
||||||
|
if !self.home_input_armed {
|
||||||
|
self.home_input_armed = !activation_input_down(hw);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.home_input_armed = false;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(action) =
|
if let Some(action) =
|
||||||
action_for_click(in_shell, hw.touch().x(), hw.touch().y(), hw.touch().f().pressed)
|
action_for_click(in_shell, hw.touch().x(), hw.touch().y(), hw.touch().f().pressed)
|
||||||
{
|
{
|
||||||
return Some(action);
|
return Some(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !in_shell && hw.pad().a().pressed {
|
None
|
||||||
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellA))
|
|
||||||
} else if !in_shell && hw.pad().b().pressed {
|
|
||||||
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellB))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, os: &mut SystemOS, hw: &mut dyn HardwareBridge) {
|
pub fn render(&mut self, os: &mut SystemOS, hw: &mut dyn HardwareBridge) {
|
||||||
@ -182,6 +188,10 @@ fn rect_contains(rect: Rect, x: i32, y: i32) -> bool {
|
|||||||
x >= rect.x && x < rect.x + rect.w && y >= rect.y && y < rect.y + rect.h
|
x >= rect.x && x < rect.x + rect.w && y >= rect.y && y < rect.y + rect.h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn activation_input_down(hw: &dyn HardwareBridge) -> bool {
|
||||||
|
hw.touch().f().down || hw.pad().a().down || hw.pad().b().down || hw.pad().start().down
|
||||||
|
}
|
||||||
|
|
||||||
fn render_home(gfx: &mut dyn GfxBridge, pointer_x: i32, pointer_y: i32) {
|
fn render_home(gfx: &mut dyn GfxBridge, pointer_x: i32, pointer_y: i32) {
|
||||||
gfx.fill_rect(VIEWPORT.x, VIEWPORT.y, VIEWPORT.w, VIEWPORT.h, COLOR_BG);
|
gfx.fill_rect(VIEWPORT.x, VIEWPORT.y, VIEWPORT.w, VIEWPORT.h, COLOR_BG);
|
||||||
draw_panel(gfx, TITLE_PANEL, COLOR_PANEL_DARK, COLOR_BORDER);
|
draw_panel(gfx, TITLE_PANEL, COLOR_PANEL_DARK, COLOR_BORDER);
|
||||||
@ -275,6 +285,12 @@ mod tests {
|
|||||||
assert_eq!(action_for_click(false, SHELL_A_BUTTON.x, SHELL_A_BUTTON.y, false), None);
|
assert_eq!(action_for_click(false, SHELL_A_BUTTON.x, SHELL_A_BUTTON.y, false), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hub_starts_with_home_input_disarmed() {
|
||||||
|
let hub = PrometeuHub::new();
|
||||||
|
assert!(!hub.home_input_armed);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn close_button_click_emits_close_only_in_shell() {
|
fn close_button_click_emits_close_only_in_shell() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user