From e9eb698dd02e16a8087d9f9f9b74733af1584b4b Mon Sep 17 00:00:00 2001 From: Poly Date: Fri, 12 Feb 2021 22:13:38 +0100 Subject: [PATCH] [Debug Trait] wayland wayland/compositor wayland/data_device wayland/dmabuf wayland/explicit_synchronization wayland/output wayland/seat wayland/shell wayland/shm --- src/wayland/compositor/mod.rs | 23 ++++++++++++-- src/wayland/compositor/tree.rs | 1 + src/wayland/data_device/mod.rs | 3 +- src/wayland/data_device/server_dnd_grab.rs | 1 + src/wayland/dmabuf/mod.rs | 3 ++ src/wayland/explicit_synchronization/mod.rs | 3 ++ src/wayland/mod.rs | 1 + src/wayland/output/mod.rs | 5 ++- src/wayland/seat/keyboard.rs | 20 +++++++++++- src/wayland/seat/mod.rs | 16 ++++++++-- src/wayland/seat/pointer.rs | 35 ++++++++++++++++++--- src/wayland/shell/legacy/mod.rs | 5 +++ src/wayland/shell/xdg/mod.rs | 15 ++++++++- src/wayland/shm/mod.rs | 2 +- 14 files changed, 119 insertions(+), 14 deletions(-) diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 43aeca7..40b5e1b 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -68,7 +68,7 @@ //! surfaces. See the documentation of the [`roles`](::wayland::compositor::roles) submodule //! for a detailed explanation. -use std::{cell::RefCell, rc::Rc, sync::Mutex}; +use std::{cell::RefCell, fmt, rc::Rc, sync::Mutex}; mod handlers; pub mod roles; @@ -89,6 +89,7 @@ use wayland_server::{ /// Description of which part of a surface /// should be considered damaged and needs to be redrawn +#[derive(Debug)] pub enum Damage { /// The whole surface must be considered damaged (this is the default) Full, @@ -100,12 +101,13 @@ pub enum Damage { Buffer(Rectangle), } -#[derive(Copy, Clone, Default)] +#[derive(Debug, Copy, Clone, Default)] struct Marker { _r: ::std::marker::PhantomData, } /// New buffer assignation for a surface +#[derive(Debug)] pub enum BufferAssignment { /// The surface no longer has a buffer attached to it Removed, @@ -170,6 +172,21 @@ pub struct SurfaceAttributes { pub user_data: UserDataMap, } +impl fmt::Debug for SurfaceAttributes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SurfaceAttributes") + .field("buffer", &self.buffer) + .field("buffer_scale", &self.buffer_scale) + .field("buffer_transform", &self.buffer_transform) + .field("opaque_region", &self.opaque_region) + .field("input_region", &self.input_region) + .field("damage", &self.damage) + .field("frame_callback", &self.frame_callback) + .field("user_data", &"...") + .finish() + } +} + impl Default for SurfaceAttributes { fn default() -> SurfaceAttributes { SurfaceAttributes { @@ -259,6 +276,7 @@ impl RegionAttributes { /// access data associated with the [`wl_surface`](wayland_server::protocol::wl_surface) /// and [`wl_region`](wayland_server::protocol::wl_region) managed /// by the `CompositorGlobal` that provided it. +#[derive(Debug)] pub struct CompositorToken { _role: ::std::marker::PhantomData<*mut R>, } @@ -516,6 +534,7 @@ where /// The global provided by smithay cannot process these events for you, so /// they are forwarded directly via your provided implementation, and are /// described by this global. +#[derive(Debug)] pub enum SurfaceEvent { /// The double-buffered state has been validated by the client /// diff --git a/src/wayland/compositor/tree.rs b/src/wayland/compositor/tree.rs index e25a81c..7b20878 100644 --- a/src/wayland/compositor/tree.rs +++ b/src/wayland/compositor/tree.rs @@ -28,6 +28,7 @@ pub enum Location { } /// Possible actions to do after handling a node diring tree traversal +#[derive(Debug)] pub enum TraversalAction { /// Traverse its children as well, providing them the data T DoChildren(T), diff --git a/src/wayland/data_device/mod.rs b/src/wayland/data_device/mod.rs index ab128e6..d223e56 100644 --- a/src/wayland/data_device/mod.rs +++ b/src/wayland/data_device/mod.rs @@ -78,6 +78,7 @@ pub use self::data_source::{with_source_metadata, SourceMetadata}; pub use self::server_dnd_grab::ServerDndEvent; /// Events that are generated by interactions of the clients with the data device +#[derive(Debug)] pub enum DataDeviceEvent { /// A client has set the selection NewSelection(Option), @@ -108,7 +109,7 @@ pub enum DataDeviceEvent { } /// The role applied to surfaces used as DnD icons -#[derive(Default)] +#[derive(Debug, Default)] pub struct DnDIconRole; enum Selection { diff --git a/src/wayland/data_device/server_dnd_grab.rs b/src/wayland/data_device/server_dnd_grab.rs index 8672acc..22af98f 100644 --- a/src/wayland/data_device/server_dnd_grab.rs +++ b/src/wayland/data_device/server_dnd_grab.rs @@ -11,6 +11,7 @@ use crate::wayland::Serial; use super::{DataDeviceData, SeatData}; /// Event generated by the interactions of clients with a server initiated drag'n'drop +#[derive(Debug)] pub enum ServerDndEvent { /// The client chose an action Action(DndAction), diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index 7ebb0c7..5a152f1 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -76,6 +76,7 @@ use wayland_protocols::unstable::linux_dmabuf::v1::server::{ use wayland_server::{protocol::wl_buffer, Display, Filter, Global, Main}; /// Representation of a Dmabuf format, as advertized to the client +#[derive(Debug)] pub struct Format { /// The format identifier. pub format: ::drm::buffer::format::PixelFormat, @@ -89,6 +90,7 @@ pub struct Format { } /// A plane send by the client +#[derive(Debug)] pub struct Plane { /// The file descriptor pub fd: RawFd, @@ -115,6 +117,7 @@ bitflags! { } /// The complete information provided by the client to create a dmabuf buffer +#[derive(Debug)] pub struct BufferInfo { /// The submitted planes pub planes: Vec, diff --git a/src/wayland/explicit_synchronization/mod.rs b/src/wayland/explicit_synchronization/mod.rs index 9b5d59b..0a8012f 100644 --- a/src/wayland/explicit_synchronization/mod.rs +++ b/src/wayland/explicit_synchronization/mod.rs @@ -86,6 +86,7 @@ use wayland_server::{protocol::wl_surface::WlSurface, Display, Filter, Global, M use crate::wayland::compositor::{CompositorToken, SurfaceAttributes}; /// An object to signal end of use of a buffer +#[derive(Debug)] pub struct ExplicitBufferRelease { release: ZwpLinuxBufferReleaseV1, } @@ -111,6 +112,7 @@ impl ExplicitBufferRelease { /// The client is not required to fill both. `acquire` being `None` means that you don't need to wait /// before acessing the buffer, `release` being `None` means that the client does not require additionnal /// signaling that you are finished (you still need to send `wl_buffer.release`). +#[derive(Debug)] pub struct ExplicitSyncState { /// An acquire `dma_fence` object, that you should wait on before accessing the contents of the /// buffer associated with the surface. @@ -143,6 +145,7 @@ impl ESUserData { } /// Possible errors you can send to an ill-behaving clients +#[derive(Debug)] pub enum ExplicitSyncError { /// An invalid file descriptor was sent by the client for an acquire fence InvalidFence, diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 8906e7e..876bedd 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -80,6 +80,7 @@ impl From for u32 { /// /// The counter will wrap around on overflow, ensuring it can run for as long /// as needed. +#[derive(Debug)] pub struct SerialCounter { // TODO: replace with an AtomicU32 when stabilized serial: AtomicUsize, diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 73b199a..05dfda1 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -65,7 +65,7 @@ use wayland_server::{ /// /// This should only describe the characteristics of the video driver, /// not taking into account any global scaling. -#[derive(Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct Mode { /// The width in pixels pub width: i32, @@ -78,6 +78,7 @@ pub struct Mode { } /// The physical properties of an output +#[derive(Debug)] pub struct PhysicalProperties { /// The width in millimeters pub width: i32, @@ -91,6 +92,7 @@ pub struct PhysicalProperties { pub model: String, } +#[derive(Debug)] struct Inner { name: String, log: ::slog::Logger, @@ -155,6 +157,7 @@ impl Inner { /// /// This handle is stored in the event loop, and allows you to notify clients /// about any change in the properties of this output. +#[derive(Debug)] pub struct Output { inner: Arc>, } diff --git a/src/wayland/seat/keyboard.rs b/src/wayland/seat/keyboard.rs index 4242ae9..7244f92 100644 --- a/src/wayland/seat/keyboard.rs +++ b/src/wayland/seat/keyboard.rs @@ -3,6 +3,7 @@ use crate::wayland::Serial; use std::{ cell::RefCell, default::Default, + fmt, io::{Error as IoError, Write}, ops::Deref as _, os::unix::io::AsRawFd, @@ -119,6 +120,22 @@ struct KbdInternal { focus_hook: Box)>, } +impl fmt::Debug for KbdInternal { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("KbdInternal") + .field("known_kbds", &self.known_kbds) + .field("focus", &self.focus) + .field("pressed_keys", &self.pressed_keys) + .field("mods_state", &self.mods_state) + .field("keymap", &self.keymap.get_raw_ptr()) + .field("state", &self.state.get_raw_ptr()) + .field("repeat_rate", &self.repeat_rate) + .field("repeat_delay", &self.repeat_delay) + .field("focus_hook", &"...") + .finish() + } +} + // This is OK because all parts of `xkb` will remain on the // same thread unsafe impl Send for KbdInternal {} @@ -267,6 +284,7 @@ where }) } +#[derive(Debug)] struct KbdRc { internal: RefCell, keymap: String, @@ -284,7 +302,7 @@ struct KbdRc { /// - process key inputs from the input backend, allowing them to be caught at the compositor-level /// or forwarded to the client. See the documentation of the [`KeyboardHandle::input`] method for /// details. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct KeyboardHandle { arc: Rc, } diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index a36c964..385dca8 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -40,7 +40,7 @@ //! These methods return handles that can be cloned and sent across thread, so you can keep one around //! in your event-handling code to forward inputs to your clients. -use std::{cell::RefCell, ops::Deref as _, rc::Rc}; +use std::{cell::RefCell, fmt, ops::Deref as _, rc::Rc}; mod keyboard; mod pointer; @@ -60,6 +60,7 @@ use wayland_server::{ Display, Filter, Global, Main, UserDataMap, }; +#[derive(Debug)] struct Inner { pointer: Option, keyboard: Option, @@ -73,6 +74,17 @@ pub(crate) struct SeatRc { name: String, } +impl fmt::Debug for SeatRc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SeatRc") + .field("inner", &self.inner) + .field("user_data", &"...") + .field("log", &self.log) + .field("name", &self.name) + .finish() + } +} + impl Inner { fn compute_caps(&self) -> wl_seat::Capability { let mut caps = wl_seat::Capability::empty(); @@ -103,7 +115,7 @@ impl Inner { /// This is an handle to the inner logic, it can be cloned. /// /// See module-level documentation for details of use. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Seat { pub(crate) arc: Rc, } diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 14754b0..0933ded 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, ops::Deref as _, rc::Rc}; +use std::{cell::RefCell, fmt, ops::Deref as _, rc::Rc}; use wayland_server::{ protocol::{ @@ -12,14 +12,14 @@ use crate::wayland::compositor::{roles::Role, CompositorToken}; use crate::wayland::Serial; /// The role representing a surface set as the pointer cursor -#[derive(Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct CursorImageRole { /// Location of the hotspot of the pointer in the surface pub hotspot: (i32, i32), } /// Possible status of a cursor as requested by clients -#[derive(Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum CursorImageStatus { /// The cursor should be hidden Hidden, @@ -35,6 +35,16 @@ enum GrabStatus { Borrowed, } +impl fmt::Debug for GrabStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + GrabStatus::None => f.debug_tuple("GrabStatus::None").finish(), + GrabStatus::Active(serial, _) => f.debug_tuple("GrabStatus::Active").field(&serial).finish(), + GrabStatus::Borrowed => f.debug_tuple("GrabStatus::Borrowed").finish(), + } + } +} + struct PointerInternal { known_pointers: Vec, focus: Option<(WlSurface, (f64, f64))>, @@ -45,6 +55,20 @@ struct PointerInternal { image_callback: Box, } +impl fmt::Debug for PointerInternal { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Point") + .field("known_pointers", &self.known_pointers) + .field("focus", &self.focus) + .field("pending_focus", &self.pending_focus) + .field("location", &self.location) + .field("grab", &self.grab) + .field("pressed_buttons", &self.pressed_buttons) + .field("image_callback", &"...") + .finish() + } +} + impl PointerInternal { fn new(token: CompositorToken, mut cb: F) -> PointerInternal where @@ -125,7 +149,7 @@ impl PointerInternal { /// /// When sending events using this handle, they will be intercepted by a pointer /// grab if any is active. See the [`PointerGrab`] trait for details. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct PointerHandle { inner: Rc>, } @@ -233,7 +257,7 @@ impl PointerHandle { } /// Data about the event that started the grab. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct GrabStartData { /// The focused surface and its location, if any, at the start of the grab. /// @@ -287,6 +311,7 @@ pub trait PointerGrab { /// This inner handle is accessed from inside a pointer grab logic, and directly /// sends event to the client +#[derive(Debug)] pub struct PointerInnerHandle<'a> { inner: &'a mut PointerInternal, } diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index ea7c33d..518b6cf 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -77,6 +77,7 @@ use wayland_server::{ mod wl_handlers; /// Metadata associated with the `wl_surface` role +#[derive(Debug)] pub struct ShellSurfaceRole { /// Title of the surface pub title: String, @@ -86,6 +87,7 @@ pub struct ShellSurfaceRole { } /// A handle to a shell surface +#[derive(Debug)] pub struct ShellSurface { wl_surface: wl_surface::WlSurface, shell_surface: wl_shell_surface::WlShellSurface, @@ -169,6 +171,7 @@ where } /// Possible kinds of shell surface of the `wl_shell` protocol +#[derive(Debug)] pub enum ShellSurfaceKind { /// Toplevel, a regular window displayed somewhere in the compositor space Toplevel, @@ -222,6 +225,7 @@ pub enum ShellSurfaceKind { } /// A request triggered by a `wl_shell_surface` +#[derive(Debug)] pub enum ShellRequest { /// A new shell surface was created /// @@ -275,6 +279,7 @@ pub enum ShellRequest { /// /// This state allows you to retrieve a list of surfaces /// currently known to the shell global. +#[derive(Debug)] pub struct ShellState { known_surfaces: Vec>, } diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 2d358f7..4fea174 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -109,6 +109,7 @@ mod xdg_handlers; mod zxdgv6_handlers; /// Metadata associated with the `xdg_surface` role +#[derive(Debug)] pub struct XdgSurfaceRole { /// Pending state as requested by the client /// @@ -177,6 +178,7 @@ impl PositionerState { } /// Contents of the pending state of a shell surface, depending on its role +#[derive(Debug)] pub enum XdgSurfacePendingState { /// This a regular, toplevel surface /// @@ -196,6 +198,7 @@ pub enum XdgSurfacePendingState { } /// State of a regular toplevel surface +#[derive(Debug)] pub struct ToplevelState { /// Parent of this surface /// @@ -233,6 +236,7 @@ impl Clone for ToplevelState { } /// The pending state of a popup surface +#[derive(Debug)] pub struct PopupState { /// Parent of this popup surface pub parent: Option, @@ -326,6 +330,7 @@ where /// /// This state allows you to retrieve a list of surfaces /// currently known to the shell global. +#[derive(Debug)] pub struct ShellState { known_toplevels: Vec>, known_popups: Vec>, @@ -350,6 +355,7 @@ where * User interaction */ +#[derive(Debug)] enum ShellClientKind { Xdg(xdg_wm_base::XdgWmBase), ZxdgV6(zxdg_shell_v6::ZxdgShellV6), @@ -377,6 +383,7 @@ fn make_shell_client_data() -> ShellClientData { /// /// You can use this handle to access a storage for any /// client-specific data you wish to associate with it. +#[derive(Debug)] pub struct ShellClient { kind: ShellClientKind, _token: CompositorToken, @@ -481,13 +488,14 @@ where } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub(crate) enum ToplevelKind { Xdg(xdg_toplevel::XdgToplevel), ZxdgV6(zxdg_toplevel_v6::ZxdgToplevelV6), } /// A handle to a toplevel surface +#[derive(Debug)] pub struct ToplevelSurface { wl_surface: wl_surface::WlSurface, shell_surface: ToplevelKind, @@ -650,6 +658,7 @@ where } } +#[derive(Debug)] pub(crate) enum PopupKind { Xdg(xdg_popup::XdgPopup), ZxdgV6(zxdg_popup_v6::ZxdgPopupV6), @@ -659,6 +668,7 @@ pub(crate) enum PopupKind { /// /// This is an unified abstraction over the popup surfaces /// of both `wl_shell` and `xdg_shell`. +#[derive(Debug)] pub struct PopupSurface { wl_surface: wl_surface::WlSurface, shell_surface: PopupKind, @@ -818,6 +828,7 @@ where } /// A configure message for toplevel surfaces +#[derive(Debug)] pub struct ToplevelConfigure { /// A suggestion for a new size for the surface pub size: Option<(i32, i32)>, @@ -835,6 +846,7 @@ pub struct ToplevelConfigure { } /// A configure message for popup surface +#[derive(Debug)] pub struct PopupConfigure { /// The position chosen for this popup relative to /// its parent @@ -855,6 +867,7 @@ pub struct PopupConfigure { /// for you directly. /// /// Depending on what you want to do, you might ignore some of them +#[derive(Debug)] pub enum XdgRequest { /// A new shell client was instantiated NewClient { diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index b86e945..47c3b40 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -82,7 +82,7 @@ use wayland_server::{ mod pool; -#[derive(Clone)] +#[derive(Debug, Clone)] /// Internal data storage of `ShmGlobal` /// /// This type is only visible as type parameter of