show-hide binding

This commit is contained in:
galister
2024-02-01 19:49:37 +01:00
parent 22f94671e2
commit 832e5a7ecb
7 changed files with 66 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
use std::time::{Duration, Instant};
use glam::{bool, Affine3A, Quat, Vec3};
use openxr as xr;
@@ -6,6 +8,28 @@ use crate::{backend::input::Pointer, state::AppState};
use super::XrState;
type XrSession = xr::Session<xr::Vulkan>;
static DOUBLE_CLICK_TIME: Duration = Duration::from_millis(500);
pub(super) struct DoubleClickCounter {
pub(super) last_click: Option<Instant>,
}
impl DoubleClickCounter {
pub(super) fn new() -> Self {
Self { last_click: None }
}
// submit a click. returns true if it should count as a double click
pub(super) fn click(&mut self) -> bool {
let now = Instant::now();
let double_click = match self.last_click {
Some(last_click) => now - last_click < DOUBLE_CLICK_TIME,
None => false,
};
self.last_click = if double_click { None } else { Some(now) };
double_click
}
}
pub(super) struct OpenXrInputSource {
action_set: xr::ActionSet,

View File

@@ -16,7 +16,7 @@ use crate::{
backend::{
common::OverlayContainer,
input::interact,
openxr::{lines::LinePool, overlay::OpenXrOverlayData},
openxr::{input::DoubleClickCounter, lines::LinePool, overlay::OpenXrOverlayData},
},
graphics::WlxGraphics,
state::AppState,
@@ -114,6 +114,8 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let mut session_running = false;
let mut event_storage = xr::EventDataBuffer::new();
let mut show_hide_counter = DoubleClickCounter::new();
'main_loop: loop {
if !running.load(Ordering::Relaxed) {
log::warn!("Received shutdown signal.");
@@ -184,6 +186,17 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
input_source.update(&xr_state, &mut app_state);
app_state.input_state.post_update();
if app_state
.input_state
.pointers
.iter()
.any(|p| p.now.show_hide && !p.before.show_hide)
{
if show_hide_counter.click() {
overlays.show_hide();
}
}
let (_, views) = xr_state
.session
.locate_views(