wayland: implement pointer_warp_v1

This commit is contained in:
Skygrango 2026-05-24 01:47:57 +08:00 committed by Jacob Kauffmann
parent 821b431973
commit b6cab38528
3 changed files with 47 additions and 0 deletions

View file

@ -86,6 +86,7 @@ use smithay::{
output::OutputManagerState, output::OutputManagerState,
pointer_constraints::PointerConstraintsState, pointer_constraints::PointerConstraintsState,
pointer_gestures::PointerGesturesState, pointer_gestures::PointerGesturesState,
pointer_warp::PointerWarpManager,
presentation::PresentationState, presentation::PresentationState,
seat::WaylandFocus, seat::WaylandFocus,
security_context::{SecurityContext, SecurityContextState}, security_context::{SecurityContext, SecurityContextState},
@ -671,6 +672,7 @@ impl State {
XWaylandKeyboardGrabState::new::<Self>(dh); XWaylandKeyboardGrabState::new::<Self>(dh);
let xwayland_shell_state = XWaylandShellState::new::<Self>(dh); let xwayland_shell_state = XWaylandShellState::new::<Self>(dh);
PointerConstraintsState::new::<Self>(dh); PointerConstraintsState::new::<Self>(dh);
PointerWarpManager::new::<Self>(dh);
PointerGesturesState::new::<Self>(dh); PointerGesturesState::new::<Self>(dh);
TabletManagerState::new::<Self>(dh); TabletManagerState::new::<Self>(dh);
SecurityContextState::new::<Self, _>(dh, client_has_no_security_context); SecurityContextState::new::<Self, _>(dh, client_has_no_security_context);

View file

@ -25,6 +25,7 @@ pub mod output_configuration;
pub mod output_power; pub mod output_power;
pub mod overlap_notify; pub mod overlap_notify;
pub mod pointer_constraints; pub mod pointer_constraints;
pub mod pointer_warp;
pub mod primary_selection; pub mod primary_selection;
pub mod seat; pub mod seat;
pub mod security_context; pub mod security_context;

View file

@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::state::State;
use smithay::{
input::pointer::PointerHandle,
reexports::wayland_server::protocol::{wl_pointer::WlPointer, wl_surface::WlSurface},
utils::{Logical, Point, Serial},
wayland::pointer_warp::PointerWarpHandler,
};
impl PointerWarpHandler for State {
fn warp_pointer(
&mut self,
surface: WlSurface,
pointer: WlPointer,
pos: Point<f64, Logical>,
serial: Serial,
) {
let Some(resource_handle) = PointerHandle::<State>::from_resource(&pointer) else {
return;
};
let shell = self.common.shell.read();
let pointer_handle = shell.seats.iter().find_map(|seat| {
if let Some(pointer_handle) = seat.get_pointer()
&& resource_handle == pointer_handle
&& pointer_handle.last_enter() == Some(serial)
&& let Some(keyboard) = seat.get_keyboard()
&& let Some(keyboard_focus) = keyboard.current_focus()
&& keyboard_focus.has_surface(&shell, &surface)
{
return Some(pointer_handle);
}
None
});
drop(shell);
if let Some(pointer_handle) = pointer_handle {
self.apply_cursor_hint(&surface, &pointer_handle, pos);
}
}
}