From cf5eabdfdf55bdc4695ea46629fc20e72f52d2df Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 26 Oct 2024 18:40:05 +0200 Subject: [PATCH] WayVR: `shown_at_start` app param support --- src/config_wayvr.rs | 29 ++++++++++++++++++++++++++--- src/overlays/wayvr.rs | 2 +- src/res/wayvr.yaml | 2 +- src/state.rs | 11 ++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/config_wayvr.rs b/src/config_wayvr.rs index 11dabed..eed17fd 100644 --- a/src/config_wayvr.rs +++ b/src/config_wayvr.rs @@ -1,13 +1,20 @@ #[cfg(not(feature = "wayvr"))] compile_error!("WayVR feature is not enabled"); -use std::collections::{BTreeMap, HashMap}; +use std::{ + collections::{BTreeMap, HashMap}, + sync::Arc, +}; use serde::{Deserialize, Serialize}; use crate::{ - backend::overlay::RelativeTo, + backend::{ + overlay::RelativeTo, + task::{TaskContainer, TaskType}, + }, config::{load_known_yaml, ConfigType}, + overlays::wayvr::WayVRAction, }; // Flat version of RelativeTo @@ -45,13 +52,14 @@ pub struct WayVRAppEntry { pub exec: String, pub args: Option, pub env: Option>, + pub shown_at_start: Option, } #[derive(Clone, Deserialize, Serialize)] pub struct WayVRDisplay { pub width: u32, pub height: u32, - pub scale: f32, + pub scale: Option, pub rotation: Option, pub pos: Option<[f32; 3]>, pub attach_to: Option, @@ -83,6 +91,21 @@ impl WayVRConfig { pub fn get_display(&self, name: &str) -> Option<&WayVRDisplay> { self.displays.get(name) } + + pub fn post_load(&self, tasks: &mut TaskContainer) { + for (catalog_name, catalog) in &self.catalogs { + for app in &catalog.apps { + if let Some(b) = app.shown_at_start { + if b { + tasks.enqueue(TaskType::WayVR(WayVRAction::AppClick { + catalog_name: Arc::from(catalog_name.as_str()), + app_name: Arc::from(app.name.as_str()), + })); + } + } + } + } + } } pub fn load_wayvr() -> WayVRConfig { diff --git a/src/overlays/wayvr.rs b/src/overlays/wayvr.rs index 46d124f..e5fd5dc 100644 --- a/src/overlays/wayvr.rs +++ b/src/overlays/wayvr.rs @@ -328,7 +328,7 @@ where conf_display.width, conf_display.height, display_handle, - conf_display.scale, + conf_display.scale.unwrap_or(1.0), )?; if let Some(attach_to) = &conf_display.attach_to { diff --git a/src/res/wayvr.yaml b/src/res/wayvr.yaml index d105e67..292c8a8 100644 --- a/src/res/wayvr.yaml +++ b/src/res/wayvr.yaml @@ -16,7 +16,6 @@ displays: Disp1: width: 640 height: 480 - scale: 1.25 Disp2: width: 1280 height: 720 @@ -29,6 +28,7 @@ catalogs: target_display: "Disp1" exec: "kcalc" env: ["FOO=bar"] + shown_at_start: false - name: "htop" target_display: "Watch" diff --git a/src/state.rs b/src/state.rs index 4b3fc98..ee35d21 100644 --- a/src/state.rs +++ b/src/state.rs @@ -91,12 +91,21 @@ impl AppState { shaders.insert("frag_swapchain", shader); } + #[cfg(feature = "wayvr")] + let mut tasks = TaskContainer::new(); + + #[cfg(not(feature = "wayvr"))] + let tasks = TaskContainer::new(); + let session = AppSession::load(); + #[cfg(feature = "wayvr")] + session.wayvr_config.post_load(&mut tasks); + Ok(AppState { fc: FontCache::new(session.config.primary_font.clone())?, session, - tasks: TaskContainer::new(), + tasks, graphics, input_state: InputState::new(), hid_provider: crate::hid::initialize(),