grab, mouse move
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4027,6 +4027,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"ashpd",
|
||||
"drm-fourcc",
|
||||
"idmap",
|
||||
"libc",
|
||||
"libspa-sys",
|
||||
"log",
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::{
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use glam::Vec2;
|
||||
use idmap::IdMap;
|
||||
|
||||
use crate::{
|
||||
@@ -22,6 +23,7 @@ where
|
||||
T: Default,
|
||||
{
|
||||
overlays: IdMap<usize, OverlayData<T>>,
|
||||
pub extent: Vec2,
|
||||
}
|
||||
|
||||
impl<T> OverlayContainer<T>
|
||||
@@ -31,7 +33,7 @@ where
|
||||
pub fn new(app: &mut AppState) -> Self {
|
||||
let mut overlays = IdMap::new();
|
||||
|
||||
let screens = if std::env::var("WAYLAND_DISPLAY").is_ok() {
|
||||
let (screens, extent) = if std::env::var("WAYLAND_DISPLAY").is_ok() {
|
||||
get_screens_wayland(&app.session)
|
||||
} else {
|
||||
get_screens_x11()
|
||||
@@ -52,7 +54,7 @@ where
|
||||
overlays.insert(screen.state.id, screen);
|
||||
}
|
||||
|
||||
Self { overlays }
|
||||
Self { overlays, extent }
|
||||
}
|
||||
|
||||
pub fn mut_by_selector(&mut self, selector: &OverlaySelector) -> Option<&mut OverlayData<T>> {
|
||||
|
||||
@@ -214,12 +214,12 @@ impl<THand> Pointer<THand> {
|
||||
{
|
||||
if let Some(grab_data) = self.interaction.grabbed {
|
||||
if let Some(grabbed) = overlays.mut_by_id(grab_data.grabbed_id) {
|
||||
self.handle_grabbed(grabbed, grab_data.offset);
|
||||
self.handle_grabbed(grabbed);
|
||||
} else {
|
||||
log::warn!("Grabbed overlay {} does not exist", grab_data.grabbed_id);
|
||||
self.interaction.grabbed = None;
|
||||
}
|
||||
return grab_data.offset.length(); // grab interaction
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
let Some(mut hit) = self.get_nearest_hit(overlays) else {
|
||||
@@ -270,7 +270,8 @@ impl<THand> Pointer<THand> {
|
||||
hit.primary = true;
|
||||
}
|
||||
|
||||
log::debug!("Hit: {} {:?}", hovered.state.name, hit);
|
||||
#[cfg(debug_assertions)]
|
||||
log::trace!("Hit: {} {:?}", hovered.state.name, hit);
|
||||
|
||||
if self.now.grab && !self.before.grab {
|
||||
self.start_grab(hovered);
|
||||
@@ -358,25 +359,25 @@ impl<THand> Pointer<THand> {
|
||||
offset,
|
||||
grabbed_id: overlay.state.id,
|
||||
});
|
||||
log::info!("Hand {}: grabbed {}", self.idx, overlay.state.name);
|
||||
log::debug!("Hand {}: grabbed {}", self.idx, overlay.state.name);
|
||||
}
|
||||
|
||||
fn handle_grabbed<O>(&mut self, overlay: &mut OverlayData<O>, offset: Vec3A)
|
||||
fn handle_grabbed<O>(&mut self, overlay: &mut OverlayData<O>)
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
if self.now.grab {
|
||||
overlay.state.transform.translation = self.pose.transform_point3a(offset);
|
||||
|
||||
if self.now.click && !self.before.click {
|
||||
log::warn!("todo: click-while-grabbed");
|
||||
}
|
||||
|
||||
let grab_data = self.interaction.grabbed.as_mut().unwrap();
|
||||
match self.interaction.mode {
|
||||
PointerMode::Left => {
|
||||
overlay.state.transform.translation.y += self.now.scroll * 0.01;
|
||||
grab_data.offset.z -= self.now.scroll * 0.05;
|
||||
}
|
||||
_ => {
|
||||
log::warn!("scale: {}", self.now.scroll);
|
||||
overlay.state.transform.matrix3 = overlay
|
||||
.state
|
||||
.transform
|
||||
@@ -384,6 +385,7 @@ impl<THand> Pointer<THand> {
|
||||
.mul_scalar(1.0 + 0.01 * self.now.scroll);
|
||||
}
|
||||
}
|
||||
overlay.state.transform.translation = self.pose.transform_point3a(grab_data.offset);
|
||||
overlay.state.dirty = true;
|
||||
} else {
|
||||
overlay.state.spawn_point = overlay.state.transform.translation;
|
||||
|
||||
@@ -200,7 +200,7 @@ impl InputState<OpenVrInputState, OpenVrHandState> {
|
||||
|
||||
hand.now.scroll = input
|
||||
.get_analog_action_data(self.data.scroll_hnd, hand.data.input_hnd)
|
||||
.map(|x| x.0.x)
|
||||
.map(|x| x.0.y)
|
||||
.unwrap_or(0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ pub fn openvr_run() {
|
||||
let mut state = AppState::new(instance_extensions, device_extensions_fn);
|
||||
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state);
|
||||
|
||||
state.input.set_desktop_extent(overlays.extent);
|
||||
|
||||
if let Err(e) = input_mngr.set_action_manifest(action_manifest_path()) {
|
||||
log::error!("Failed to set action manifest: {}", e.description());
|
||||
return;
|
||||
|
||||
@@ -59,7 +59,7 @@ impl UInputProvider {
|
||||
let id = InputId {
|
||||
bustype: 0x03,
|
||||
vendor: 0x4711,
|
||||
product: 0x0819,
|
||||
product: 0x0829,
|
||||
version: 5,
|
||||
};
|
||||
|
||||
@@ -144,7 +144,8 @@ impl InputProvider for UInputProvider {
|
||||
}
|
||||
self.mouse_moved = true;
|
||||
|
||||
log::info!("Mouse move: {:?}", pos);
|
||||
#[cfg(debug_assertions)]
|
||||
log::trace!("Mouse move: {:?}", pos);
|
||||
|
||||
let pos = pos * (MOUSE_EXTENT / self.desktop_extent);
|
||||
|
||||
|
||||
@@ -72,7 +72,8 @@ impl ScreenInteractionHandler {
|
||||
|
||||
impl InteractionHandler for ScreenInteractionHandler {
|
||||
fn on_hover(&mut self, app: &mut AppState, hit: &PointerHit) {
|
||||
log::info!("Hover: {:?}", hit.uv);
|
||||
#[cfg(debug_assertions)]
|
||||
log::trace!("Hover: {:?}", hit.uv);
|
||||
if self.next_move < Instant::now() {
|
||||
let pos = self.mouse_transform.transform_point2(hit.uv);
|
||||
app.input.mouse_move(pos);
|
||||
@@ -212,9 +213,7 @@ impl ScreenRenderer {
|
||||
let Some(client) = WlxClient::new() else {
|
||||
return None;
|
||||
};
|
||||
let Some(capture) = WlrDmabufCapture::new(client, output.id) else {
|
||||
return None;
|
||||
};
|
||||
let capture = WlrDmabufCapture::new(client, output.id);
|
||||
Some(ScreenRenderer {
|
||||
capture: Box::new(capture),
|
||||
receiver: None,
|
||||
@@ -286,11 +285,11 @@ impl OverlayRenderer for ScreenRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_create_screen<O>(wl: &WlxClient, idx: usize, session: &AppSession) -> Option<OverlayData<O>>
|
||||
fn try_create_screen<O>(wl: &WlxClient, id: u32, session: &AppSession) -> Option<OverlayData<O>>
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
let output = &wl.outputs[idx];
|
||||
let output = &wl.outputs.get(id).unwrap();
|
||||
log::info!(
|
||||
"{}: Res {}x{} Size {:?} Pos {:?}",
|
||||
output.name,
|
||||
@@ -343,13 +342,13 @@ where
|
||||
Affine2::from_translation(Vec2 { x: 0.5, y: 0.5 })
|
||||
* Affine2::from_scale(Vec2 {
|
||||
x: 1.,
|
||||
y: output.size.0 as f32 / output.size.1 as f32,
|
||||
y: -output.size.0 as f32 / output.size.1 as f32,
|
||||
})
|
||||
} else {
|
||||
Affine2::from_translation(Vec2 { x: 0.5, y: 0.5 })
|
||||
* Affine2::from_scale(Vec2 {
|
||||
x: output.size.1 as f32 / output.size.0 as f32,
|
||||
y: 1.,
|
||||
y: -1.,
|
||||
})
|
||||
};
|
||||
|
||||
@@ -357,7 +356,7 @@ where
|
||||
state: OverlayState {
|
||||
name: output.name.clone(),
|
||||
size,
|
||||
want_visible: idx == 0,
|
||||
want_visible: session.show_screens.iter().any(|s| s == &*output.name),
|
||||
show_hide: true,
|
||||
grabbable: true,
|
||||
spawn_rotation: Quat::from_axis_angle(axis, angle),
|
||||
@@ -373,22 +372,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_screens_wayland<O>(session: &AppSession) -> Vec<OverlayData<O>>
|
||||
pub fn get_screens_wayland<O>(session: &AppSession) -> (Vec<OverlayData<O>>, Vec2)
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
let mut overlays = vec![];
|
||||
let wl = WlxClient::new().unwrap();
|
||||
|
||||
for idx in 0..wl.outputs.len() {
|
||||
if let Some(overlay) = try_create_screen(&wl, idx, &session) {
|
||||
for id in wl.outputs.keys() {
|
||||
if let Some(overlay) = try_create_screen(&wl, *id, &session) {
|
||||
overlays.push(overlay);
|
||||
}
|
||||
}
|
||||
overlays
|
||||
let extent = wl.get_desktop_extent();
|
||||
(overlays, Vec2::new(extent.0 as f32, extent.1 as f32))
|
||||
}
|
||||
|
||||
pub fn get_screens_x11<O>() -> Vec<OverlayData<O>>
|
||||
pub fn get_screens_x11<O>() -> (Vec<OverlayData<O>>, Vec2)
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user