Add Store support and unsigned app releases
This commit is contained in:
112
crates/sf-compositor/src/main.rs
Normal file
112
crates/sf-compositor/src/main.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
//! 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 output_mgmt;
|
||||
#[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(())
|
||||
}
|
||||
Reference in New Issue
Block a user