wayland_server: fix mouse

This commit is contained in:
galister
2025-12-26 02:49:43 +09:00
parent 03173434bc
commit dd4a795b4c
3 changed files with 46 additions and 14 deletions

View File

@@ -398,7 +398,15 @@ impl WayVRState {
} }
if let Some(window) = self.wm.windows.get_mut(&handle) { if let Some(window) = self.wm.windows.get_mut(&handle) {
window.send_mouse_move(&mut self.manager, x, y); window.send_mouse_move(&mut self.manager, x, y);
} else {
return;
} }
self.mouse_freeze = Instant::now() + Duration::from_millis(1); // prevent other pointer from moving the mouse on the same frame
self.wm.mouse = Some(window::MouseState {
hover_window: handle.clone(),
x,
y,
});
} }
pub fn send_mouse_down(&mut self, handle: window::WindowHandle, index: MouseIndex) { pub fn send_mouse_down(&mut self, handle: window::WindowHandle, index: MouseIndex) {

View File

@@ -42,7 +42,7 @@ impl Window {
self.size_y = size_y; self.size_y = size_y;
} }
pub fn send_mouse_move(&self, manager: &mut WayVRCompositor, x: u32, y: u32) { pub(super) fn send_mouse_move(&self, manager: &mut WayVRCompositor, x: u32, y: u32) {
let surf = self.toplevel.wl_surface().clone(); let surf = self.toplevel.wl_surface().clone();
let point = Point::<f64, Logical>::from((f64::from(x as i32), f64::from(y as i32))); let point = Point::<f64, Logical>::from((f64::from(x as i32), f64::from(y as i32)));
@@ -67,7 +67,11 @@ impl Window {
} }
} }
pub fn send_mouse_down(&mut self, manager: &mut WayVRCompositor, index: super::MouseIndex) { pub(super) fn send_mouse_down(
&mut self,
manager: &mut WayVRCompositor,
index: super::MouseIndex,
) {
let surf = self.toplevel.wl_surface().clone(); let surf = self.toplevel.wl_surface().clone();
// Change keyboard focus to pressed window // Change keyboard focus to pressed window
@@ -90,7 +94,7 @@ impl Window {
manager.seat_pointer.frame(&mut manager.state); manager.seat_pointer.frame(&mut manager.state);
} }
pub fn send_mouse_up(manager: &mut WayVRCompositor, index: super::MouseIndex) { pub(super) fn send_mouse_up(manager: &mut WayVRCompositor, index: super::MouseIndex) {
manager.seat_pointer.button( manager.seat_pointer.button(
&mut manager.state, &mut manager.state,
&input::pointer::ButtonEvent { &input::pointer::ButtonEvent {
@@ -104,7 +108,7 @@ impl Window {
manager.seat_pointer.frame(&mut manager.state); manager.seat_pointer.frame(&mut manager.state);
} }
pub fn send_mouse_scroll(manager: &mut WayVRCompositor, delta: WheelDelta) { pub(super) fn send_mouse_scroll(manager: &mut WayVRCompositor, delta: WheelDelta) {
manager.seat_pointer.axis( manager.seat_pointer.axis(
&mut manager.state, &mut manager.state,
input::pointer::AxisFrame { input::pointer::AxisFrame {
@@ -123,15 +127,24 @@ impl Window {
} }
} }
#[derive(Debug)]
pub struct MouseState {
pub hover_window: WindowHandle,
pub x: u32,
pub y: u32,
}
#[derive(Debug)] #[derive(Debug)]
pub struct WindowManager { pub struct WindowManager {
pub windows: WindowVec, pub windows: WindowVec,
pub mouse: Option<MouseState>,
} }
impl WindowManager { impl WindowManager {
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
windows: WindowVec::new(), windows: WindowVec::new(),
mouse: None,
} }
} }

View File

@@ -3,6 +3,7 @@ use smithay::wayland::compositor::with_states;
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc}; use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
use vulkano::image::view::ImageView; use vulkano::image::view::ImageView;
use wgui::gfx::WGfx; use wgui::gfx::WGfx;
use wlx_capture::frame::MouseMeta;
use wlx_common::{ use wlx_common::{
overlays::{BackendAttrib, BackendAttribValue, StereoMode}, overlays::{BackendAttrib, BackendAttribValue, StereoMode},
windowing::{OverlayWindowState, Positioning}, windowing::{OverlayWindowState, Positioning},
@@ -80,7 +81,6 @@ pub fn create_wl_window_overlay(
pub struct WayVRBackend { pub struct WayVRBackend {
name: Arc<str>, name: Arc<str>,
pipeline: Option<ScreenPipeline>, pipeline: Option<ScreenPipeline>,
mouse_transform: Affine2,
interaction_transform: Option<Affine2>, interaction_transform: Option<Affine2>,
window: wayvr::window::WindowHandle, window: wayvr::window::WindowHandle,
wayvr: Rc<RefCell<WayVRData>>, wayvr: Rc<RefCell<WayVRData>>,
@@ -102,7 +102,6 @@ impl WayVRBackend {
pipeline: None, pipeline: None,
wayvr, wayvr,
window, window,
mouse_transform: Affine2::IDENTITY,
interaction_transform: None, interaction_transform: None,
just_resumed: false, just_resumed: false,
meta: None, meta: None,
@@ -195,13 +194,27 @@ impl OverlayBackend for WayVRBackend {
app: &mut state::AppState, app: &mut state::AppState,
rdr: &mut RenderResources, rdr: &mut RenderResources,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mouse = None; //TODO: mouse cursor
let image = self.cur_image.as_ref().unwrap().clone(); let image = self.cur_image.as_ref().unwrap().clone();
let wayvr = &self.wayvr.borrow().data;
let mouse = wayvr
.state
.wm
.mouse
.as_ref()
.filter(|m| m.hover_window == self.window)
.map(|m| {
let extent = image.extent_f32();
MouseMeta {
x: (m.x as f32) / (extent[0] as f32),
y: (m.y as f32) / (extent[1] as f32),
}
});
self.pipeline self.pipeline
.as_mut() .as_mut()
.unwrap() .unwrap()
.render(image, mouse, app, rdr)?; .render(image, mouse.as_ref(), app, rdr)?;
Ok(()) Ok(())
} }
@@ -220,12 +233,10 @@ impl OverlayBackend for WayVRBackend {
fn on_hover(&mut self, _app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult { fn on_hover(&mut self, _app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult {
let wayvr = &mut self.wayvr.borrow_mut().data; let wayvr = &mut self.wayvr.borrow_mut().data;
if let Some((x, y)) = wayvr.state.wm.windows.get(&self.window).map(|window| {
let pos = self.mouse_transform.transform_point2(hit.uv); if let Some(meta) = self.meta.as_ref() {
let x = ((pos.x * (window.size_x as f32)) as u32).max(0); let x = ((hit.uv.x * (meta.extent[0] as f32)) as u32).max(0);
let y = ((pos.y * (window.size_y as f32)) as u32).max(0); let y = ((hit.uv.y * (meta.extent[1] as f32)) as u32).max(0);
(x, y)
}) {
wayvr.state.send_mouse_move(self.window, x, y); wayvr.state.send_mouse_move(self.window, x, y);
} }