From 4eeb0afb0be8a3b8e1c6eef67e130759474a5481 Mon Sep 17 00:00:00 2001
From: galister <22305755+galister@users.noreply.github.com>
Date: Sun, 2 Aug 2026 00:44:42 +0900
Subject: [PATCH] align_to_hmd regardless of Positioning
---
wayvr/src/assets/gui/edit.xml | 4 +---
wayvr/src/backend/input.rs | 23 ++++++--------------
wayvr/src/overlays/edit/mod.rs | 4 ++--
wayvr/src/overlays/edit/pos.rs | 14 ------------
wayvr/src/overlays/passthrough.rs | 6 +++++-
wayvr/src/overlays/toast.rs | 1 -
wayvr/src/overlays/watch.rs | 1 -
wayvr/src/windowing/window.rs | 36 ++++++++++++-------------------
wlx-common/src/windowing.rs | 20 +++--------------
9 files changed, 31 insertions(+), 78 deletions(-)
diff --git a/wayvr/src/assets/gui/edit.xml b/wayvr/src/assets/gui/edit.xml
index 6efc8632..9e10bd94 100644
--- a/wayvr/src/assets/gui/edit.xml
+++ b/wayvr/src/assets/gui/edit.xml
@@ -65,11 +65,9 @@
-
-
-
+
diff --git a/wayvr/src/backend/input.rs b/wayvr/src/backend/input.rs
index 824d3c47..6ea81100 100644
--- a/wayvr/src/backend/input.rs
+++ b/wayvr/src/backend/input.rs
@@ -868,11 +868,8 @@ fn start_grab(
.notify(app, OverlayEventData::OverlayGrabbed { name, pos, editing })
.inspect_err(|e| log::warn!("Error during Notify OverlayGrabbed: {e:?}"));
- o.default_state.positioning = Positioning::FollowHand {
- hand,
- lerp: 0.1,
- align_to_hmd: true,
- };
+ o.default_state.positioning = Positioning::FollowHand { hand, lerp: 0.1 };
+ o.default_state.align_to_hmd = true;
o.activate(app);
}),
)));
@@ -992,30 +989,22 @@ where
if &*overlay.config.name == WATCH_NAME {
// watch special: when dropped, follow the hand that wasn't grabbing
if let Some(overlay_state) = overlay.config.active_state.as_mut() {
+ let align_to_hmd = overlay_state.align_to_hmd;
overlay_state.positioning = match overlay_state.positioning {
- Positioning::FollowHand {
- hand,
- lerp,
- align_to_hmd,
- } => match pointer.hand() {
+ Positioning::FollowHand { hand, lerp } => match pointer.hand() {
Some(LeftRight::Left) => Positioning::FollowHand {
hand: LeftRight::Right,
lerp,
- align_to_hmd,
},
Some(LeftRight::Right) => Positioning::FollowHand {
hand: LeftRight::Left,
lerp,
- align_to_hmd,
- },
- _ => Positioning::FollowHand {
- hand,
- lerp,
- align_to_hmd,
},
+ _ => Positioning::FollowHand { hand, lerp },
},
x => x,
};
+ overlay_state.align_to_hmd = align_to_hmd;
}
} else if overlay.config.global
&& let Some(active_state) = overlay.config.active_state.as_ref()
diff --git a/wayvr/src/overlays/edit/mod.rs b/wayvr/src/overlays/edit/mod.rs
index 7600fc95..5645052f 100644
--- a/wayvr/src/overlays/edit/mod.rs
+++ b/wayvr/src/overlays/edit/mod.rs
@@ -608,7 +608,7 @@ fn reset_panel(
let c = panel
.parser_state
.fetch_component_as::("align_box")?;
- c.set_checked(&mut com, state.positioning.get_align().unwrap_or(false));
+ c.set_checked(&mut com, state.align_to_hmd);
let c = panel
.parser_state
@@ -728,7 +728,7 @@ const fn cb_assign_additive(_app: &mut AppState, owc: &mut OverlayWindowConfig,
const fn cb_assign_align(_app: &mut AppState, owc: &mut OverlayWindowConfig, align: bool) {
owc.dirty = true;
let active_state = owc.active_state.as_mut().unwrap();
- active_state.positioning = active_state.positioning.with_align(align);
+ active_state.align_to_hmd = align;
}
const fn cb_assign_global(_app: &mut AppState, owc: &mut OverlayWindowConfig, global: bool) {
diff --git a/wayvr/src/overlays/edit/pos.rs b/wayvr/src/overlays/edit/pos.rs
index d98b0d36..7933bbc8 100644
--- a/wayvr/src/overlays/edit/pos.rs
+++ b/wayvr/src/overlays/edit/pos.rs
@@ -15,7 +15,6 @@ static POS_NAMES: [&str; 6] = ["static", "anchored", "floating", "hmd", "hand_l"
pub struct PosTabState {
pos: Positioning,
has_lerp: bool,
- has_align: bool,
}
impl From for PosTabState {
@@ -23,7 +22,6 @@ impl From for PosTabState {
Self {
pos: value,
has_lerp: false,
- has_align: false,
}
}
}
@@ -32,7 +30,6 @@ pub fn new_pos_tab_handler(
panel: &mut EditModeWrapPanel,
) -> anyhow::Result> {
let interpolation_id = panel.parser_state.get_widget_id("pos_interpolation")?;
- let align_to_hmd_id = panel.parser_state.get_widget_id("pos_align_to_hmd")?;
SpriteTabHandler::new(
panel,
@@ -50,9 +47,6 @@ pub fn new_pos_tab_handler(
common
.alterables
.set_widget_visible(interpolation_id, state.has_lerp);
- common
- .alterables
- .set_widget_visible(align_to_hmd_id, state.has_align);
})),
)
}
@@ -80,40 +74,32 @@ impl SpriteTabKey for PosTabState {
"static" => Self {
pos: Positioning::Static,
has_lerp: false,
- has_align: false,
},
"anchored" => Self {
pos: Positioning::Anchored,
has_lerp: false,
- has_align: false,
},
"floating" => Self {
pos: Positioning::Floating,
has_lerp: false,
- has_align: false,
},
"hmd" => Self {
pos: Positioning::FollowHead { lerp: 1.0 },
has_lerp: true,
- has_align: false,
},
"hand_l" => Self {
pos: Positioning::FollowHand {
hand: LeftRight::Left,
lerp: 1.0,
- align_to_hmd: false,
},
has_lerp: true,
- has_align: true,
},
"hand_r" => Self {
pos: Positioning::FollowHand {
hand: LeftRight::Right,
lerp: 1.0,
- align_to_hmd: false,
},
has_lerp: true,
- has_align: true,
},
_ => {
panic!("cannot translate to positioning: {key}")
diff --git a/wayvr/src/overlays/passthrough.rs b/wayvr/src/overlays/passthrough.rs
index ef6cd4fe..24d79204 100644
--- a/wayvr/src/overlays/passthrough.rs
+++ b/wayvr/src/overlays/passthrough.rs
@@ -32,7 +32,11 @@ pub const PASSTHRU_PREFIX: &str = "__wvr_passthru-";
static PASSTHRU_COUNTER: AtomicUsize = AtomicUsize::new(1);
pub fn new_passtrhu_name() -> Arc {
- format!("{PASSTHRU_PREFIX}{}", PASSTHRU_COUNTER.fetch_add(1, Ordering::Relaxed)).into()
+ format!(
+ "{PASSTHRU_PREFIX}{}",
+ PASSTHRU_COUNTER.fetch_add(1, Ordering::Relaxed)
+ )
+ .into()
}
pub fn new_passthru(name: Arc, app: &AppState) -> OverlayWindowConfig {
diff --git a/wayvr/src/overlays/toast.rs b/wayvr/src/overlays/toast.rs
index 8ed82e84..37fb4c88 100644
--- a/wayvr/src/overlays/toast.rs
+++ b/wayvr/src/overlays/toast.rs
@@ -130,7 +130,6 @@ fn new_toast(toast: Toast, app: &mut AppState) -> Option {
let relative_to = Positioning::FollowHand {
hand: LeftRight::Left,
lerp: 0.1,
- align_to_hmd: true,
};
(vec3(0., 0., 0.), Quat::IDENTITY, relative_to)
}
diff --git a/wayvr/src/overlays/watch.rs b/wayvr/src/overlays/watch.rs
index 33c19ad5..50055d1f 100644
--- a/wayvr/src/overlays/watch.rs
+++ b/wayvr/src/overlays/watch.rs
@@ -134,7 +134,6 @@ pub fn create_watch(app: &mut AppState) -> anyhow::Result {
let positioning = Positioning::FollowHand {
hand: LeftRight::Left,
lerp: 1.0,
- align_to_hmd: false,
};
panel.update_layout(app)?;
diff --git a/wayvr/src/windowing/window.rs b/wayvr/src/windowing/window.rs
index c3110758..360ca2f5 100644
--- a/wayvr/src/windowing/window.rs
+++ b/wayvr/src/windowing/window.rs
@@ -155,18 +155,12 @@ impl OverlayWindowConfig {
.unwrap_or(self.default_state.transform);
let scale = scalar_scale(&cur_transform);
- let (parent_transform, lerp, align_to_hmd) = match state.positioning {
- Positioning::FollowHead { lerp } => (app.input_state.hmd, lerp, false),
- Positioning::FollowHand {
- hand,
- lerp,
- align_to_hmd,
- } => (
- app.input_state.pointers[hand as usize].pose,
- lerp,
- align_to_hmd,
- ),
- Positioning::Anchored => (app.anchor, 1.0, false),
+ let (parent_transform, lerp) = match state.positioning {
+ Positioning::FollowHead { lerp } => (app.input_state.hmd, lerp),
+ Positioning::FollowHand { hand, lerp } => {
+ (app.input_state.pointers[hand as usize].pose, lerp)
+ }
+ Positioning::Anchored => (app.anchor, 1.0),
_ => return,
};
@@ -192,7 +186,7 @@ impl OverlayWindowConfig {
}
};
- if align_to_hmd {
+ if state.align_to_hmd {
realign(
&mut state.transform,
&app.input_state.hmd,
@@ -233,17 +227,15 @@ impl OverlayWindowConfig {
.saved_transform
.unwrap_or(self.default_state.transform);
- let (parent_transform, align_to_hmd) = match state.positioning {
- Positioning::Floating | Positioning::FollowHead { .. } => (app.input_state.hmd, false),
- Positioning::FollowHand {
- hand, align_to_hmd, ..
- } => (app.input_state.pointers[hand as usize].pose, align_to_hmd),
- Positioning::Anchored => (app.anchor, false),
+ let parent_transform = match state.positioning {
+ Positioning::Floating | Positioning::FollowHead { .. } => app.input_state.hmd,
+ Positioning::FollowHand { hand, .. } => app.input_state.pointers[hand as usize].pose,
+ Positioning::Anchored => app.anchor,
Positioning::Static => {
if hard_reset {
- (app.input_state.hmd, false)
+ app.input_state.hmd
} else {
- (Affine3A::IDENTITY, false)
+ Affine3A::IDENTITY
}
}
};
@@ -254,7 +246,7 @@ impl OverlayWindowConfig {
state.transform = parent_transform * cur_transform;
- if align_to_hmd || (state.grabbable && hard_reset) {
+ if state.align_to_hmd || (state.grabbable && hard_reset) {
let scale = scalar_scale(&cur_transform);
realign(
&mut state.transform,
diff --git a/wlx-common/src/windowing.rs b/wlx-common/src/windowing.rs
index 16130de6..e41bd536 100644
--- a/wlx-common/src/windowing.rs
+++ b/wlx-common/src/windowing.rs
@@ -22,8 +22,6 @@ pub enum Positioning {
hand: LeftRight,
#[serde(default)]
lerp: f32,
- #[serde(default)]
- align_to_hmd: bool,
},
}
@@ -43,21 +41,6 @@ impl Positioning {
}
self
}
- pub const fn get_align(self) -> Option {
- match self {
- Self::FollowHand { align_to_hmd, .. } => Some(align_to_hmd),
- Self::FollowHead { .. } | Self::Floating | Self::Anchored | Self::Static => None,
- }
- }
- pub const fn with_align(mut self, value: bool) -> Self {
- match self {
- Self::FollowHand {
- ref mut align_to_hmd, ..
- } => *align_to_hmd = value,
- Self::FollowHead { .. } | Self::Floating | Self::Anchored | Self::Static => {}
- }
- self
- }
}
// Contains the window state for a given set
@@ -75,6 +58,8 @@ pub struct OverlayWindowState {
pub saved_transform: Option,
pub block_input: bool,
pub angle_fade: bool,
+ #[serde(default)]
+ pub align_to_hmd: bool,
}
impl Default for OverlayWindowState {
@@ -90,6 +75,7 @@ impl Default for OverlayWindowState {
saved_transform: None,
block_input: true,
angle_fade: false,
+ align_to_hmd: false,
}
}
}