From 5c88ceac83b1261eced752810ee564570c3b2f31 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Wed, 20 Sep 2023 15:30:40 -0500 Subject: [PATCH] Move pointer_grab_start_data into grab --- src/grab.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/grab/move_grab.rs | 2 +- src/grab/resize_grab.rs | 2 +- src/main.rs | 1 - src/pointer.rs | 40 ---------------------------------------- 5 files changed, 41 insertions(+), 43 deletions(-) delete mode 100644 src/pointer.rs diff --git a/src/grab.rs b/src/grab.rs index 51363d3..2aa97f5 100644 --- a/src/grab.rs +++ b/src/grab.rs @@ -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( + pointer: &PointerHandle, + surface: &WlSurface, + serial: Serial, +) -> Option> +where + S: SeatHandler + '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) +} diff --git a/src/grab/move_grab.rs b/src/grab/move_grab.rs index d42b92c..ae72c30 100644 --- a/src/grab/move_grab.rs +++ b/src/grab/move_grab.rs @@ -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; diff --git a/src/grab/resize_grab.rs b/src/grab/resize_grab.rs index c96509c..4f40247 100644 --- a/src/grab/resize_grab.rs +++ b/src/grab/resize_grab.rs @@ -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; diff --git a/src/main.rs b/src/main.rs index 8734827..cb7ce03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,6 @@ mod handlers; mod input; mod layout; mod output; -mod pointer; mod render; mod state; mod tag; diff --git a/src/pointer.rs b/src/pointer.rs deleted file mode 100644 index c437115..0000000 --- a/src/pointer.rs +++ /dev/null @@ -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( - pointer: &PointerHandle, - surface: &WlSurface, - serial: Serial, -) -> Option> -where - S: SeatHandler + '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) -}