From ade68a89c06ef2c15659786df89996b0aaee4180 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 24 Oct 2024 21:34:39 +0300 Subject: [PATCH] Expose internal pointer and touch types Lets the compositor check for click vs. dnd vs. other grabs. --- src/input/pointer/grab.rs | 20 ++++++++++++------ src/input/pointer/mod.rs | 2 +- src/wayland/selection/data_device/dnd_grab.rs | 21 ++++++++++++++++++- src/wayland/selection/data_device/mod.rs | 2 ++ .../selection/data_device/server_dnd_grab.rs | 19 ++++++++++++++++- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/input/pointer/grab.rs b/src/input/pointer/grab.rs index 006b59f5e657..7fe246a13068 100644 --- a/src/input/pointer/grab.rs +++ b/src/input/pointer/grab.rs @@ -336,15 +336,23 @@ impl PointerGrab for DefaultGrab { fn unset(&mut self, _data: &mut D) {} } -// A click grab, basic grab started when an user clicks a surface -// to maintain it focused until the user releases the click. -// -// In case the user maintains several simultaneous clicks, release -// the grab once all are released. -struct ClickGrab { +/// A click grab, basic grab started when an user clicks a surface +/// to maintain it focused until the user releases the click. +/// +/// In case the user maintains several simultaneous clicks, release +/// the grab once all are released. +pub struct ClickGrab { start_data: GrabStartData, } +impl fmt::Debug for ClickGrab { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ClickGrab") + .field("start_data", &self.start_data) + .finish() + } +} + impl PointerGrab for ClickGrab { fn motion( &mut self, diff --git a/src/input/pointer/mod.rs b/src/input/pointer/mod.rs index fe1ed9faf5af..514f743770ab 100644 --- a/src/input/pointer/mod.rs +++ b/src/input/pointer/mod.rs @@ -18,7 +18,7 @@ pub use cursor_image::{CursorImageAttributes, CursorImageStatus, CursorImageSurf mod grab; use grab::DefaultGrab; -pub use grab::{GrabStartData, PointerGrab}; +pub use grab::{ClickGrab, GrabStartData, PointerGrab}; use tracing::{info_span, instrument}; /// An handle to a pointer handler diff --git a/src/wayland/selection/data_device/dnd_grab.rs b/src/wayland/selection/data_device/dnd_grab.rs index 80b5bb160610..1eba7764c9fe 100644 --- a/src/wayland/selection/data_device/dnd_grab.rs +++ b/src/wayland/selection/data_device/dnd_grab.rs @@ -1,5 +1,6 @@ use std::{ cell::RefCell, + fmt, os::unix::io::{AsFd, OwnedFd}, sync::{Arc, Mutex}, }; @@ -32,7 +33,8 @@ use crate::{ use super::{with_source_metadata, ClientDndGrabHandler, DataDeviceHandler}; -pub(crate) struct DnDGrab { +/// Grab during a client-initiated DnD operation. +pub struct DnDGrab { dh: DisplayHandle, pointer_start_data: Option>, touch_start_data: Option>, @@ -45,6 +47,23 @@ pub(crate) struct DnDGrab { seat: Seat, } +impl fmt::Debug for DnDGrab { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("DnDGrab") + .field("dh", &self.dh) + .field("pointer_start_data", &self.pointer_start_data) + .field("touch_start_data", &self.touch_start_data) + .field("data_source", &self.data_source) + .field("current_focus", &self.current_focus) + .field("pending_offers", &self.pending_offers) + .field("offer_data", &self.offer_data) + .field("icon", &self.icon) + .field("origin", &self.origin) + .field("seat", &self.seat) + .finish() + } +} + impl DnDGrab { pub(crate) fn new_pointer( dh: &DisplayHandle, diff --git a/src/wayland/selection/data_device/mod.rs b/src/wayland/selection/data_device/mod.rs index a44c69beb680..fa8fa9db9dbf 100644 --- a/src/wayland/selection/data_device/mod.rs +++ b/src/wayland/selection/data_device/mod.rs @@ -100,6 +100,8 @@ mod server_dnd_grab; mod source; pub use device::{DataDeviceUserData, DND_ICON_ROLE}; +pub use dnd_grab::DnDGrab; +pub use server_dnd_grab::ServerDnDGrab; pub use source::{with_source_metadata, DataSourceUserData, SourceMetadata}; use super::{ diff --git a/src/wayland/selection/data_device/server_dnd_grab.rs b/src/wayland/selection/data_device/server_dnd_grab.rs index c3858a78c8fa..4a618bd85afc 100644 --- a/src/wayland/selection/data_device/server_dnd_grab.rs +++ b/src/wayland/selection/data_device/server_dnd_grab.rs @@ -1,5 +1,6 @@ use std::{ cell::RefCell, + fmt, os::unix::io::OwnedFd, sync::{Arc, Mutex}, }; @@ -33,7 +34,8 @@ use crate::{ use super::{DataDeviceHandler, DataDeviceUserData, ServerDndGrabHandler, SourceMetadata}; -pub(crate) struct ServerDnDGrab { +/// Grab during a compositor-initiated DnD operation. +pub struct ServerDnDGrab { dh: DisplayHandle, pointer_start_data: Option>, touch_start_data: Option>, @@ -44,6 +46,21 @@ pub(crate) struct ServerDnDGrab { seat: Seat, } +impl fmt::Debug for ServerDnDGrab { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ServerDnDGrab") + .field("dh", &self.dh) + .field("pointer_start_data", &self.pointer_start_data) + .field("touch_start_data", &self.touch_start_data) + .field("metadata", &self.metadata) + .field("current_focus", &self.current_focus) + .field("pending_offers", &self.pending_offers) + .field("offer_data", &self.offer_data) + .field("seat", &self.seat) + .finish() + } +} + impl ServerDnDGrab { pub(crate) fn new_pointer( dh: &DisplayHandle,