feat: keep the screensaver off while music is playing

Holds org.freedesktop.ScreenSaver.Inhibit, the call Electron apps
such as VacuumTube use to stay awake in Steam's Game Mode, and the
XDG portal's idle inhibit, from play until pause, stop or quit.
zbus 6 cannot connect through Flatpak's D-Bus proxy, so this uses
zbus 5.
This commit is contained in:
Ansho Rei
2026-11-04 12:57:14 +01:00
parent 5a2386e817
commit 62169be746
8 changed files with 351 additions and 2 deletions
+17
View File
@@ -17,6 +17,7 @@ use tokio::runtime::Handle;
use tokio::sync::Semaphore;
use crate::config::{self, Config, Settings};
use crate::inhibit::Inhibitor;
use crate::palette::{Lab, Palette, Role, Tone};
use crate::player::{Player, PlayerEvent};
use crate::prompts::{self, Control, Family, Prompts};
@@ -64,6 +65,9 @@ pub fn shutdown() {
let app = APP.with(|cell| cell.borrow_mut().take());
if let Some(mut app) = app {
app.save_queue();
if let Some(i) = app.inhibitor.take() {
i.shutdown();
}
}
}
@@ -206,6 +210,8 @@ pub struct App {
rt: Handle,
client: Option<Client>,
player: Option<Player>,
/// Keeps the screensaver off while music plays. Taken at shutdown.
inhibitor: Option<Inhibitor>,
screen: Screen,
area: Area,
section: usize,
@@ -257,11 +263,13 @@ impl App {
{
log::warn!("cover cache disabled, cannot create {}: {e}", d.display());
}
let inhibitor = Inhibitor::spawn(&rt);
App {
ui,
rt,
client: None,
player: None,
inhibitor: Some(inhibitor),
screen: Screen::Login,
area: Area::Content,
section: 0,
@@ -1644,6 +1652,15 @@ impl App {
self.save_queue();
}
}
self.sync_inhibit();
}
/// Inhibits only while sound is coming out: a restored queue is loaded
/// paused and held until play is pressed.
fn sync_inhibit(&self) {
if let Some(i) = &self.inhibitor {
i.set(self.current.is_some() && !self.paused && !self.held);
}
}
fn send_now_playing(&self) {