feat: add focus follows the mouse mode (#23)

This commit is contained in:
alexdenerqal
2024-04-07 17:12:47 +02:00
committed by GitHub
parent 7e2f172b74
commit 1d1a4f01ae
9 changed files with 69 additions and 1 deletions

View File

@@ -198,6 +198,7 @@ pub struct PointerState {
pub space_rotate: bool,
pub click_modifier_right: bool,
pub click_modifier_middle: bool,
pub move_mouse: bool,
}
#[derive(Debug, Clone, Copy, Default)]

View File

@@ -39,6 +39,7 @@ const PATH_SPACE_DRAG: &str = "/actions/default/in/SpaceDrag";
const PATH_SPACE_ROTATE: &str = "/actions/default/in/SpaceRotate";
const PATH_CLICK_MODIFIER_RIGHT: &str = "/actions/default/in/ClickModifierRight";
const PATH_CLICK_MODIFIER_MIDDLE: &str = "/actions/default/in/ClickModifierMiddle";
const PATH_MOVE_MOUSE: &str = "/actions/default/in/MoveMouse";
const INPUT_ANY: InputValueHandle = InputValueHandle(ovr_overlay::sys::k_ulInvalidInputValueHandle);
@@ -54,6 +55,7 @@ pub(super) struct OpenVrInputSource {
space_rotate_hnd: ActionHandle,
click_modifier_right_hnd: ActionHandle,
click_modifier_middle_hnd: ActionHandle,
move_mouse_hnd: ActionHandle,
}
pub(super) struct OpenVrHandSource {
@@ -77,6 +79,7 @@ impl OpenVrInputSource {
let space_rotate_hnd = input.get_action_handle(PATH_SPACE_ROTATE)?;
let click_modifier_right_hnd = input.get_action_handle(PATH_CLICK_MODIFIER_RIGHT)?;
let click_modifier_middle_hnd = input.get_action_handle(PATH_CLICK_MODIFIER_MIDDLE)?;
let move_mouse_hnd = input.get_action_handle(PATH_MOVE_MOUSE)?;
let input_hnd: Vec<InputValueHandle> = INPUT_SOURCES
.iter()
@@ -112,6 +115,7 @@ impl OpenVrInputSource {
space_rotate_hnd,
click_modifier_right_hnd,
click_modifier_middle_hnd,
move_mouse_hnd,
hands,
})
}
@@ -212,6 +216,11 @@ impl OpenVrInputSource {
.map(|x| x.0.bState)
.unwrap_or(false);
app_hand.now.move_mouse = input
.get_digital_action_data(self.move_mouse_hnd, hand.input_hnd)
.map(|x| x.0.bState)
.unwrap_or(false);
app_hand.now.scroll = input
.get_analog_action_data(self.scroll_hnd, hand.input_hnd)
.map(|x| x.0.y)

View File

@@ -53,6 +53,7 @@ pub(super) struct OpenXrHandSource {
action_show_hide: xr::Action<bool>,
action_click_modifier_right: xr::Action<bool>,
action_click_modifier_middle: xr::Action<bool>,
action_move_mouse: xr::Action<bool>,
action_haptics: xr::Action<xr::Haptic>,
}
@@ -194,6 +195,12 @@ impl OpenXrHand {
.state(&xr.session, xr::Path::NULL)?
.current_state;
pointer.now.move_mouse = self
.source
.action_move_mouse
.state(&xr.session, xr::Path::NULL)?
.current_state;
Ok(())
}
}
@@ -242,6 +249,11 @@ impl OpenXrHandSource {
&format!("{} hand middle click modifier", side),
&[],
)?;
let action_move_mouse = action_set.create_action::<bool>(
&format!("{}_move_mouse", side),
&format!("{} hand mouse move", side),
&[],
)?;
let action_haptics = action_set.create_action::<xr::Haptic>(
&format!("{}_haptics", side),
&format!("{} hand haptics", side),
@@ -257,6 +269,7 @@ impl OpenXrHandSource {
action_show_hide,
action_click_modifier_right,
action_click_modifier_middle,
action_move_mouse,
action_haptics,
})
}
@@ -359,6 +372,14 @@ fn suggest_bindings(
&hands[1].action_click_modifier_middle,
instance.string_to_path("/user/hand/right/input/a/touch")?,
),
xr::Binding::new(
&hands[0].action_move_mouse,
instance.string_to_path("/user/hand/left/input/trigger/touch")?,
),
xr::Binding::new(
&hands[1].action_move_mouse,
instance.string_to_path("/user/hand/right/input/trigger/touch")?,
),
xr::Binding::new(
&hands[0].action_haptics,
instance.string_to_path("/user/hand/left/output/haptic")?,
@@ -434,6 +455,14 @@ fn suggest_bindings(
&hands[1].action_click_modifier_middle,
instance.string_to_path("/user/hand/right/input/a/touch")?,
),
xr::Binding::new(
&hands[0].action_move_mouse,
instance.string_to_path("/user/hand/left/input/trigger/touch")?,
),
xr::Binding::new(
&hands[1].action_move_mouse,
instance.string_to_path("/user/hand/right/input/trigger/touch")?,
),
xr::Binding::new(
&hands[0].action_haptics,
instance.string_to_path("/user/hand/left/output/haptic")?,