diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e82d7d..16dea25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ One section per version, newest first. +## v0.8.4 (2026-11-04) + +### Bug fixes + +- While another app or a game is in front, the controller no longer also controls remus. Music keeps playing in the background, and media keys still work. + ## v0.8.3 (2026-11-04) ### Bug fixes diff --git a/Cargo.lock b/Cargo.lock index 01e6c2b..1e8c8fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "remus" -version = "0.8.3" +version = "0.8.4" dependencies = [ "anyhow", "directories", @@ -4907,6 +4907,7 @@ dependencies = [ "const-field-offset", "i-slint-backend-linuxkms", "i-slint-backend-selector", + "i-slint-backend-winit", "i-slint-common", "i-slint-core", "i-slint-core-macros", diff --git a/Cargo.toml b/Cargo.toml index 6f76e4e..0bca9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remus" -version = "0.8.3" +version = "0.8.4" edition = "2024" license = "MIT" @@ -18,7 +18,7 @@ md5 = "0.8.1" reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls"] } serde = { version = "1.0.229", features = ["derive"] } serde_json = "1.0.154" -slint = "1.18.1" +slint = { version = "1.18.1", features = ["unstable-winit-030"] } tokio = { version = "1.54.1", features = ["rt-multi-thread", "sync", "macros", "time"] } toml = "1.1.8" zbus = { version = "5.19.0", default-features = false, features = ["tokio"] } diff --git a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml index 24ac08d..2b8534f 100644 --- a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml +++ b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml @@ -20,6 +20,7 @@ + diff --git a/src/app.rs b/src/app.rs index 6646b63..8df900b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -289,6 +289,9 @@ pub struct App { volume_save_timer: Timer, /// Keyboard keys or the buttons of the controller used last. prompts: Prompts, + /// Whether the window has focus. True until the windowing system says + /// otherwise, so a system that never says still gets controller input. + window_active: bool, /// Decoded hint icons, so a selection move does not parse SVG again. icons: RefCell>>, settings: Settings, @@ -383,6 +386,7 @@ impl App { art_waiting: false, flip_timer: Timer::default(), prompts: Prompts::Keyboard, + window_active: true, icons: RefCell::default(), settings: config::load_settings(), fade: Fade { @@ -701,10 +705,30 @@ impl App { /// A button pressed on a controller of this family. pub fn pad_action(&mut self, a: Action, family: Family) { + // Meant for whatever is in front: a game, Steam, another app. + if !self.window_active { + return; + } self.set_prompts(Prompts::Pad(family)); self.action(a); } + /// The window gained or lost focus. Only the controller cares: keys only + /// arrive while it has focus anyway. + pub fn set_window_active(&mut self, active: bool) { + if active != self.window_active { + log::info!( + "window {}", + if active { + "in front, controller on" + } else { + "in the background, controller off" + } + ); + self.window_active = active; + } + } + /// A controller connected (its family) or the last one disconnected. pub fn pad_present(&mut self, family: Option) { self.set_prompts(family.map_or(Prompts::Keyboard, Prompts::Pad)); diff --git a/src/main.rs b/src/main.rs index 4cc904b..1280ea8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,18 @@ fn main() -> anyhow::Result<()> { let ui = AppWindow::new()?; ui.set_version(env!("CARGO_PKG_VERSION").into()); app::install(&ui, rt.handle().clone()); + // The controller is read from the device, whichever window is in front, so + // the app needs to know when another one is, to leave the presses to it. + { + use slint::winit_030::{EventResult, WinitWindowAccessor, winit::event::WindowEvent}; + ui.window().on_winit_window_event(|_, event| { + if let WindowEvent::Focused(focused) = *event { + log::debug!("window focused: {focused}"); + app::with_app(move |app| app.set_window_active(focused)); + } + EventResult::Propagate + }); + } input::spawn_gamepad(|ev| { let _ = slint::invoke_from_event_loop(move || { app::with_app(move |app| match ev {