Skip to content

Commit

Permalink
feat: dummy screens and battery states for uidev (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
galister authored Apr 17, 2024
1 parent 42ab3a3 commit f6a9db5
Showing 3 changed files with 59 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/backend/input.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@ use std::{collections::VecDeque, time::Instant};

use glam::{Affine3A, Vec2, Vec3A};

#[cfg(feature = "openvr")]
use ovr_overlay::TrackedDeviceIndex;
use smallvec::{smallvec, SmallVec};

use crate::backend::common::snap_upright;
@@ -16,9 +14,6 @@ use super::{
};

pub struct TrackedDevice {
#[cfg(feature = "openvr")]
pub index: TrackedDeviceIndex,
pub valid: bool,
pub soc: Option<f32>,
pub charging: bool,
pub role: TrackedDeviceRole,
2 changes: 0 additions & 2 deletions src/backend/openvr/input.rs
Original file line number Diff line number Diff line change
@@ -309,8 +309,6 @@ fn get_tracked_device(
}

Some(TrackedDevice {
valid: true,
index,
soc,
charging,
role,
61 changes: 59 additions & 2 deletions src/backend/uidev/mod.rs
Original file line number Diff line number Diff line change
@@ -25,10 +25,13 @@ use crate::{
Canvas,
},
hid::USE_UINPUT,
state::AppState,
state::{AppState, ScreenMeta},
};

use super::overlay::OverlayRenderer;
use super::{
input::{TrackedDevice, TrackedDeviceRole},
overlay::OverlayRenderer,
};

static LAST_SIZE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);

@@ -114,6 +117,9 @@ pub fn uidev_run(panel_name: &str) -> anyhow::Result<()> {
USE_UINPUT.store(false, std::sync::atomic::Ordering::Relaxed);

let mut state = AppState::from_graphics(graphics.clone())?;
add_dummy_devices(&mut state);
add_dummy_screens(&mut state);

let mut preview = Some(PreviewState::new(
&mut state,
surface.clone(),
@@ -257,3 +263,54 @@ fn create_swapchain(

Ok((swapchain, image_views))
}

fn add_dummy_devices(app: &mut AppState) {
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::Hmd,
soc: Some(0.42),
charging: true,
});
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::LeftHand,
soc: Some(0.72),
charging: false,
});
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::RightHand,
soc: Some(0.73),
charging: false,
});
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::Tracker,
soc: Some(0.65),
charging: false,
});
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::Tracker,
soc: Some(0.67),
charging: false,
});
app.input_state.devices.push(TrackedDevice {
role: TrackedDeviceRole::Tracker,
soc: Some(0.69),
charging: false,
});
}

fn add_dummy_screens(app: &mut AppState) {
app.screens.push(ScreenMeta {
name: "HDMI-A-1".into(),
id: 0,
native_handle: 0,
});
app.screens.push(ScreenMeta {
name: "DP-2".into(),
id: 0,
native_handle: 0,
});
app.screens.push(ScreenMeta {
name: "DP-3".into(),
id: 0,
native_handle: 0,
});
}

0 comments on commit f6a9db5

Please sign in to comment.