Move pointer_grab_start_data into grab

This commit is contained in:
Ottatop 2023-09-20 15:30:40 -05:00
parent ea913e898c
commit 5c88ceac83
5 changed files with 41 additions and 43 deletions

View file

@ -2,3 +2,42 @@
pub mod move_grab;
pub mod resize_grab;
use smithay::{
input::{
pointer::{GrabStartData, PointerHandle},
SeatHandler,
},
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
utils::Serial,
wayland::seat::WaylandFocus,
};
use crate::focus::FocusTarget;
/// Returns the [GrabStartData] from a pointer grab, if any.
pub fn pointer_grab_start_data<S>(
pointer: &PointerHandle<S>,
surface: &WlSurface,
serial: Serial,
) -> Option<GrabStartData<S>>
where
S: SeatHandler<PointerFocus = FocusTarget> + 'static,
{
tracing::debug!("start of pointer_grab_start_data");
if !pointer.has_grab(serial) {
tracing::debug!("pointer doesn't have grab");
return None;
}
let start_data = pointer.grab_start_data()?;
let (focus_surface, _point) = start_data.focus.as_ref()?;
if !focus_surface.same_client_as(&surface.id()) {
tracing::debug!("surface isn't the same");
return None;
}
Some(start_data)
}

View file

@ -248,7 +248,7 @@ pub fn move_request_client(
button_used: u32,
) {
let pointer = seat.get_pointer().expect("seat had no pointer");
if let Some(start_data) = crate::pointer::pointer_grab_start_data(&pointer, surface, serial) {
if let Some(start_data) = crate::grab::pointer_grab_start_data(&pointer, surface, serial) {
let Some(window) = state.window_for_surface(surface) else {
tracing::error!("Surface had no window, cancelling move request");
return;

View file

@ -431,7 +431,7 @@ pub fn resize_request_client(
) {
let pointer = seat.get_pointer().expect("seat had no pointer");
if let Some(start_data) = crate::pointer::pointer_grab_start_data(&pointer, surface, serial) {
if let Some(start_data) = crate::grab::pointer_grab_start_data(&pointer, surface, serial) {
let Some(window) = state.window_for_surface(surface) else {
tracing::error!("Surface had no window, cancelling resize request");
return;

View file

@ -25,7 +25,6 @@ mod handlers;
mod input;
mod layout;
mod output;
mod pointer;
mod render;
mod state;
mod tag;

View file

@ -1,40 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use smithay::{
input::{
pointer::{GrabStartData, PointerHandle},
SeatHandler,
},
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
utils::Serial,
wayland::seat::WaylandFocus,
};
use crate::focus::FocusTarget;
/// Returns the [GrabStartData] from a pointer grab, if any.
pub fn pointer_grab_start_data<S>(
pointer: &PointerHandle<S>,
surface: &WlSurface,
serial: Serial,
) -> Option<GrabStartData<S>>
where
S: SeatHandler<PointerFocus = FocusTarget> + 'static,
{
tracing::debug!("start of pointer_grab_start_data");
if !pointer.has_grab(serial) {
tracing::debug!("pointer doesn't have grab");
return None;
}
let start_data = pointer.grab_start_data()?;
let (focus_surface, _point) = start_data.focus.as_ref()?;
if !focus_surface.same_client_as(&surface.id()) {
tracing::debug!("surface isn't the same");
return None;
}
Some(start_data)
}