diff --git a/src/config_wayvr.rs b/src/config_wayvr.rs index 81905d6..11dabed 100644 --- a/src/config_wayvr.rs +++ b/src/config_wayvr.rs @@ -5,7 +5,38 @@ use std::collections::{BTreeMap, HashMap}; use serde::{Deserialize, Serialize}; -use crate::config::{load_known_yaml, ConfigType}; +use crate::{ + backend::overlay::RelativeTo, + config::{load_known_yaml, ConfigType}, +}; + +// Flat version of RelativeTo +#[derive(Clone, Deserialize, Serialize)] +pub enum AttachTo { + None, + HandLeft, + HandRight, + Head, + Stage, +} + +impl AttachTo { + pub fn get_relative_to(&self) -> RelativeTo { + match self { + AttachTo::None => RelativeTo::None, + AttachTo::HandLeft => RelativeTo::Hand(0), + AttachTo::HandRight => RelativeTo::Hand(1), + AttachTo::Stage => RelativeTo::Stage, + AttachTo::Head => RelativeTo::Head, + } + } +} + +#[derive(Clone, Deserialize, Serialize)] +pub struct Rotation { + pub axis: [f32; 3], + pub angle: f32, +} #[derive(Clone, Deserialize, Serialize)] pub struct WayVRAppEntry { @@ -21,6 +52,9 @@ pub struct WayVRDisplay { pub width: u32, pub height: u32, pub scale: f32, + pub rotation: Option, + pub pos: Option<[f32; 3]>, + pub attach_to: Option, } #[derive(Clone, Deserialize, Serialize)] diff --git a/src/overlays/wayvr.rs b/src/overlays/wayvr.rs index 570845c..46d124f 100644 --- a/src/overlays/wayvr.rs +++ b/src/overlays/wayvr.rs @@ -1,4 +1,4 @@ -use glam::{vec3a, Affine2}; +use glam::{vec3a, Affine2, Vec3, Vec3A}; use serde::Deserialize; use std::{cell::RefCell, rc::Rc, sync::Arc}; use vulkano::image::SubresourceLayout; @@ -314,7 +314,8 @@ where .ok_or(anyhow::anyhow!( "Cannot find display named \"{}\"", app_entry.target_display - ))?; + ))? + .clone(); let display_handle = wayvr.create_display( conf_display.width, @@ -322,7 +323,7 @@ where &app_entry.target_display, )?; - let overlay = create_wayvr_display_overlay::( + let mut overlay = create_wayvr_display_overlay::( app, conf_display.width, conf_display.height, @@ -330,6 +331,21 @@ where conf_display.scale, )?; + if let Some(attach_to) = &conf_display.attach_to { + overlay.state.relative_to = attach_to.get_relative_to(); + } + + if let Some(rot) = &conf_display.rotation { + overlay.state.spawn_rotation = glam::Quat::from_axis_angle( + Vec3::from_slice(&rot.axis), + f32::to_radians(rot.angle), + ); + } + + if let Some(pos) = &conf_display.pos { + overlay.state.spawn_point = Vec3A::from_slice(pos); + } + let display = wayvr.displays.get_mut(&display_handle).unwrap(); // Never fails display.overlay_id = Some(overlay.state.id); diff --git a/src/res/wayvr.yaml b/src/res/wayvr.yaml index 4298445..d105e67 100644 --- a/src/res/wayvr.yaml +++ b/src/res/wayvr.yaml @@ -6,6 +6,13 @@ version: 1 displays: + Watch: + width: 400 + height: 600 + scale: 0.4 + attach_to: "HandRight" # HandLeft, HandRight + pos: [0.0, 0.0, 0.125] + rotation: {axis: [1.0, 0.0, 0.0], angle: -45.0} Disp1: width: 640 height: 480 @@ -24,7 +31,7 @@ catalogs: env: ["FOO=bar"] - name: "htop" - target_display: "Disp1" + target_display: "Watch" exec: "konsole" args: "-e htop"