settings tab buttons; autorestart

This commit is contained in:
galister
2026-01-08 02:19:00 +09:00
parent cd8480100f
commit 2f010bb42b
20 changed files with 212 additions and 88 deletions

View File

@@ -113,7 +113,7 @@
<Hmd idx="0" />
<LeftHand idx="1" />
<RightHand idx="2" />
<Track idx="3" />
<Tracker idx="3" />
</div>
<!-- All other elements inside the container -->

View File

@@ -10,10 +10,10 @@ use ovr_overlay::{
},
system::SystemManager,
};
use wlx_common::config_io;
use crate::{
backend::input::{Haptics, TrackedDevice, TrackedDeviceRole},
config_io,
state::AppState,
};

View File

@@ -4,7 +4,7 @@ use anyhow::{Context, bail};
use json::{array, object};
use ovr_overlay::applications::ApplicationsManager;
use crate::config_io;
use wlx_common::config_io;
const APP_KEY: &str = "galister.wlxoverlay-s";

View File

@@ -8,10 +8,10 @@ use glam::{Affine3A, Quat, Vec3, bool};
use libmonado as mnd;
use openxr::{self as xr, Quaternionf, Vector2f, Vector3f};
use serde::{Deserialize, Serialize};
use wlx_common::config_io;
use crate::{
backend::input::{Haptics, Pointer, TrackedDevice, TrackedDeviceRole},
config_io,
state::{AppSession, AppState},
};

View File

@@ -11,10 +11,10 @@ use vulkano::{
pipeline::graphics::color_blend::AttachmentBlend,
};
use wgui::gfx::{cmd::WGfxClearMode, pipeline::WPipelineCreateInfo};
use wlx_common::config_io;
use crate::{
backend::openxr::{helpers::translation_rotation_to_posef, swapchain::SwapchainOpts},
config_io,
graphics::{ExtentExt, GpuFutures, dds::WlxCommandBufferDds},
state::AppState,
};

View File

@@ -1,4 +1,3 @@
use crate::config_io;
use config::{Config, File};
use log::error;
use serde::{Deserialize, Serialize};
@@ -6,6 +5,7 @@ use std::path::PathBuf;
use wlx_common::{
astr_containers::AStrMap,
config::{GeneralConfig, SerializedWindowSet, SerializedWindowStates},
config_io,
overlays::BackendAttribValue,
};

View File

@@ -1,54 +0,0 @@
use log::error;
use std::{path::PathBuf, sync::LazyLock};
pub enum ConfigRoot {
Generic,
#[allow(dead_code)]
WayVR,
}
const FALLBACK_CONFIG_PATH: &str = "/tmp/wlxoverlay";
static CONFIG_ROOT_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
if let Some(mut dir) = xdg::BaseDirectories::new().get_config_home() {
dir.push("wlxoverlay");
return dir;
}
//Return fallback config path
error!("Err: Failed to find config path, using {FALLBACK_CONFIG_PATH}");
PathBuf::from(FALLBACK_CONFIG_PATH)
});
pub fn get_config_root() -> PathBuf {
CONFIG_ROOT_PATH.clone()
}
impl ConfigRoot {
pub fn get_conf_d_path(&self) -> PathBuf {
get_config_root().join(match self {
Self::Generic => "conf.d",
Self::WayVR => "wayvr.conf.d",
})
}
// Make sure config directory is present and return root config path
pub fn ensure_dir(&self) -> PathBuf {
let path = get_config_root();
let _ = std::fs::create_dir(&path);
let path_conf_d = self.get_conf_d_path();
let _ = std::fs::create_dir(path_conf_d);
path
}
}
pub fn get_config_file_path(filename: &str) -> PathBuf {
get_config_root().join(filename)
}
pub fn load(filename: &str) -> Option<String> {
let path = get_config_file_path(filename);
log::info!("Loading config: {}", path.to_string_lossy());
std::fs::read_to_string(path).ok()
}

View File

@@ -9,7 +9,7 @@ use std::{
use anyhow::Context;
use serde::{Deserialize, Serialize};
use wgui::gfx::WGfx;
use wlx_common::{common::LeftRight, config::GeneralConfig, windowing::Positioning};
use wlx_common::{common::LeftRight, config::GeneralConfig, config_io, windowing::Positioning};
use crate::{
backend::{
@@ -17,7 +17,6 @@ use crate::{
wayvr::{self, WvrServerState},
},
config::load_config_with_conf_d,
config_io,
graphics::WGfxExtras,
ipc::{event_queue::SyncEventQueue, signal::WayVRSignal},
};

View File

@@ -25,9 +25,8 @@ use wgui::{
use wlx_common::overlays::ToastTopic;
use crate::{
RUNNING,
RESTART, RUNNING,
backend::{
XrBackend,
task::{OverlayTask, PlayspaceTask, TaskType, ToggleMode},
wayvr::process::KillSignal,
},
@@ -572,16 +571,8 @@ pub(super) fn setup_custom_button<S: 'static>(
if !test_button(data) || !test_duration(&button, app) {
return Ok(EventResult::Pass);
}
let runtime = match app.xr_backend {
XrBackend::OpenVR => "--openvr",
XrBackend::OpenXR => "--openxr",
};
Command::new("/proc/self/exe")
.arg(runtime) // ensure same runtime
.arg("--replace") // SIGTERM the previous process
.arg("--show");
RUNNING.store(false, Ordering::Relaxed);
RESTART.store(true, Ordering::Relaxed);
Ok(EventResult::Consumed)
}),

View File

@@ -20,7 +20,6 @@
mod app_misc;
mod backend;
mod config;
mod config_io;
mod graphics;
mod gui;
mod ipc;
@@ -34,7 +33,9 @@ mod windowing;
mod config_wayvr;
use std::{
os::unix::process::CommandExt,
path::PathBuf,
process::Command,
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
};
@@ -45,10 +46,11 @@ use sysinfo::Pid;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
use crate::subsystem::dbus::DbusConnector;
use crate::{backend::XrBackend, subsystem::dbus::DbusConnector};
pub static FRAME_COUNTER: AtomicUsize = AtomicUsize::new(0);
pub static RUNNING: AtomicBool = AtomicBool::new(true);
pub static RESTART: AtomicBool = AtomicBool::new(false);
pub static KEYMAP_CHANGE: AtomicBool = AtomicBool::new(false);
/// The lightweight desktop overlay for OpenVR and OpenXR
@@ -121,13 +123,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
setup_signal_hooks()?;
auto_run(args);
let mut used_backend = None;
auto_run(args, &mut used_backend);
if RESTART.load(Ordering::Relaxed) {
log::warn!("Restarting...");
let exe = std::env::current_exe()?;
let mut args = vec!["--replace", "--show"];
match used_backend {
Some(XrBackend::OpenXR) => args.push("--openxr"),
Some(XrBackend::OpenVR) => args.push("--openvr"),
_ => {}
};
let _ = Command::new(exe).args(args).spawn();
}
Ok(())
}
#[allow(unused_mut, clippy::similar_names)]
fn auto_run(args: Args) {
fn auto_run(args: Args, used_backend: &mut Option<XrBackend>) {
let mut tried_xr = false;
let mut tried_vr = false;
@@ -136,9 +154,13 @@ fn auto_run(args: Args) {
use crate::backend::{BackendError, openxr::openxr_run};
tried_xr = true;
match openxr_run(args.show, args.headless) {
Ok(()) => return,
Ok(()) => {
used_backend.replace(XrBackend::OpenXR);
return;
}
Err(BackendError::NotSupported) => (),
Err(e) => {
used_backend.replace(XrBackend::OpenXR);
log::error!("{e:?}");
return;
}
@@ -150,9 +172,13 @@ fn auto_run(args: Args) {
use crate::backend::{BackendError, openvr::openvr_run};
tried_vr = true;
match openvr_run(args.show, args.headless) {
Ok(()) => return,
Ok(()) => {
used_backend.replace(XrBackend::OpenVR);
return;
}
Err(BackendError::NotSupported) => (),
Err(e) => {
used_backend.replace(XrBackend::OpenVR);
log::error!("{e:?}");
return;
}

View File

@@ -1,3 +1,5 @@
use std::sync::atomic::Ordering;
use dash_frontend::frontend::{self, FrontendTask, FrontendUpdateParams};
use glam::{Affine2, Affine3A, Vec2, vec2, vec3};
use wayvr_ipc::{
@@ -23,6 +25,7 @@ use wlx_common::{
};
use crate::{
RESTART, RUNNING,
backend::{
input::{Haptics, HoverResult, PointerHit, PointerMode},
task::{OverlayTask, PlayspaceTask, TaskType, ToggleMode},
@@ -418,4 +421,9 @@ impl DashInterface<AppState> for DashInterfaceLive {
data.tasks
.enqueue(TaskType::Overlay(OverlayTask::SettingsChanged));
}
fn restart(&mut self, _data: &mut AppState) {
RUNNING.store(false, Ordering::Relaxed);
RESTART.store(true, Ordering::Relaxed);
}
}

View File

@@ -6,9 +6,12 @@ use wlx_capture::{
pipewire::{PipewireCapture, PipewireSelectScreenResult},
wayland::WlxOutput,
};
use wlx_common::config::{PwTokenMap, def_pw_tokens};
use wlx_common::{
config::{PwTokenMap, def_pw_tokens},
config_io,
};
use crate::{config_io, state::AppState, subsystem::dbus::DbusConnector};
use crate::{state::AppState, subsystem::dbus::DbusConnector};
use super::{
backend::ScreenBackend,

View File

@@ -9,6 +9,7 @@ use wgui::{
use wlx_common::{
audio,
config::GeneralConfig,
config_io::{self, get_config_file_path},
desktop_finder::DesktopFinder,
overlays::{ToastDisplayMethod, ToastTopic},
};
@@ -24,7 +25,6 @@ use crate::subsystem::osc::OscSender;
use crate::{
backend::{XrBackend, input::InputState, task::TaskContainer},
config::load_general_config,
config_io::{self, get_config_file_path},
graphics::WGfxExtras,
gui,
ipc::{event_queue::SyncEventQueue, ipc_server, signal::WayVRSignal},