add wlx-common lib, move GeneralConfig into it

This commit is contained in:
Aleksander
2025-11-25 00:21:51 +01:00
parent a6da79bf3d
commit 8485639e00
35 changed files with 601 additions and 566 deletions

View File

@@ -2,6 +2,7 @@ use std::collections::HashMap;
use glam::{Affine3A, Vec3, Vec3A};
use slotmap::{HopSlotMap, Key, SecondaryMap};
use wlx_common::config::SerializedWindowSet;
use crate::{
overlays::{
@@ -10,11 +11,8 @@ use crate::{
},
state::AppState,
windowing::{
backend::OverlayEventData,
set::{OverlayWindowSet, SerializedWindowSet},
snap_upright,
OverlayID, OverlaySelector, backend::OverlayEventData, set::OverlayWindowSet, snap_upright,
window::OverlayWindowData,
OverlayID, OverlaySelector,
},
};

View File

@@ -1,18 +1,11 @@
use std::{collections::HashMap, sync::Arc};
use serde::{Deserialize, Serialize};
use slotmap::SecondaryMap;
use std::sync::Arc;
use wlx_common::windowing::OverlayWindowState;
use crate::windowing::{window::OverlayWindowState, OverlayID};
use crate::windowing::OverlayID;
#[derive(Default)]
pub struct OverlayWindowSet {
pub(super) name: Arc<str>,
pub(super) overlays: SecondaryMap<OverlayID, OverlayWindowState>,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct SerializedWindowSet {
pub name: Arc<str>,
pub overlays: HashMap<Arc<str>, OverlayWindowState>,
}

View File

@@ -1,9 +1,9 @@
use glam::{Affine3A, Mat3A, Quat, Vec3, Vec3A};
use serde::{Deserialize, Serialize};
use std::{f32::consts::PI, sync::Arc};
use wlx_common::windowing::{OverlayWindowState, Positioning};
use crate::{
state::{AppState, LeftRight},
state::AppState,
subsystem::input::KeyboardFocus,
windowing::{
backend::{FrameMeta, OverlayBackend, RenderResources, ShouldRender},
@@ -11,33 +11,6 @@ use crate::{
},
};
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
pub enum Positioning {
/// Stays in place, recenters relative to HMD
#[default]
Floating,
/// Stays in place, recenters relative to anchor. Follows anchor during anchor grab.
Anchored,
/// Same as anchor but paused due to interaction
AnchoredPaused,
/// Stays in place, no recentering
Static,
/// Following HMD
FollowHead { lerp: f32 },
/// Normally follows HMD, but paused due to interaction
FollowHeadPaused { lerp: f32 },
/// Following hand
FollowHand { hand: LeftRight, lerp: f32 },
/// Normally follows hand, but paused due to interaction
FollowHandPaused { hand: LeftRight, lerp: f32 },
}
impl Positioning {
pub const fn moves_with_space(self) -> bool {
matches!(self, Self::Floating | Self::Anchored | Self::Static)
}
}
pub struct OverlayWindowData<T> {
pub config: OverlayWindowConfig,
pub data: T,
@@ -261,53 +234,20 @@ pub fn realign(transform: &mut Affine3A, hmd: &Affine3A) {
transform.matrix3 = Mat3A::from_cols(col_x, col_y, col_z).mul_scalar(scale) * rot;
}
// Contains the window state for a given set
#[derive(Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct OverlayWindowState {
pub transform: Affine3A,
pub alpha: f32,
pub grabbable: bool,
pub interactable: bool,
pub positioning: Positioning,
pub curvature: Option<f32>,
pub additive: bool,
pub saved_transform: Option<Affine3A>,
}
impl Default for OverlayWindowState {
fn default() -> Self {
Self {
grabbable: false,
interactable: false,
alpha: 1.0,
positioning: Positioning::Floating,
curvature: None,
transform: Affine3A::IDENTITY,
additive: false,
saved_transform: None,
pub fn save_transform(state: &mut OverlayWindowState, app: &mut AppState) -> bool {
let parent_transform = match state.positioning {
Positioning::Floating => snap_upright(app.input_state.hmd, Vec3A::Y),
Positioning::FollowHead { .. } | Positioning::FollowHeadPaused { .. } => {
app.input_state.hmd
}
}
}
impl OverlayWindowState {
pub fn save_transform(&mut self, app: &mut AppState) -> bool {
let parent_transform = match self.positioning {
Positioning::Floating => snap_upright(app.input_state.hmd, Vec3A::Y),
Positioning::FollowHead { .. } | Positioning::FollowHeadPaused { .. } => {
app.input_state.hmd
}
Positioning::FollowHand { hand, .. } | Positioning::FollowHandPaused { hand, .. } => {
app.input_state.pointers[hand as usize].pose
}
Positioning::Anchored | Positioning::AnchoredPaused => {
snap_upright(app.anchor, Vec3A::Y)
}
Positioning::Static => return false,
};
self.saved_transform = Some(parent_transform.inverse() * self.transform);
true
}
Positioning::FollowHand { hand, .. } | Positioning::FollowHandPaused { hand, .. } => {
app.input_state.pointers[hand as usize].pose
}
Positioning::Anchored | Positioning::AnchoredPaused => snap_upright(app.anchor, Vec3A::Y),
Positioning::Static => return false,
};
state.saved_transform = Some(parent_transform.inverse() * state.transform);
true
}