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) {
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) {

View File

@@ -42,7 +42,7 @@ impl Window {
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 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();
// Change keyboard focus to pressed window
@@ -90,7 +94,7 @@ impl Window {
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(
&mut manager.state,
&input::pointer::ButtonEvent {
@@ -104,7 +108,7 @@ impl Window {
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(
&mut manager.state,
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)]
pub struct WindowManager {
pub windows: WindowVec,
pub mouse: Option<MouseState>,
}
impl WindowManager {
pub const fn new() -> Self {
Self {
windows: WindowVec::new(),
mouse: None,
}
}