From 3f858e5e2f60f30eb506d3d195f7ff2fabdaa58a Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Thu, 2 Jul 2026 16:31:46 +0900 Subject: [PATCH] fix weird range slider behavior --- dash-frontend/src/views/bindings.rs | 27 +++++++++++++----------- wayvr/src/backend/openxr/input.rs | 3 ++- wlx-common/src/openxr_bindings_schema.rs | 2 ++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/dash-frontend/src/views/bindings.rs b/dash-frontend/src/views/bindings.rs index 9062d068..67465a3b 100644 --- a/dash-frontend/src/views/bindings.rs +++ b/dash-frontend/src/views/bindings.rs @@ -20,7 +20,9 @@ use wgui::{ use wlx_common::{ config_io, openxr_actions::{OneOrMany, OpenXrInputAction, OpenXrInputProfile, load_xr_input_profiles}, - openxr_bindings_schema::{XrControllerProfile, XrInputComponent, XrInputSide, XrInputSubpathKind}, + openxr_bindings_schema::{ + DEFAULT_BUTTON_THRESHOLDS, XrControllerProfile, XrInputComponent, XrInputSide, XrInputSubpathKind, + }, }; use crate::{ @@ -39,7 +41,7 @@ enum Task { Save, Cancel, OpenContextMenu(glam::Vec2, Vec), - UpdateThreshold(Rc, XrInputSide, f32, f32), + UpdateThreshold(Rc, XrInputSide, usize, f32), } pub struct Params<'a> { @@ -88,17 +90,18 @@ impl ViewTrait for View { blueprint: context_menu::Blueprint::Cells(cells), }); } - Task::UpdateThreshold(action_name, side, lo, hi) => { - log::warn!("UpdateThreshold {action_name} {lo:.2} {hi:.2}"); - + Task::UpdateThreshold(action_name, side, i, val) => { let cur_profile = &mut self.profiles[self.cur_profile_idx]; let action_mut = get_action_mut(cur_profile, &*action_name); - if matches!(side, XrInputSide::Right) { - action_mut.threshold_right = Some([lo, hi]); + let threshold = if matches!(side, XrInputSide::Right) { + action_mut.threshold_right.get_or_insert(DEFAULT_BUTTON_THRESHOLDS) } else { - action_mut.threshold_left = Some([lo, hi]); - } + action_mut.threshold_left.get_or_insert(DEFAULT_BUTTON_THRESHOLDS) + }; + + threshold[i] = val; + log::warn!("UpdateThreshold {action_name} {side:?} {threshold:?}"); } } } @@ -552,7 +555,7 @@ fn threshold_slider( let id = mp.idx.to_string(); mp.idx += 1; - let current = current.unwrap_or([0.5, 0.7]); + let current = current.unwrap_or(DEFAULT_BUTTON_THRESHOLDS); let mut params: HashMap, Rc> = HashMap::new(); params.insert(Rc::from("id"), Rc::from(id.as_ref())); @@ -571,9 +574,9 @@ fn threshold_slider( let tasks = mp.tasks.clone(); move |_common, e| { if matches!(e.index, wgui::components::slider::ValueIndex::Primary) { - tasks.push(Task::UpdateThreshold(action.clone(), side, e.value, current[1])); + tasks.push(Task::UpdateThreshold(action.clone(), side, 0, e.value)); } else { - tasks.push(Task::UpdateThreshold(action.clone(), side, current[0], e.value)); + tasks.push(Task::UpdateThreshold(action.clone(), side, 1, e.value)); } } })); diff --git a/wayvr/src/backend/openxr/input.rs b/wayvr/src/backend/openxr/input.rs index f2df3ddb..5dbd517a 100644 --- a/wayvr/src/backend/openxr/input.rs +++ b/wayvr/src/backend/openxr/input.rs @@ -10,6 +10,7 @@ use openxr::{self as xr, Quaternionf, Vector2f, Vector3f}; use wlx_common::{ config::HandsfreePointer, openxr_actions::{OneOrMany, load_xr_input_profiles}, + openxr_bindings_schema::DEFAULT_BUTTON_THRESHOLDS, }; use crate::{ @@ -128,7 +129,7 @@ impl CustomClickAction { single, double, triple, - threshold: [0.5, 0.7], + threshold: DEFAULT_BUTTON_THRESHOLDS, }) } diff --git a/wlx-common/src/openxr_bindings_schema.rs b/wlx-common/src/openxr_bindings_schema.rs index 645ddab9..9c482123 100644 --- a/wlx-common/src/openxr_bindings_schema.rs +++ b/wlx-common/src/openxr_bindings_schema.rs @@ -1,6 +1,8 @@ use serde::{Deserialize, Serialize}; use strum::{AsRefStr, EnumProperty, EnumString}; +pub const DEFAULT_BUTTON_THRESHOLDS: [f32; 2] = [0.5, 0.7]; + pub struct XrControllerProfile { pub display_name: &'static str, pub profile_id: &'static str,