Skip to content

Commit

Permalink
Expose internal pointer and touch types
Browse files Browse the repository at this point in the history
Lets the compositor check for click vs. dnd vs. other grabs.
  • Loading branch information
YaLTeR authored and Drakulix committed Oct 27, 2024
1 parent 57e2bcd commit ade68a8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/input/pointer/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,23 @@ impl<D: SeatHandler + 'static> PointerGrab<D> 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<D: SeatHandler> {
/// 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<D: SeatHandler> {
start_data: GrabStartData<D>,
}

impl<D: SeatHandler + 'static> fmt::Debug for ClickGrab<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ClickGrab")
.field("start_data", &self.start_data)
.finish()
}
}

impl<D: SeatHandler + 'static> PointerGrab<D> for ClickGrab<D> {
fn motion(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/input/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/wayland/selection/data_device/dnd_grab.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
cell::RefCell,
fmt,
os::unix::io::{AsFd, OwnedFd},
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -32,7 +33,8 @@ use crate::{

use super::{with_source_metadata, ClientDndGrabHandler, DataDeviceHandler};

pub(crate) struct DnDGrab<D: SeatHandler> {
/// Grab during a client-initiated DnD operation.
pub struct DnDGrab<D: SeatHandler> {
dh: DisplayHandle,
pointer_start_data: Option<PointerGrabStartData<D>>,
touch_start_data: Option<TouchGrabStartData<D>>,
Expand All @@ -45,6 +47,23 @@ pub(crate) struct DnDGrab<D: SeatHandler> {
seat: Seat<D>,
}

impl<D: SeatHandler + 'static> fmt::Debug for DnDGrab<D> {
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<D: SeatHandler> DnDGrab<D> {
pub(crate) fn new_pointer(
dh: &DisplayHandle,
Expand Down
2 changes: 2 additions & 0 deletions src/wayland/selection/data_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
19 changes: 18 additions & 1 deletion src/wayland/selection/data_device/server_dnd_grab.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
cell::RefCell,
fmt,
os::unix::io::OwnedFd,
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -33,7 +34,8 @@ use crate::{

use super::{DataDeviceHandler, DataDeviceUserData, ServerDndGrabHandler, SourceMetadata};

pub(crate) struct ServerDnDGrab<D: SeatHandler> {
/// Grab during a compositor-initiated DnD operation.
pub struct ServerDnDGrab<D: SeatHandler> {
dh: DisplayHandle,
pointer_start_data: Option<PointerGrabStartData<D>>,
touch_start_data: Option<TouchGrabStartData<D>>,
Expand All @@ -44,6 +46,21 @@ pub(crate) struct ServerDnDGrab<D: SeatHandler> {
seat: Seat<D>,
}

impl<D: SeatHandler + 'static> fmt::Debug for ServerDnDGrab<D> {
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<D: SeatHandler> ServerDnDGrab<D> {
pub(crate) fn new_pointer(
dh: &DisplayHandle,
Expand Down

0 comments on commit ade68a8

Please sign in to comment.