WayVR: External process support, various tweaks and bugfixes
- Support for foreign wayland clients, WayVR process is now separated into managed and external one - Add `run_compositor_at_start` global param - Add `primary` display param - Export WAYLAND_DISPLAY number into XDG_RUNTIME_DIR directory - Bugfix: Redraw event is not triggered after despawning a process - Sanitization in WayVRConfig::post_load()
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
compile_error!("WayVR feature is not enabled");
|
||||
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{BTreeMap, HashMap},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -12,6 +14,7 @@ use crate::{
|
||||
backend::{
|
||||
overlay::RelativeTo,
|
||||
task::{TaskContainer, TaskType},
|
||||
wayvr,
|
||||
},
|
||||
config::{load_known_yaml, ConfigType},
|
||||
overlays::wayvr::WayVRAction,
|
||||
@@ -63,6 +66,7 @@ pub struct WayVRDisplay {
|
||||
pub rotation: Option<Rotation>,
|
||||
pub pos: Option<[f32; 3]>,
|
||||
pub attach_to: Option<AttachTo>,
|
||||
pub primary: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
@@ -79,6 +83,7 @@ impl WayVRCatalog {
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct WayVRConfig {
|
||||
pub version: u32,
|
||||
pub run_compositor_at_start: bool,
|
||||
pub catalogs: HashMap<String, WayVRCatalog>,
|
||||
pub displays: BTreeMap<String, WayVRDisplay>, // sorted alphabetically
|
||||
}
|
||||
@@ -92,7 +97,31 @@ impl WayVRConfig {
|
||||
self.displays.get(name)
|
||||
}
|
||||
|
||||
pub fn post_load(&self, tasks: &mut TaskContainer) {
|
||||
pub fn get_default_display(&self) -> Option<(String, &WayVRDisplay)> {
|
||||
for (disp_name, disp) in &self.displays {
|
||||
if disp.primary.unwrap_or(false) {
|
||||
return Some((disp_name.clone(), disp));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn post_load(
|
||||
&self,
|
||||
tasks: &mut TaskContainer,
|
||||
) -> anyhow::Result<Option<Rc<RefCell<wayvr::WayVR>>>> {
|
||||
let primary_count = self
|
||||
.displays
|
||||
.iter()
|
||||
.filter(|d| d.1.primary.unwrap_or(false))
|
||||
.count();
|
||||
|
||||
if primary_count > 1 {
|
||||
anyhow::bail!("Number of primary displays is more than 1")
|
||||
} else if primary_count == 0 {
|
||||
log::warn!("No primary display specified");
|
||||
}
|
||||
|
||||
for (catalog_name, catalog) in &self.catalogs {
|
||||
for app in &catalog.apps {
|
||||
if let Some(b) = app.shown_at_start {
|
||||
@@ -105,6 +134,14 @@ impl WayVRConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.run_compositor_at_start {
|
||||
// Start Wayland server instantly
|
||||
Ok(Some(Rc::new(RefCell::new(wayvr::WayVR::new()?))))
|
||||
} else {
|
||||
// Lazy-init WayVR later if the user requested
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user