Files
Remus/src/main.rs
T
Ansho Rei 0bcba21f1a feat: control playback through MPRIS
Remus owns org.mpris.MediaPlayer2.remus on the session bus and serves
the root and player interfaces: play, pause, play-pause, stop, next,
previous and quit, with the playback status, track metadata, position
and volume. Desktops route media keys to the active MPRIS player, and
headphone buttons arrive as media keys, so this is how they reach remus.

Reading the headphones' input devices directly was ruled out: keyboard
type devices, AVRCP included, are root:input, and only gamepads are
opened up to the logged-in user. Seeking is not offered (CanSeek false).

The Flatpak gets --own-name for the bus name.
2026-11-04 17:57:32 +01:00

76 lines
2.3 KiB
Rust

slint::include_modules!();
mod app;
mod config;
mod devscript;
mod inhibit;
mod input;
mod mpris;
mod palette;
mod player;
mod prompts;
mod saved_queue;
mod subsonic;
use std::time::Duration;
fn main() -> anyhow::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("remus=info")).init();
let dev_script = std::env::var("REMUS_DEV_SCRIPT").ok();
let windowed = std::env::args().any(|a| a == "--windowed") || std::env::var_os("REMUS_WINDOWED").is_some();
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.enable_all()
.build()?;
let ui = AppWindow::new()?;
ui.set_version(env!("CARGO_PKG_VERSION").into());
app::install(&ui, rt.handle().clone());
input::spawn_gamepad(|ev| {
let _ = slint::invoke_from_event_loop(move || {
app::with_app(move |app| match ev {
input::PadEvent::Action(action, family) => app.pad_action(action, family),
input::PadEvent::Present(family) => app.pad_present(family),
})
});
});
// Kept alive until the event loop ends.
let fullscreen_retry = slint::Timer::default();
if !windowed {
ui.window().set_fullscreen(true);
// Compositors ignore the request until the window is mapped, and a
// tiling one (COSMIC) can take the window back right after granting
// it. Keep asking until fullscreen has held for a second, giving up
// after five. Then stop, so a later F11 to leave fullscreen sticks.
let weak = ui.as_weak();
let (mut ticks, mut held) = (0, 0);
fullscreen_retry.start(slint::TimerMode::Repeated, Duration::from_millis(100), move || {
let Some(ui) = weak.upgrade() else { return };
if ticks >= 50 || held >= 10 {
return;
}
ticks += 1;
if ui.window().is_fullscreen() {
held += 1;
return;
}
held = 0;
log::debug!("not fullscreen yet ({:?}), asking again", ui.window().size());
ui.window().set_fullscreen(false);
ui.window().set_fullscreen(true);
});
}
if let Some(script) = dev_script {
devscript::run(&ui, &script);
}
ui.run()?;
app::shutdown();
drop(rt);
Ok(())
}