implements PLN-0063 hub mouse click routing

This commit is contained in:
2026-05-15 17:54:25 +01:00
parent edfac5a99b
commit 414bdd0333
4 changed files with 130 additions and 12 deletions
@@ -1,8 +1,13 @@
use crate::{CrashReport, SystemOS};
use prometeu_hal::color::Color;
use prometeu_hal::primitives::Rect;
use prometeu_hal::{HardwareBridge, InputSignals};
use prometeu_vm::VirtualMachine;
const SHELL_A_BUTTON: Rect = Rect { x: 112, y: 108, w: 112, h: 48 };
const SHELL_B_BUTTON: Rect = Rect { x: 256, y: 108, w: 112, h: 48 };
const CLOSE_BUTTON: Rect = Rect { x: 420, y: 24, w: 16, h: 16 };
/// PrometeuHub: Launcher and system UI environment.
pub struct PrometeuHub;
@@ -63,14 +68,21 @@ impl PrometeuHub {
pub fn gui_update(
&mut self,
_os: &mut SystemOS,
os: &mut SystemOS,
hw: &mut dyn HardwareBridge,
) -> Option<SystemProfileAction> {
hw.gfx_mut().clear(Color::BLACK);
if hw.pad().a().pressed {
let in_shell = os.windows().focused_window().is_some();
if let Some(action) =
action_for_click(in_shell, hw.touch().x(), hw.touch().y(), hw.touch().f().pressed)
{
return Some(action);
}
if !in_shell && hw.pad().a().pressed {
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellA))
} else if hw.pad().b().pressed {
} else if !in_shell && hw.pad().b().pressed {
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellB))
} else {
None
@@ -102,7 +114,7 @@ impl PrometeuHub {
if os.windows().focused_window().is_some() {
if hw.pad().start().down {
action = Some(SystemProfileAction::CloseShell);
} else {
} else if action != Some(SystemProfileAction::CloseShell) {
crash = os.vm().tick(vm, signals, hw);
}
}
@@ -113,3 +125,77 @@ impl PrometeuHub {
SystemProfileUpdate { crash, action }
}
}
fn action_for_click(in_shell: bool, x: i32, y: i32, pressed: bool) -> Option<SystemProfileAction> {
if !pressed {
return None;
}
if in_shell {
return rect_contains(CLOSE_BUTTON, x, y).then_some(SystemProfileAction::CloseShell);
}
if rect_contains(SHELL_A_BUTTON, x, y) {
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellA))
} else if rect_contains(SHELL_B_BUTTON, x, y) {
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellB))
} else {
None
}
}
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
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn shell_a_button_click_emits_launch_action() {
assert_eq!(
action_for_click(false, SHELL_A_BUTTON.x, SHELL_A_BUTTON.y, true),
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellA))
);
}
#[test]
fn shell_b_button_click_emits_launch_action() {
assert_eq!(
action_for_click(
false,
SHELL_B_BUTTON.x + SHELL_B_BUTTON.w - 1,
SHELL_B_BUTTON.y,
true
),
Some(SystemProfileAction::LaunchNativeShell(NativeShellApp::ShellB))
);
}
#[test]
fn button_hit_test_excludes_right_and_bottom_edges() {
assert_eq!(
action_for_click(false, SHELL_A_BUTTON.x + SHELL_A_BUTTON.w, SHELL_A_BUTTON.y, true),
None
);
assert_eq!(
action_for_click(false, SHELL_A_BUTTON.x, SHELL_A_BUTTON.y + SHELL_A_BUTTON.h, true),
None
);
}
#[test]
fn held_pointer_does_not_emit_click_action() {
assert_eq!(action_for_click(false, SHELL_A_BUTTON.x, SHELL_A_BUTTON.y, false), None);
}
#[test]
fn close_button_click_emits_close_only_in_shell() {
assert_eq!(
action_for_click(true, CLOSE_BUTTON.x, CLOSE_BUTTON.y, true),
Some(SystemProfileAction::CloseShell)
);
assert_eq!(action_for_click(false, CLOSE_BUTTON.x, CLOSE_BUTTON.y, true), None);
}
}