know what the main window is
This commit is contained in:
parent
e53dff0a30
commit
5e8b3e612c
2 changed files with 41 additions and 5 deletions
|
@ -167,7 +167,7 @@ fn run(args: Args) -> ! {
|
|||
|
||||
let mut window_manager = WindowManager::new(sender, stream);
|
||||
|
||||
let window = window_manager.add(
|
||||
let window = window_manager.add_main(
|
||||
scale_override,
|
||||
Some(Gilrs::new().unwrap()),
|
||||
shader_path,
|
||||
|
|
|
@ -45,6 +45,7 @@ pub struct WindowManager {
|
|||
}
|
||||
|
||||
struct WindowManagerData {
|
||||
main_window: Option<WindowId>,
|
||||
windows: HashMap<WindowId, Arc<WindowData>>,
|
||||
window_data_manager: Arc<RendererBackendManager>,
|
||||
input: Arc<Mutex<WinitInputHelper>>,
|
||||
|
@ -63,6 +64,7 @@ impl WindowManager {
|
|||
Self {
|
||||
event_loop,
|
||||
data: WindowManagerData {
|
||||
main_window: None,
|
||||
windows: HashMap::new(),
|
||||
window_data_manager,
|
||||
input: Arc::new(Mutex::new(WinitInputHelper::new())),
|
||||
|
@ -72,6 +74,23 @@ impl WindowManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn add_main(
|
||||
&mut self,
|
||||
factor: usize,
|
||||
gamepad_handler: Option<Gilrs>,
|
||||
shader_path: Option<PathBuf>,
|
||||
resizable: bool,
|
||||
) -> WindowRenderer {
|
||||
self.data.add(
|
||||
factor,
|
||||
gamepad_handler,
|
||||
shader_path,
|
||||
resizable,
|
||||
&self.event_loop,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn add(
|
||||
&mut self,
|
||||
factor: usize,
|
||||
|
@ -85,6 +104,7 @@ impl WindowManager {
|
|||
shader_path,
|
||||
resizable,
|
||||
&self.event_loop,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -109,6 +129,7 @@ impl WindowManagerData {
|
|||
shader_path: Option<PathBuf>,
|
||||
resizable: bool,
|
||||
event_loop: &EventLoop<()>,
|
||||
is_main: bool,
|
||||
) -> WindowRenderer {
|
||||
let (r, info) = WindowRenderer::new(
|
||||
factor,
|
||||
|
@ -120,6 +141,9 @@ impl WindowManagerData {
|
|||
resizable,
|
||||
);
|
||||
self.windows.insert(info.id, info.data);
|
||||
if is_main {
|
||||
self.main_window = Some(info.id);
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
|
@ -134,7 +158,11 @@ impl WindowManagerData {
|
|||
|
||||
if let Ok(mut i) = self.input.lock() {
|
||||
if i.update(&event) && i.key_pressed(VirtualKeyCode::Space) {
|
||||
self.windows.iter().for_each(|(_id, window)| {
|
||||
if let Some(window) = self
|
||||
.main_window
|
||||
.as_ref()
|
||||
.and_then(|id| self.windows.get(id))
|
||||
{
|
||||
if let Ok(buf) = window.last_buf.lock() {
|
||||
if let Ok(size) = window.rendered_size.read() {
|
||||
let image = ImageBuffer::<image::Rgba<u8>, _>::from_raw(
|
||||
|
@ -169,7 +197,7 @@ impl WindowManagerData {
|
|||
.expect("Could not save screenshot!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,9 +207,17 @@ impl WindowManagerData {
|
|||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id: _,
|
||||
window_id,
|
||||
} => {
|
||||
if self.main_window.is_some_and(|v| v == window_id) {
|
||||
self.sender.send(EmulatorMessage::Exit).unwrap();
|
||||
} else if let Some(window) = self
|
||||
.main_window
|
||||
.as_ref()
|
||||
.and_then(|id| self.windows.get(id))
|
||||
{
|
||||
window.window.focus_window();
|
||||
}
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
if run_return {
|
||||
|
|
Loading…
Add table
Reference in a new issue