@@ -102,6 +102,7 @@ pub struct Platform {
fonts: Arc<dyn super::FontSystem>,
current_clipboard_item: Mutex<Option<ClipboardItem>>,
cursor: Mutex<CursorStyle>,
+ active_window_id: Arc<Mutex<Option<usize>>>,
}
impl Platform {
@@ -111,6 +112,7 @@ impl Platform {
fonts: Arc::new(super::current::FontSystem::new()),
current_clipboard_item: Default::default(),
cursor: Mutex::new(CursorStyle::Arrow),
+ active_window_id: Default::default(),
}
}
}
@@ -144,22 +146,31 @@ impl super::Platform for Platform {
fn open_window(
&self,
- _: usize,
+ id: usize,
options: super::WindowOptions,
_executor: Rc<super::executor::Foreground>,
) -> Box<dyn super::Window> {
- Box::new(Window::new(match options.bounds {
- WindowBounds::Maximized | WindowBounds::Fullscreen => vec2f(1024., 768.),
- WindowBounds::Fixed(rect) => rect.size(),
- }))
+ *self.active_window_id.lock() = Some(id);
+ Box::new(Window::new(
+ id,
+ match options.bounds {
+ WindowBounds::Maximized | WindowBounds::Fullscreen => vec2f(1024., 768.),
+ WindowBounds::Fixed(rect) => rect.size(),
+ },
+ self.active_window_id.clone(),
+ ))
}
fn main_window_id(&self) -> Option<usize> {
- None
+ self.active_window_id.lock().clone()
}
- fn add_status_item(&self) -> Box<dyn crate::platform::Window> {
- Box::new(Window::new(vec2f(24., 24.)))
+ fn add_status_item(&self, id: usize) -> Box<dyn crate::platform::Window> {
+ Box::new(Window::new(
+ id,
+ vec2f(24., 24.),
+ self.active_window_id.clone(),
+ ))
}
fn write_to_clipboard(&self, item: ClipboardItem) {
@@ -245,6 +256,7 @@ impl super::Screen for Screen {
}
pub struct Window {
+ id: usize,
pub(crate) size: Vector2F,
scale_factor: f32,
current_scene: Option<crate::Scene>,
@@ -258,11 +270,13 @@ pub struct Window {
pub(crate) title: Option<String>,
pub(crate) edited: bool,
pub(crate) pending_prompts: RefCell<VecDeque<oneshot::Sender<usize>>>,
+ active_window_id: Arc<Mutex<Option<usize>>>,
}
impl Window {
- pub fn new(size: Vector2F) -> Self {
+ pub fn new(id: usize, size: Vector2F, active_window_id: Arc<Mutex<Option<usize>>>) -> Self {
Self {
+ id,
size,
event_handlers: Default::default(),
resize_handlers: Default::default(),
@@ -276,6 +290,7 @@ impl Window {
title: None,
edited: false,
pending_prompts: Default::default(),
+ active_window_id,
}
}
@@ -326,7 +341,9 @@ impl super::Window for Window {
done_rx
}
- fn activate(&self) {}
+ fn activate(&self) {
+ *self.active_window_id.lock() = Some(self.id);
+ }
fn set_title(&mut self, title: &str) {
self.title = Some(title.to_string())