headless mode

This commit is contained in:
galister
2025-05-30 22:14:04 +09:00
parent b0f5e23ffd
commit f29364d772
4 changed files with 62 additions and 45 deletions

View File

@@ -59,13 +59,18 @@ impl<T> OverlayContainer<T>
where
T: Default,
{
pub fn new(app: &mut AppState) -> anyhow::Result<Self> {
pub fn new(app: &mut AppState, headless: bool) -> anyhow::Result<Self> {
let mut overlays = IdMap::new();
let mut wl = create_wl_client();
let keymap;
let mut show_screens = app.session.config.show_screens.clone();
let keymap = None;
app.screens.clear();
if headless {
log::info!("Running in headless mode; keyboard will be en-US");
} else {
let mut wl = create_wl_client();
let data = if let Some(wl) = wl.as_mut() {
log::info!("Wayland detected.");
keymap = get_keymap_wl()
@@ -86,7 +91,6 @@ where
}
};
let mut show_screens = app.session.config.show_screens.clone();
if show_screens.is_empty() {
if let Some((_, s, _)) = data.screens.first() {
show_screens.arc_set(s.name.clone());
@@ -107,6 +111,7 @@ where
);
app.screens.push(meta);
}
}
let anchor = create_anchor(app)?;
overlays.insert(anchor.state.id.0, anchor);

View File

@@ -62,7 +62,11 @@ pub fn openvr_uninstall() {
}
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn openvr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(), BackendError> {
pub fn openvr_run(
running: Arc<AtomicBool>,
show_by_default: bool,
headless: bool,
) -> Result<(), BackendError> {
let app_type = EVRApplicationType::VRApplication_Overlay;
let Ok(context) = ovr_overlay::Context::init(app_type) else {
log::warn!("Will not use OpenVR: Context init failed");
@@ -112,7 +116,7 @@ pub fn openvr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
let _ = install_manifest(&mut app_mgr);
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state)?;
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state, headless)?;
let mut notifications = NotificationManager::new();
notifications.run_dbus();
notifications.run_udp();

View File

@@ -57,7 +57,11 @@ struct XrState {
}
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn openxr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(), BackendError> {
pub fn openxr_run(
running: Arc<AtomicBool>,
show_by_default: bool,
headless: bool,
) -> Result<(), BackendError> {
let (xr_instance, system) = match helpers::init_xr() {
Ok((xr_instance, system)) => (xr_instance, system),
Err(e) => {
@@ -90,7 +94,7 @@ pub fn openxr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
);
}
let mut overlays = OverlayContainer::<OpenXrOverlayData>::new(&mut app)?;
let mut overlays = OverlayContainer::<OpenXrOverlayData>::new(&mut app, headless)?;
let mut lines = LinePool::new(app.graphics.clone())?;
let mut notifications = NotificationManager::new();

View File

@@ -70,6 +70,10 @@ struct Args {
#[arg(long)]
multi: bool,
/// Disable desktop access altogether.
#[arg(long)]
headless: bool,
/// Path to write logs to
#[arg(short, long, value_name = "FILE_PATH")]
log_to: Option<String>,
@@ -139,7 +143,7 @@ fn auto_run(running: Arc<AtomicBool>, args: Args) {
if !args_get_openvr(&args) {
use crate::backend::openxr::openxr_run;
tried_xr = true;
match openxr_run(running.clone(), args.show) {
match openxr_run(running.clone(), args.show, args.headless) {
Ok(()) => return,
Err(BackendError::NotSupported) => (),
Err(e) => {
@@ -153,7 +157,7 @@ fn auto_run(running: Arc<AtomicBool>, args: Args) {
if !args_get_openxr(&args) {
use crate::backend::openvr::openvr_run;
tried_vr = true;
match openvr_run(running, args.show) {
match openvr_run(running, args.show, args.headless) {
Ok(()) => return,
Err(BackendError::NotSupported) => (),
Err(e) => {