Files
os/crates/sf-compositor/src/main.rs
Tamas Csikel 9c710bedb9 Fennec OS 0.3.2: one app at a time, Raspberry Pi shell packages
- sf-core: only one app runs. Home, another app or a cast closes the app
  on screen (after the switch animation) instead of freezing it in the
  background. A frozen app that held a sound stream stalled PipeWire, so
  the next app could not play at all ("Failed to connect stream: No such
  entity" in Netflex after YouTube was sent home mid-video). The
  background limit and the low-memory watcher go with the freezing.
- Raspberry Pi: image/pi (installer on Raspberry Pi OS), aarch64 shell
  packages (sf-shell-<v>-aarch64, arch in pkg.toml, sf-update installs only
  its own architecture), CI builds the aarch64 shell too.
- sf-compositor: volume OSD, screencopy for remote view, blank cursor.
- SDK v0.1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 19:38:09 +01:00

117 lines
4.2 KiB
Rust

//! sf-compositor: the Fennec OS kiosk Wayland compositor (Smithay).
//!
//! - Every window is full screen. One is visible: the launcher or the app
//! sf-core put in front (`focus <app-id>` on the control socket). Other
//! app windows stay mapped but hidden, so a frozen app comes back at once.
//! - Switching animates: an app zooms and fades in over the launcher, and
//! back out on Home.
//! - Volume keys change the PipeWire volume and show an OSD bar; the Home key
//! (if it reaches us as a key) is sent to the launcher.
//! - wlr-output-management, so `wlr-randr` can list and set display modes
//! and turn the screen off (the launcher's display settings and standby).
//!
//! Usage: `sf-compositor [--winit] -- <startup command>`; exits when the
//! startup command exits (like cage).
#[cfg(target_os = "linux")]
mod control;
#[cfg(target_os = "linux")]
mod osd;
#[cfg(target_os = "linux")]
mod output_mgmt;
#[cfg(target_os = "linux")]
mod screencopy;
#[cfg(target_os = "linux")]
mod state;
#[cfg(target_os = "linux")]
mod udev;
#[cfg(target_os = "linux")]
mod winit;
fn main() -> anyhow::Result<()> {
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info,smithay=warn"));
tracing_subscriber::fmt().with_env_filter(filter).init();
#[cfg(target_os = "linux")]
{
linux_main()
}
#[cfg(not(target_os = "linux"))]
{
anyhow::bail!("sf-compositor needs Linux (DRM/KMS or a Wayland/X11 session for --winit)")
}
}
#[cfg(target_os = "linux")]
fn linux_main() -> anyhow::Result<()> {
use std::time::Duration;
use anyhow::Context;
use smithay::reexports::calloop::EventLoop;
use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
use smithay::reexports::wayland_server::Display;
let mut winit = std::env::var_os("WAYLAND_DISPLAY").is_some() || std::env::var_os("DISPLAY").is_some();
let mut command: Vec<String> = vec![];
let mut args = std::env::args().skip(1);
while let Some(a) = args.next() {
match a.as_str() {
"--winit" => winit = true,
"--drm" => winit = false,
"--" => {
command = args.by_ref().collect();
break;
}
other => command.push(other.to_string()),
}
}
let mut event_loop: EventLoop<state::App> = EventLoop::try_new()?;
let display: Display<state::State> = Display::new()?;
let mut st = state::State::new(&mut event_loop, display)?;
let backend = if winit {
tracing::info!("backend: winit (nested window)");
winit::init(&mut event_loop, &mut st)?
} else {
tracing::info!("backend: DRM/KMS");
udev::init(&mut event_loop, &mut st)?
};
control::listen(&event_loop.handle()).context("control socket")?;
// SAFETY-free env setup: done before any thread is spawned by us.
unsafe {
std::env::set_var("WAYLAND_DISPLAY", &st.socket_name);
std::env::set_var("SMARTFOX_WM_SOCKET", sf_ipc::paths::wm_socket());
}
tracing::info!("WAYLAND_DISPLAY={}", st.socket_name.to_string_lossy());
let mut app = state::App { state: st, backend };
if let Some((prog, rest)) = command.split_first() {
let mut child = std::process::Command::new(prog)
.args(rest)
.spawn()
.with_context(|| format!("starting {prog}"))?;
tracing::info!("started {prog} (pid {})", child.id());
event_loop
.handle()
.insert_source(Timer::from_duration(Duration::from_millis(500)), move |_, _, app: &mut state::App| {
match child.try_wait() {
Ok(Some(status)) => {
tracing::info!("startup command exited ({status}), quitting");
app.state.loop_signal.stop();
TimeoutAction::Drop
}
_ => TimeoutAction::ToDuration(Duration::from_millis(500)),
}
})
.map_err(|e| anyhow::anyhow!("timer: {e}"))?;
}
event_loop.run(Some(Duration::from_millis(16)), &mut app, |app| {
app.after_dispatch();
})?;
let _ = std::fs::remove_file(sf_ipc::paths::wm_socket());
Ok(())
}