implements PLN-0060 focused window ownership API
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::os::SystemOS;
|
||||
use crate::task::TaskId;
|
||||
use crate::windows::{Window, WindowId, WindowOwner};
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::primitives::Rect;
|
||||
@@ -26,6 +27,10 @@ impl<'a> WindowFacade<'a> {
|
||||
self.os.window_manager.focused
|
||||
}
|
||||
|
||||
pub fn focused_window_belongs_to_task(&self, task_id: TaskId) -> bool {
|
||||
self.os.window_manager.focused_window_belongs_to_task(task_id)
|
||||
}
|
||||
|
||||
pub fn close_window(&mut self, id: WindowId) {
|
||||
self.os.window_manager.remove_window(id);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::services::windows::window::{Window, WindowId};
|
||||
use crate::task::TaskId;
|
||||
use crate::windows::WindowOwner;
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::primitives::Rect;
|
||||
@@ -51,6 +52,17 @@ impl WindowManager {
|
||||
window.has_focus = window.id == id;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focused_window_belongs_to_task(&self, task_id: TaskId) -> bool {
|
||||
let Some(focused_id) = self.focused else {
|
||||
return false;
|
||||
};
|
||||
|
||||
self.windows
|
||||
.iter()
|
||||
.find(|window| window.id == focused_id)
|
||||
.is_some_and(|window| window.owner == WindowOwner::Task(task_id))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -103,4 +115,91 @@ mod tests {
|
||||
assert_eq!(wm.windows.len(), 0);
|
||||
assert_eq!(wm.focused, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_returns_false_without_focus() {
|
||||
let mut wm = WindowManager::new();
|
||||
wm.add_window(
|
||||
"Task Window".to_string(),
|
||||
WindowOwner::Task(crate::task::TaskId(1)),
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
assert!(!wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_matches_focused_task_owner() {
|
||||
let mut wm = WindowManager::new();
|
||||
let id = wm.add_window(
|
||||
"Task Window".to_string(),
|
||||
WindowOwner::Task(crate::task::TaskId(1)),
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
wm.set_focus(id);
|
||||
|
||||
assert!(wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_rejects_other_task_owner() {
|
||||
let mut wm = WindowManager::new();
|
||||
let id = wm.add_window(
|
||||
"Task Window".to_string(),
|
||||
WindowOwner::Task(crate::task::TaskId(2)),
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
wm.set_focus(id);
|
||||
|
||||
assert!(!wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_rejects_hub_owner() {
|
||||
let mut wm = WindowManager::new();
|
||||
let id = wm.add_window(
|
||||
"Hub Window".to_string(),
|
||||
WindowOwner::Hub,
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
wm.set_focus(id);
|
||||
|
||||
assert!(!wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_rejects_overlay_owner() {
|
||||
let mut wm = WindowManager::new();
|
||||
let id = wm.add_window(
|
||||
"Overlay Window".to_string(),
|
||||
WindowOwner::Overlay,
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
wm.set_focus(id);
|
||||
|
||||
assert!(!wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focused_window_belongs_to_task_rejects_stale_focus() {
|
||||
let mut wm = WindowManager::new();
|
||||
wm.add_window(
|
||||
"Task Window".to_string(),
|
||||
WindowOwner::Task(crate::task::TaskId(1)),
|
||||
Rect { x: 0, y: 0, w: 10, h: 10 },
|
||||
Color::WHITE,
|
||||
);
|
||||
wm.focused = Some(WindowId(999));
|
||||
|
||||
assert!(!wm.focused_window_belongs_to_task(crate::task::TaskId(1)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user