Files
Remus/src/main.rs
T
Ansho Rei f6e303bd0f fix: give the window the app id so docks show the remus icon
Without an app id on Wayland, or a WM_CLASS on X11, a dock cannot link
the window to me.anshorei.Fettleshed.Remus.desktop and draws a generic
icon. The desktop file also names the class in StartupWMClass.
2026-11-07 03:34:28 +01:00

96 lines
3.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 shuffle;
mod subsonic;
use std::time::Duration;
/// The Flatpak app id, which is also the name of the desktop file.
const APP_ID: &str = "me.anshorei.Fettleshed.Remus";
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()?;
// Docks match the window to the desktop file by this id, on Wayland as
// the app id and on X11 as the WM_CLASS. It needs the platform that
// AppWindow::new sets up, and has to be set before the window is shown.
slint::set_xdg_app_id(APP_ID)?;
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 {
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(())
}