From 1d4c6c9e88f7b777e0380fd67ddc2292b02e95c6 Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Sat, 15 Aug 2026 00:18:39 -0400 Subject: [PATCH] Support playing roms by dragging into window --- src/app.rs | 3 +++ src/window.rs | 6 +++++- src/window/game.rs | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 008682b..0219926 100644 --- a/src/app.rs +++ b/src/app.rs @@ -424,6 +424,9 @@ impl ApplicationHandler for Application { { self.controllers.handle_key_event(&event); } + WindowEvent::DroppedFile(path) => { + self.app.handle_dropped_file(viewport_id, path); + } WindowEvent::Focused(new_focused) => { self.focused = new_focused.then_some(viewport_id); } diff --git a/src/window.rs b/src/window.rs index 8e4d930..248c781 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; pub use about::AboutWindow; use egui::{Ui, ViewportBuilder}; @@ -47,6 +47,10 @@ pub trait AppWindow { let _ = event; false } + fn handle_dropped_file(&mut self, path: PathBuf) -> bool { + let _ = path; + false + } } pub struct InitArgs<'a> { diff --git a/src/window/game.rs b/src/window/game.rs index e849459..2286528 100644 --- a/src/window/game.rs +++ b/src/window/game.rs @@ -1,5 +1,6 @@ use std::{ ops::{Deref, DerefMut}, + path::PathBuf, sync::{Arc, Mutex, atomic::AtomicBool, mpsc}, time::Duration, }; @@ -214,6 +215,10 @@ impl GameWindow { self.handle_event(viewport_id, |window| window.handle_gamepad_event(event)) } + pub fn handle_dropped_file(&mut self, viewport_id: ViewportId, path: PathBuf) -> bool { + self.handle_event(viewport_id, |window| window.handle_dropped_file(path)) + } + fn handle_event(&mut self, viewport_id: ViewportId, cb: F) -> R where F: FnOnce(&mut dyn AppWindow) -> R, @@ -765,6 +770,12 @@ impl AppWindow for GameWindow { } self.file_picker.set_window(args.window); } + + fn handle_dropped_file(&mut self, path: PathBuf) -> bool { + self.client + .send_command(EmulatorCommand::LoadGame(self.sim_id, path)); + true + } } impl Drop for GameWindow {