From f6a63d351d9bcb9339c274d5426ca4b636117dc0 Mon Sep 17 00:00:00 2001 From: Poly Date: Tue, 9 Feb 2021 20:57:14 +0100 Subject: [PATCH 1/9] [Debug Trait] input.rs, udev.rs, winit.rs smithay/smithay#258 --- src/backend/input.rs | 2 ++ src/backend/udev.rs | 13 +++++++++++++ src/backend/winit.rs | 32 ++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/backend/input.rs b/src/backend/input.rs index 24625d5..330aafe 100644 --- a/src/backend/input.rs +++ b/src/backend/input.rs @@ -87,6 +87,7 @@ pub trait Event { /// that is not used by an [`InputBackend`] implementation. Initialization is not /// possible, making accidental use impossible and enabling a lot of possible /// compiler optimizations. +#[derive(Debug)] pub enum UnusedEvent {} impl Event for UnusedEvent { @@ -537,6 +538,7 @@ pub trait InputBackend: Sized { } /// Different events that can be generated by an input backend +#[derive(Debug)] pub enum InputEvent { /// A new seat has been created NewSeat(Seat), diff --git a/src/backend/udev.rs b/src/backend/udev.rs index ffae665..45fe192 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -43,6 +43,7 @@ use nix::sys::stat::{dev_t, stat}; use std::{ collections::HashMap, ffi::OsString, + fmt, io::Result as IoResult, os::unix::io::{AsRawFd, RawFd}, path::{Path, PathBuf}, @@ -62,6 +63,17 @@ pub struct UdevBackend { logger: ::slog::Logger, } +impl fmt::Debug for UdevBackend { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use udev::AsRaw; + f.debug_struct("UdevBackend") + .field("devices", &self.devices) + .field("monitor", &format!("MonitorSocket ({:?})", self.monitor.as_raw())) + .field("logger", &self.logger) + .finish() + } +} + impl AsRawFd for UdevBackend { fn as_raw_fd(&self) -> RawFd { self.monitor.as_raw_fd() @@ -182,6 +194,7 @@ impl EventSource for UdevBackend { } /// Events generated by the [`UdevBackend`], notifying you of changes in system devices +#[derive(Debug)] pub enum UdevEvent { /// A new device has been detected Added { diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 9896cf7..995c6fd 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -16,6 +16,7 @@ use nix::libc::c_void; use std::{ cell::{Ref, RefCell}, convert::TryInto, + fmt, rc::Rc, time::Instant, }; @@ -65,6 +66,16 @@ enum Window { }, } +impl fmt::Debug for Window { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Window::Wayland { .. } => f.debug_tuple("Window::Wayland"), + Window::X11 { .. } => f.debug_tuple("Window::X11"), + } + .finish() + } +} + impl Window { fn window(&self) -> Ref<'_, WinitWindow> { match *self { @@ -74,6 +85,7 @@ impl Window { } } +#[derive(Debug)] struct WindowSize { physical_size: PhysicalSize, scale_factor: f64, @@ -81,6 +93,7 @@ struct WindowSize { /// Window with an active EGL Context created by `winit`. Implements the /// [`EGLGraphicsBackend`] and [`GLGraphicsBackend`] graphics backend trait +#[derive(Debug)] pub struct WinitGraphicsBackend { window: Rc, size: Rc>, @@ -91,6 +104,7 @@ pub struct WinitGraphicsBackend { /// /// You need to call [`dispatch_new_events`](InputBackend::dispatch_new_events) /// periodically to receive any events. +#[derive(Debug)] pub struct WinitInputBackend { events_loop: EventLoop<()>, window: Rc, @@ -226,6 +240,7 @@ where } /// Specific events generated by Winit +#[derive(Debug)] pub enum WinitEvent { /// The window has been resized Resized { @@ -358,8 +373,8 @@ pub enum WinitInputError { WindowClosed, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] /// Winit-Backend internal event wrapping `winit`'s types into a [`KeyboardKeyEvent`] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WinitKeyboardInputEvent { time: u32, key: u32, @@ -387,8 +402,8 @@ impl KeyboardKeyEvent for WinitKeyboardInputEvent { } } -#[derive(Clone)] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerMotionAbsoluteEvent`] +#[derive(Debug, Clone)] pub struct WinitMouseMovedEvent { size: Rc>, time: u32, @@ -426,8 +441,8 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { } } -#[derive(Debug, Clone, Copy, PartialEq)] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerAxisEvent`] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct WinitMouseWheelEvent { time: u32, delta: MouseScrollDelta, @@ -464,8 +479,8 @@ impl PointerAxisEvent for WinitMouseWheelEvent { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerButtonEvent`] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WinitMouseInputEvent { time: u32, button: WinitMouseButton, @@ -488,8 +503,8 @@ impl PointerButtonEvent for WinitMouseInputEvent { } } -#[derive(Clone)] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchDownEvent`] +#[derive(Debug, Clone)] pub struct WinitTouchStartedEvent { size: Rc>, time: u32, @@ -531,8 +546,8 @@ impl TouchDownEvent for WinitTouchStartedEvent { } } -#[derive(Clone)] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchMotionEvent`] +#[derive(Debug, Clone)] pub struct WinitTouchMovedEvent { size: Rc>, time: u32, @@ -574,8 +589,8 @@ impl TouchMotionEvent for WinitTouchMovedEvent { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] /// Winit-Backend internal event wrapping `winit`'s types into a `TouchUpEvent` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WinitTouchEndedEvent { time: u32, id: u64, @@ -593,8 +608,8 @@ impl TouchUpEvent for WinitTouchEndedEvent { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchCancelEvent`] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WinitTouchCancelledEvent { time: u32, id: u64, @@ -615,6 +630,7 @@ impl TouchCancelEvent for WinitTouchCancelledEvent { /// Input config for Winit /// /// This backend does not allow any input configuration, so this type does nothing. +#[derive(Debug)] pub struct WinitInputConfig; impl InputBackend for WinitInputBackend { From bb90631d658987f281f8eb1902f21ffd9eb2ad7a Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 10 Feb 2021 03:22:37 +0100 Subject: [PATCH 2/9] [Debug Trait] signaling.rs --- src/signaling.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/signaling.rs b/src/signaling.rs index 6a12a2e..9a6743d 100644 --- a/src/signaling.rs +++ b/src/signaling.rs @@ -21,10 +21,12 @@ use std::{ any::Any, cell::RefCell, collections::VecDeque, + fmt, rc::{Rc, Weak}, }; /// A signaler, main type for signaling +#[derive(Debug)] pub struct Signaler { inner: Rc>, } @@ -88,6 +90,7 @@ impl Default for Signaler { /// Dropping it will disable and drop the callback it is associated to. /// If you don't plan to ever disable the callback, you can use the `leak` /// method to safely get rid of this value. +#[derive(Debug)] pub struct SignalToken { signal: Rc, } @@ -108,6 +111,16 @@ struct SignalInner { pending_events: RefCell>, } +impl fmt::Debug for SignalInner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SignalInner") + .field("callbacks::len()", &self.callbacks.borrow().len()) + .field("pending_callbacks::len()", &self.pending_callbacks.borrow().len()) + .field("pending_events", &self.pending_events) + .finish() + } +} + impl SignalInner { fn new() -> SignalInner { SignalInner { From f96fcee1fd3af11874b5dacc18e24cacebad3ed4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 10 Feb 2021 03:37:17 +0100 Subject: [PATCH 3/9] [Debug Trait] backend backend/libinput backend/egl backend/drm backend/session --- src/backend/drm/atomic/mod.rs | 30 +++++++++++++++++++++++++++ src/backend/drm/atomic/session.rs | 1 + src/backend/drm/atomic/surface.rs | 16 ++++++++++++++ src/backend/drm/common/fallback.rs | 31 ++++++++++++++++++++++++++++ src/backend/drm/egl/mod.rs | 23 +++++++++++++++++++++ src/backend/drm/egl/session.rs | 1 + src/backend/drm/egl/surface.rs | 2 ++ src/backend/drm/eglstream/egl.rs | 1 + src/backend/drm/eglstream/mod.rs | 11 ++++++++++ src/backend/drm/eglstream/session.rs | 1 + src/backend/drm/eglstream/surface.rs | 3 +++ src/backend/egl/context.rs | 1 + src/backend/egl/display.rs | 13 ++++++++++++ src/backend/egl/mod.rs | 14 +++++++++++++ src/backend/egl/native.rs | 3 +++ src/backend/egl/surface.rs | 1 + src/backend/graphics/gl.rs | 10 +++++++++ src/backend/graphics/glium.rs | 11 ++++++++++ src/backend/libinput/mod.rs | 17 +++++++++++++++ src/backend/session/auto.rs | 3 ++- src/backend/session/dbus/logind.rs | 19 +++++++++++++++-- src/backend/session/direct.rs | 21 +++++++++++++++++++ 22 files changed, 230 insertions(+), 3 deletions(-) diff --git a/src/backend/drm/atomic/mod.rs b/src/backend/drm/atomic/mod.rs index 507abd3..856c017 100644 --- a/src/backend/drm/atomic/mod.rs +++ b/src/backend/drm/atomic/mod.rs @@ -20,6 +20,7 @@ use std::cell::RefCell; use std::collections::HashMap; +use std::fmt; use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::Rc; use std::sync::{ @@ -59,6 +60,23 @@ pub struct AtomicDrmDevice { logger: ::slog::Logger, } +impl fmt::Debug for AtomicDrmDevice { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut debug = f.debug_struct("AtomicDrmDevice"); + + debug + .field("dev", &self.dev) + .field("dev_id", &self.dev_id) + .field("active", &self.active) + .field("backends", &self.backends); + + #[cfg(feature = "backend_session")] + debug.field("links", &self.links); + + debug.field("logger", &self.logger).finish() + } +} + type OldState = ( Vec<(connector::Handle, PropertyValueSet)>, Vec<(crtc::Handle, PropertyValueSet)>, @@ -82,6 +100,18 @@ pub(in crate::backend::drm) struct Dev { logger: ::slog::Logger, } +impl fmt::Debug for Dev { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Dev") + .field("privileged", &self.privileged) + .field("active", &self.active) + .field("old_state", &self.old_state) + .field("prop_mapping", &self.prop_mapping) + .field("logger", &self.logger) + .finish() + } +} + impl AsRawFd for Dev { fn as_raw_fd(&self) -> RawFd { self.fd.as_raw_fd() diff --git a/src/backend/drm/atomic/session.rs b/src/backend/drm/atomic/session.rs index 5b7cfbc..d58e9ba 100644 --- a/src/backend/drm/atomic/session.rs +++ b/src/backend/drm/atomic/session.rs @@ -25,6 +25,7 @@ use crate::{ /// [`SessionObserver`](SessionObserver) /// linked to the [`AtomicDrmDevice`](AtomicDrmDevice) /// it was created from. +#[derive(Debug)] pub struct AtomicDrmDeviceObserver { dev: WeakArc>, dev_id: dev_t, diff --git a/src/backend/drm/atomic/surface.rs b/src/backend/drm/atomic/surface.rs index 96c08ef..475aec6 100644 --- a/src/backend/drm/atomic/surface.rs +++ b/src/backend/drm/atomic/surface.rs @@ -7,6 +7,7 @@ use drm::control::{ use drm::Device as BasicDevice; use std::collections::HashSet; +use std::fmt; use std::os::unix::io::{AsRawFd, RawFd}; use std::sync::{atomic::Ordering, Arc, Mutex, RwLock}; @@ -47,6 +48,20 @@ pub(in crate::backend::drm) struct AtomicDrmSurfaceInternal>, } +impl fmt::Debug for AtomicDrmSurfaceInternal { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("AtomicDrmSurfaceInternal") + .field("crtc", &self.crtc) + .field("cursor", &self.cursor) + .field("planse", &self.planes) + .field("state", &self.state) + .field("pending", &self.pending) + .field("logger", &self.logger) + .field("test_buffer", &self.test_buffer) + .finish() + } +} + impl AsRawFd for AtomicDrmSurfaceInternal { fn as_raw_fd(&self) -> RawFd { self.dev.as_raw_fd() @@ -1003,6 +1018,7 @@ impl AtomicDrmSurfaceInternal { } /// Open raw crtc utilizing atomic mode-setting +#[derive(Debug)] pub struct AtomicDrmSurface( pub(in crate::backend::drm) Arc>, ); diff --git a/src/backend/drm/common/fallback.rs b/src/backend/drm/common/fallback.rs index c9d9f39..d86aed8 100644 --- a/src/backend/drm/common/fallback.rs +++ b/src/backend/drm/common/fallback.rs @@ -36,6 +36,7 @@ use drm::{ use nix::libc::c_void; use nix::libc::dev_t; use std::env; +use std::fmt; use std::os::unix::io::{AsRawFd, RawFd}; #[cfg(feature = "use_system_lib")] use wayland_server::Display; @@ -49,6 +50,21 @@ pub enum FallbackDevice { Fallback(D2), } +impl fmt::Debug for FallbackDevice { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + FallbackDevice::Preference(d) => f + .debug_struct("FallbackDevice::Preference") + .field("device_id", &d.device_id()) + .finish(), + FallbackDevice::Fallback(d) => f + .debug_struct("FallbackDevice::Preference") + .field("device_id", &d.device_id()) + .finish(), + } + } +} + struct FallbackDeviceHandlerD1( Box> + 'static>, ) @@ -136,6 +152,21 @@ pub enum FallbackSurface { Fallback(S2), } +impl fmt::Debug for FallbackSurface { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + FallbackSurface::Preference(s) => f + .debug_struct("FallbackDevice::Preference") + .field("crtc", &s.crtc()) + .finish(), + FallbackSurface::Fallback(s) => f + .debug_struct("FallbackDevice::Preference") + .field("crtc", &s.crtc()) + .finish(), + } + } +} + /// Enum uniting two kinds of possible errors. #[derive(Debug, thiserror::Error)] pub enum EitherError { diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index dac507f..c45f04c 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -15,6 +15,7 @@ use drm::SystemError as DrmError; use nix::libc::dev_t; use std::cell::RefCell; use std::collections::HashMap; +use std::fmt; use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::Rc; use std::sync::{Arc, Weak as WeakArc}; @@ -69,6 +70,28 @@ where links: Vec, } +impl fmt::Debug for EglDevice +where + B: Backend::Surface, Error = <::Surface as Surface>::Error> + + 'static, + D: Device + NativeDisplay + 'static, + ::Surface: NativeSurface::Surface as Surface>::Error>, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut debug = f.debug_struct("EglDevice"); + + debug + .field("logger", &self.logger) + .field("default_attributes", &self.default_attributes) + .field("default_requirements", &self.default_requirements); + + #[cfg(feature = "backend_session")] + debug.field("links", &self.links); + + debug.finish() + } +} + impl AsRawFd for EglDevice where B: Backend::Surface, Error = <::Surface as Surface>::Error> diff --git a/src/backend/drm/egl/session.rs b/src/backend/drm/egl/session.rs index f8ab7ab..2465beb 100644 --- a/src/backend/drm/egl/session.rs +++ b/src/backend/drm/egl/session.rs @@ -23,6 +23,7 @@ use crate::{ /// [`SessionObserver`](SessionObserver) /// linked to the [`EglDevice`](EglDevice) it was /// created from. +#[derive(Debug)] pub struct EglDeviceObserver { backends: Weak>>>>, } diff --git a/src/backend/drm/egl/surface.rs b/src/backend/drm/egl/surface.rs index 2b852fb..4967300 100644 --- a/src/backend/drm/egl/surface.rs +++ b/src/backend/drm/egl/surface.rs @@ -14,8 +14,10 @@ use crate::backend::graphics::PixelFormat; use crate::backend::graphics::{CursorBackend, SwapBuffersError}; /// Egl surface for rendering +#[derive(Debug)] pub struct EglSurface(pub(super) Arc>); +#[derive(Debug)] pub(super) struct EglSurfaceInternal where N: native::NativeSurface + Surface, diff --git a/src/backend/drm/eglstream/egl.rs b/src/backend/drm/eglstream/egl.rs index 861e5e1..5e836a0 100644 --- a/src/backend/drm/eglstream/egl.rs +++ b/src/backend/drm/eglstream/egl.rs @@ -31,6 +31,7 @@ use std::sync::Arc; /// Egl Device backend type /// /// See [`Backend`](::backend::egl::native::Backend). +#[derive(Debug)] pub struct EglStreamDeviceBackend { _userdata: PhantomData, } diff --git a/src/backend/drm/eglstream/mod.rs b/src/backend/drm/eglstream/mod.rs index 69f759b..aef74a3 100644 --- a/src/backend/drm/eglstream/mod.rs +++ b/src/backend/drm/eglstream/mod.rs @@ -28,6 +28,7 @@ use nix::libc::dev_t; use std::cell::RefCell; use std::collections::HashMap; use std::ffi::CStr; +use std::fmt; use std::os::unix::fs::MetadataExt; use std::os::unix::io::{AsRawFd, RawFd}; use std::rc::{Rc, Weak}; @@ -90,6 +91,16 @@ pub struct EglStreamDevice { links: Vec, } +impl fmt::Debug for EglStreamDevice { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut debug = f.debug_struct("EglStreamDevice"); + debug.field("dev", &self.dev).field("logger", &self.logger); + #[cfg(feature = "backend_session")] + debug.field("links", &self.links); + debug.finish() + } +} + impl EglStreamDevice { /// Try to create a new [`EglStreamDevice`] from an open device. /// diff --git a/src/backend/drm/eglstream/session.rs b/src/backend/drm/eglstream/session.rs index a85cc5c..ca845cc 100644 --- a/src/backend/drm/eglstream/session.rs +++ b/src/backend/drm/eglstream/session.rs @@ -19,6 +19,7 @@ use drm::control::{crtc, Device as ControlDevice}; /// [`SessionObserver`](SessionObserver) /// linked to the [`EglStreamDevice`](EglStreamDevice) it was /// created from. +#[derive(Debug)] pub struct EglStreamDeviceObserver { backends: Weak>>>>, logger: ::slog::Logger, diff --git a/src/backend/drm/eglstream/surface.rs b/src/backend/drm/eglstream/surface.rs index 0d26d88..a7d86ea 100644 --- a/src/backend/drm/eglstream/surface.rs +++ b/src/backend/drm/eglstream/surface.rs @@ -30,10 +30,12 @@ use crate::backend::graphics::CursorBackend; // We do not want to mark the whole surface as `Send` in case we screw up somewhere else // and because S needs to be `Send` as well for this to work. +#[derive(Debug)] pub(super) struct StreamHandle(pub(super) EGLStreamKHR); // EGLStreamKHR can be moved between threads unsafe impl Send for StreamHandle {} +#[derive(Debug)] pub(in crate::backend::drm) struct EglStreamSurfaceInternal { pub(in crate::backend::drm) crtc: S, pub(in crate::backend::drm) cursor: Mutex>, @@ -205,6 +207,7 @@ impl CursorBackend for EglStreamSurfaceInternal { } /// egl stream surface for rendering +#[derive(Debug)] pub struct EglStreamSurface( pub(in crate::backend::drm) Arc>, ); diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 9b16651..f62e14a 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -10,6 +10,7 @@ use std::ptr; use std::sync::{atomic::Ordering, Arc}; /// EGL context for rendering +#[derive(Debug)] pub struct EGLContext { context: ffi::egl::types::EGLContext, display: Arc, diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 0e960cd..6012a3b 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -24,10 +24,12 @@ use std::ffi::CStr; use std::marker::PhantomData; use std::mem::MaybeUninit; +use std::fmt; use std::ops::Deref; /// Wrapper around [`ffi::EGLDisplay`](ffi::egl::types::EGLDisplay) to ensure display is only destroyed /// once all resources bound to it have been dropped. +#[derive(Debug)] pub struct EGLDisplayHandle { /// ffi EGLDisplay ptr pub handle: ffi::egl::types::EGLDisplay, @@ -54,6 +56,7 @@ impl Drop for EGLDisplayHandle { } /// [`EGLDisplay`] represents an initialised EGL environment +#[derive(Debug)] pub struct EGLDisplay> { native: RefCell, pub(crate) display: Arc, @@ -454,6 +457,16 @@ pub struct EGLBufferReader { gl: gl_ffi::Gles2, } +#[cfg(feature = "use_system_lib")] +impl fmt::Debug for EGLBufferReader { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EGLBufferReader") + .field("display", &self.display) + .field("wayland", &self.wayland) + .finish() + } +} + #[cfg(feature = "use_system_lib")] impl EGLBufferReader { fn new(display: Arc, wayland: *mut wl_display) -> Self { diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 047bd64..f03c311 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -269,6 +269,20 @@ pub struct EGLImages { gl: gl_ffi::Gles2, } +#[cfg(feature = "wayland_frontend")] +impl fmt::Debug for EGLImages { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Point") + .field("display", &self.display) + .field("width", &self.width) + .field("height", &self.height) + .field("y_inverted", &self.y_inverted) + .field("format", &self.format) + .field("images", &self.images) + .finish() + } +} + #[cfg(feature = "wayland_frontend")] impl EGLImages { /// Amount of planes of these `EGLImages` diff --git a/src/backend/egl/native.rs b/src/backend/egl/native.rs index 8ffce1d..1864f78 100644 --- a/src/backend/egl/native.rs +++ b/src/backend/egl/native.rs @@ -35,6 +35,7 @@ pub trait Backend { } #[cfg(feature = "backend_winit")] +#[derive(Debug)] /// Wayland backend type pub enum Wayland {} #[cfg(feature = "backend_winit")] @@ -79,10 +80,12 @@ impl Backend for Wayland { } #[cfg(feature = "backend_winit")] +#[derive(Debug)] /// Typed Xlib window for the `X11` backend pub struct XlibWindow(u64); #[cfg(feature = "backend_winit")] /// X11 backend type +#[derive(Debug)] pub enum X11 {} #[cfg(feature = "backend_winit")] impl Backend for X11 { diff --git a/src/backend/egl/surface.rs b/src/backend/egl/surface.rs index 463f95d..3f4f1f0 100644 --- a/src/backend/egl/surface.rs +++ b/src/backend/egl/surface.rs @@ -11,6 +11,7 @@ use std::sync::{ }; /// EGL surface of a given EGL context for rendering +#[derive(Debug)] pub struct EGLSurface { pub(crate) display: Arc, native: N, diff --git a/src/backend/graphics/gl.rs b/src/backend/graphics/gl.rs index 8aa1fc0..58a4991 100644 --- a/src/backend/graphics/gl.rs +++ b/src/backend/graphics/gl.rs @@ -1,6 +1,7 @@ //! OpenGL rendering types use nix::libc::c_void; +use std::fmt; use super::{PixelFormat, SwapBuffersError}; @@ -39,6 +40,15 @@ pub trait GLGraphicsBackend { /// Returns the pixel format of the main framebuffer of the context. fn get_pixel_format(&self) -> PixelFormat; + + /// Formats the debug value using the given formatter. + fn debug_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("GLGraphicsBackend") + .field("framebuffer_dimensions", &self.get_framebuffer_dimensions()) + .field("is_current", &self.is_current()) + .field("pixel_format", &self.get_pixel_format()) + .finish() + } } /// Loads a Raw GLES Interface for a given [`GLGraphicsBackend`] diff --git a/src/backend/graphics/glium.rs b/src/backend/graphics/glium.rs index 4e04f93..d1f7979 100644 --- a/src/backend/graphics/glium.rs +++ b/src/backend/graphics/glium.rs @@ -8,6 +8,7 @@ use glium::{ }; use std::{ cell::{Cell, Ref, RefCell, RefMut}, + fmt, os::raw::c_void, rc::Rc, }; @@ -22,6 +23,16 @@ pub struct GliumGraphicsBackend { error_channel: Rc>>>, } +impl fmt::Debug for GliumGraphicsBackend { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let backend = &self.backend.0.borrow().debug_fmt(f); + + f.debug_struct("GliumGraphicsBackend") + .field("backend", backend) + .finish() + } +} + struct InternalBackend(RefCell, Rc>>>); impl GliumGraphicsBackend { diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index f14364f..cac97c2 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -16,6 +16,7 @@ use input::event; use std::path::Path; use std::{ collections::hash_map::HashMap, + fmt, io::Error as IoError, os::unix::io::{AsRawFd, RawFd}, }; @@ -32,6 +33,7 @@ const INPUT_MAJOR: u32 = 13; /// /// Tracks input of all devices given manually or via a udev seat to a provided libinput /// context. +#[derive(Debug)] pub struct LibinputInputBackend { context: libinput::Libinput, config: LibinputConfig, @@ -273,6 +275,7 @@ impl backend::Event for event::touch::TouchFrameEvent { impl backend::TouchFrameEvent for event::touch::TouchFrameEvent {} /// Special events generated by Libinput +#[derive(Debug)] pub enum LibinputEvent { /// A new device was plugged in NewDevice(libinput::Device), @@ -284,6 +287,7 @@ pub enum LibinputEvent { /// /// This type allows you to access the list of know devices to configure them /// if relevant +#[derive(Debug)] pub struct LibinputConfig { devices: Vec, } @@ -423,6 +427,19 @@ impl From for backend::MouseButtonState { #[cfg(feature = "backend_session")] pub struct LibinputSessionInterface(S); +#[cfg(feature = "backend_session")] +impl fmt::Debug for LibinputSessionInterface { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let sesion = &f + .debug_struct("Session") + .field("is_active", &self.0.is_active()) + .field("seat", &self.0.seat()) + .finish(); + + f.debug_tuple("LibinputSessionInterface").field(sesion).finish() + } +} + #[cfg(feature = "backend_session")] impl From for LibinputSessionInterface { fn from(session: S) -> LibinputSessionInterface { diff --git a/src/backend/session/auto.rs b/src/backend/session/auto.rs index 289e83b..94ff4ae 100644 --- a/src/backend/session/auto.rs +++ b/src/backend/session/auto.rs @@ -44,7 +44,7 @@ use std::{cell::RefCell, io, os::unix::io::RawFd, path::Path, rc::Rc}; use calloop::{EventSource, Poll, Readiness, Token}; /// [`Session`] using the best available interface -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum AutoSession { /// Logind session #[cfg(feature = "backend_session_logind")] @@ -54,6 +54,7 @@ pub enum AutoSession { } /// [`SessionNotifier`] using the best available interface +#[derive(Debug)] pub enum AutoSessionNotifier { /// Logind session notifier #[cfg(feature = "backend_session_logind")] diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index 44ff53d..6294e19 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -49,6 +49,7 @@ use nix::{ }; use std::{ cell::RefCell, + fmt, io::Error as IoError, os::unix::io::RawFd, path::Path, @@ -70,15 +71,29 @@ struct LogindSessionImpl { logger: ::slog::Logger, } +impl fmt::Debug for LogindSessionImpl { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("LogindSessionImpl ") + .field("session_id", &self.session_id) + .field("conn", &"..") + .field("session_path", &self.session_path) + .field("active", &self.active) + .field("signaler", &self.signaler) + .field("seat", &self.seat) + .field("logger", &self.logger) + .finish() + } +} + /// [`Session`] via the logind dbus interface -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct LogindSession { internal: Weak, seat: String, } /// [`SessionNotifier`] via the logind dbus interface -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct LogindSessionNotifier { internal: Rc, } diff --git a/src/backend/session/direct.rs b/src/backend/session/direct.rs index 3eaae76..f84d5c8 100644 --- a/src/backend/session/direct.rs +++ b/src/backend/session/direct.rs @@ -57,6 +57,7 @@ use nix::{ Error as NixError, Result as NixResult, }; use std::{ + fmt, os::unix::io::RawFd, path::Path, sync::{ @@ -142,6 +143,7 @@ fn is_tty_device(dev: dev_t, path: Option<&Path>) -> bool { } /// [`Session`] via the virtual terminal direct kernel interface +#[derive(Debug)] pub struct DirectSession { tty: RawFd, active: Arc, @@ -160,6 +162,25 @@ pub struct DirectSessionNotifier { source: Option, } +impl fmt::Debug for DirectSessionNotifier { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Point") + .field("tty", &self.tty) + .field("active", &self.active) + .field("signaler", &self.signaler) + .field("signal", &self.signal) + .field("logger", &self.logger) + .field( + "source", + &match self.source { + Some(_) => "Some(..)", + None => "None", + }, + ) + .finish() + } +} + impl DirectSession { /// Tries to create a new session via the legacy virtual terminal interface. /// From aa2a0523bf1644d8369fe91de4c6c336c80e2ab8 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 10 Feb 2021 03:46:03 +0100 Subject: [PATCH 4/9] [Debug Trait] utils --- src/utils/signaling.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/signaling.rs b/src/utils/signaling.rs index c88d921..28c925b 100644 --- a/src/utils/signaling.rs +++ b/src/utils/signaling.rs @@ -1,5 +1,6 @@ use std::{rc::Rc, cell::RefCell}; +#[derive(Debug)] struct SignalerInner { closures: RefCell>> } @@ -12,6 +13,7 @@ impl SignalerInner { } } +#[derive(Debug)] pub struct Signaler { inner: Rc> } From e9eb698dd02e16a8087d9f9f9b74733af1584b4b Mon Sep 17 00:00:00 2001 From: Poly Date: Fri, 12 Feb 2021 22:13:38 +0100 Subject: [PATCH 5/9] [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 From de3dfacee07b80f97161b1abf78ea7fb382a01e8 Mon Sep 17 00:00:00 2001 From: Poly Date: Sat, 13 Feb 2021 00:04:45 +0100 Subject: [PATCH 6/9] [Debug Trait] General cleanup and small fixes --- src/backend/drm/atomic/mod.rs | 8 +++++--- src/backend/drm/atomic/surface.rs | 3 ++- src/backend/drm/egl/mod.rs | 7 +++++-- src/backend/drm/eglstream/mod.rs | 9 +++++++-- src/backend/graphics/gl.rs | 10 ---------- src/backend/graphics/glium.rs | 16 ++++++++++++++-- src/backend/libinput/mod.rs | 18 ++++++++++++------ src/backend/session/dbus/logind.rs | 2 +- src/backend/winit.rs | 19 ++++++++++++++++--- 9 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/backend/drm/atomic/mod.rs b/src/backend/drm/atomic/mod.rs index 856c017..dcaf7d4 100644 --- a/src/backend/drm/atomic/mod.rs +++ b/src/backend/drm/atomic/mod.rs @@ -60,7 +60,7 @@ pub struct AtomicDrmDevice { logger: ::slog::Logger, } -impl fmt::Debug for AtomicDrmDevice { +impl fmt::Debug for AtomicDrmDevice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("AtomicDrmDevice"); @@ -68,7 +68,8 @@ impl fmt::Debug for AtomicDrmDevice { .field("dev", &self.dev) .field("dev_id", &self.dev_id) .field("active", &self.active) - .field("backends", &self.backends); + .field("backends", &self.backends) + .field("handler", &"..."); #[cfg(feature = "backend_session")] debug.field("links", &self.links); @@ -100,9 +101,10 @@ pub(in crate::backend::drm) struct Dev { logger: ::slog::Logger, } -impl fmt::Debug for Dev { +impl fmt::Debug for Dev { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Dev") + .field("fd", &self.fd) .field("privileged", &self.privileged) .field("active", &self.active) .field("old_state", &self.old_state) diff --git a/src/backend/drm/atomic/surface.rs b/src/backend/drm/atomic/surface.rs index 475aec6..fc05cee 100644 --- a/src/backend/drm/atomic/surface.rs +++ b/src/backend/drm/atomic/surface.rs @@ -48,9 +48,10 @@ pub(in crate::backend::drm) struct AtomicDrmSurfaceInternal>, } -impl fmt::Debug for AtomicDrmSurfaceInternal { +impl fmt::Debug for AtomicDrmSurfaceInternal { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("AtomicDrmSurfaceInternal") + .field("dev", &self.dev) .field("crtc", &self.crtc) .field("cursor", &self.cursor) .field("planse", &self.planes) diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index c45f04c..0261058 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -73,17 +73,20 @@ where impl fmt::Debug for EglDevice where B: Backend::Surface, Error = <::Surface as Surface>::Error> + + fmt::Debug + 'static, - D: Device + NativeDisplay + 'static, + D: Device + NativeDisplay + fmt::Debug + 'static, ::Surface: NativeSurface::Surface as Surface>::Error>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("EglDevice"); debug + .field("dev", &self.dev) .field("logger", &self.logger) .field("default_attributes", &self.default_attributes) - .field("default_requirements", &self.default_requirements); + .field("default_requirements", &self.default_requirements) + .field("backends", &"..."); #[cfg(feature = "backend_session")] debug.field("links", &self.links); diff --git a/src/backend/drm/eglstream/mod.rs b/src/backend/drm/eglstream/mod.rs index aef74a3..c579c2c 100644 --- a/src/backend/drm/eglstream/mod.rs +++ b/src/backend/drm/eglstream/mod.rs @@ -91,10 +91,15 @@ pub struct EglStreamDevice { links: Vec, } -impl fmt::Debug for EglStreamDevice { +impl fmt::Debug for EglStreamDevice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("EglStreamDevice"); - debug.field("dev", &self.dev).field("logger", &self.logger); + debug + .field("dev", &self.dev) + .field("raw", &self.raw) + .field("backends", &"...") + .field("logger", &self.logger); + #[cfg(feature = "backend_session")] debug.field("links", &self.links); debug.finish() diff --git a/src/backend/graphics/gl.rs b/src/backend/graphics/gl.rs index 58a4991..8aa1fc0 100644 --- a/src/backend/graphics/gl.rs +++ b/src/backend/graphics/gl.rs @@ -1,7 +1,6 @@ //! OpenGL rendering types use nix::libc::c_void; -use std::fmt; use super::{PixelFormat, SwapBuffersError}; @@ -40,15 +39,6 @@ pub trait GLGraphicsBackend { /// Returns the pixel format of the main framebuffer of the context. fn get_pixel_format(&self) -> PixelFormat; - - /// Formats the debug value using the given formatter. - fn debug_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("GLGraphicsBackend") - .field("framebuffer_dimensions", &self.get_framebuffer_dimensions()) - .field("is_current", &self.is_current()) - .field("pixel_format", &self.get_pixel_format()) - .finish() - } } /// Loads a Raw GLES Interface for a given [`GLGraphicsBackend`] diff --git a/src/backend/graphics/glium.rs b/src/backend/graphics/glium.rs index d1f7979..8168ab5 100644 --- a/src/backend/graphics/glium.rs +++ b/src/backend/graphics/glium.rs @@ -25,10 +25,22 @@ pub struct GliumGraphicsBackend { impl fmt::Debug for GliumGraphicsBackend { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let backend = &self.backend.0.borrow().debug_fmt(f); + struct BackendDebug<'a, T: GLGraphicsBackend>(&'a Rc>); + impl<'a, T: GLGraphicsBackend> fmt::Debug for BackendDebug<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let b = &self.0 .0.borrow(); + f.debug_struct("GLGraphicsBackend") + .field("framebuffer_dimensions", &b.get_framebuffer_dimensions()) + .field("is_current", &b.is_current()) + .field("pixel_format", &b.get_pixel_format()) + .finish() + } + } f.debug_struct("GliumGraphicsBackend") - .field("backend", backend) + .field("context", &"...") + .field("backend", &BackendDebug(&self.backend)) + .field("error_channel", &"...") .finish() } } diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index cac97c2..1c16236 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -430,13 +430,19 @@ pub struct LibinputSessionInterface(S); #[cfg(feature = "backend_session")] impl fmt::Debug for LibinputSessionInterface { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let sesion = &f - .debug_struct("Session") - .field("is_active", &self.0.is_active()) - .field("seat", &self.0.seat()) - .finish(); + struct SessionDebug<'a, S: Session>(&'a S); + impl<'a, S: Session> fmt::Debug for SessionDebug<'a, S> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Session") + .field("is_active", &self.0.is_active()) + .field("seat", &self.0.seat()) + .finish() + } + } - f.debug_tuple("LibinputSessionInterface").field(sesion).finish() + f.debug_tuple("LibinputSessionInterface") + .field(&SessionDebug(&self.0)) + .finish() } } diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index 6294e19..c51a49c 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -75,7 +75,7 @@ impl fmt::Debug for LogindSessionImpl { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("LogindSessionImpl ") .field("session_id", &self.session_id) - .field("conn", &"..") + .field("conn", &"...") .field("session_path", &self.session_path) .field("active", &self.active) .field("signaler", &self.signaler) diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 995c6fd..5a501ea 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -69,10 +69,23 @@ enum Window { impl fmt::Debug for Window { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Window::Wayland { .. } => f.debug_tuple("Window::Wayland"), - Window::X11 { .. } => f.debug_tuple("Window::X11"), + Window::Wayland { display, context, .. } => f + .debug_struct("Window::Wayland") + .field("display", &display) + .field("context", &context) + .field("surface", &"...") + .finish(), + Window::X11 { + display, + context, + surface, + } => f + .debug_struct("Window::X11") + .field("display", &display) + .field("context", &context) + .field("surface", &surface) + .finish(), } - .finish() } } From 6d76d1c1a27f2f28785acf2a9bb9b7f3201daa12 Mon Sep 17 00:00:00 2001 From: Poly Date: Mon, 22 Feb 2021 21:05:00 +0100 Subject: [PATCH 7/9] [Debug Trait] Comments and Cleanup . --- src/backend/drm/atomic/mod.rs | 15 ++------------- src/backend/drm/atomic/surface.rs | 17 +---------------- src/backend/drm/common/fallback.rs | 2 ++ src/backend/drm/egl/mod.rs | 1 + src/backend/drm/eglstream/mod.rs | 1 + src/backend/egl/display.rs | 1 + src/backend/egl/mod.rs | 1 + src/backend/graphics/glium.rs | 1 + src/backend/libinput/mod.rs | 1 + src/backend/session/dbus/logind.rs | 1 + src/backend/udev.rs | 1 + src/backend/winit.rs | 1 + src/signaling.rs | 1 + src/wayland/compositor/mod.rs | 1 + src/wayland/seat/keyboard.rs | 1 + src/wayland/seat/mod.rs | 1 + src/wayland/seat/pointer.rs | 2 ++ 17 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/backend/drm/atomic/mod.rs b/src/backend/drm/atomic/mod.rs index dcaf7d4..38e2e71 100644 --- a/src/backend/drm/atomic/mod.rs +++ b/src/backend/drm/atomic/mod.rs @@ -60,6 +60,7 @@ pub struct AtomicDrmDevice { logger: ::slog::Logger, } +// DeviceHandler does not implement Debug, so we have to impl Debug manually impl fmt::Debug for AtomicDrmDevice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("AtomicDrmDevice"); @@ -92,6 +93,7 @@ type Mapping = ( HashMap>, ); +#[derive(Debug)] pub(in crate::backend::drm) struct Dev { fd: A, privileged: bool, @@ -101,19 +103,6 @@ pub(in crate::backend::drm) struct Dev { logger: ::slog::Logger, } -impl fmt::Debug for Dev { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Dev") - .field("fd", &self.fd) - .field("privileged", &self.privileged) - .field("active", &self.active) - .field("old_state", &self.old_state) - .field("prop_mapping", &self.prop_mapping) - .field("logger", &self.logger) - .finish() - } -} - impl AsRawFd for Dev { fn as_raw_fd(&self) -> RawFd { self.fd.as_raw_fd() diff --git a/src/backend/drm/atomic/surface.rs b/src/backend/drm/atomic/surface.rs index fc05cee..9946858 100644 --- a/src/backend/drm/atomic/surface.rs +++ b/src/backend/drm/atomic/surface.rs @@ -7,7 +7,6 @@ use drm::control::{ use drm::Device as BasicDevice; use std::collections::HashSet; -use std::fmt; use std::os::unix::io::{AsRawFd, RawFd}; use std::sync::{atomic::Ordering, Arc, Mutex, RwLock}; @@ -37,6 +36,7 @@ pub struct Planes { pub cursor: plane::Handle, } +#[derive(Debug)] pub(in crate::backend::drm) struct AtomicDrmSurfaceInternal { pub(super) dev: Arc>, pub(in crate::backend::drm) crtc: crtc::Handle, @@ -48,21 +48,6 @@ pub(in crate::backend::drm) struct AtomicDrmSurfaceInternal>, } -impl fmt::Debug for AtomicDrmSurfaceInternal { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("AtomicDrmSurfaceInternal") - .field("dev", &self.dev) - .field("crtc", &self.crtc) - .field("cursor", &self.cursor) - .field("planse", &self.planes) - .field("state", &self.state) - .field("pending", &self.pending) - .field("logger", &self.logger) - .field("test_buffer", &self.test_buffer) - .finish() - } -} - impl AsRawFd for AtomicDrmSurfaceInternal { fn as_raw_fd(&self) -> RawFd { self.dev.as_raw_fd() diff --git a/src/backend/drm/common/fallback.rs b/src/backend/drm/common/fallback.rs index d86aed8..306b7b6 100644 --- a/src/backend/drm/common/fallback.rs +++ b/src/backend/drm/common/fallback.rs @@ -50,6 +50,7 @@ pub enum FallbackDevice { Fallback(D2), } +// Device is a trait, so we have to impl Debug manually impl fmt::Debug for FallbackDevice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -152,6 +153,7 @@ pub enum FallbackSurface { Fallback(S2), } +// Surface is a trait, so we have to impl Debug manually impl fmt::Debug for FallbackSurface { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index 0261058..36633ac 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -70,6 +70,7 @@ where links: Vec, } +// BackendRef does not implement debug, so we have to impl Debug manually impl fmt::Debug for EglDevice where B: Backend::Surface, Error = <::Surface as Surface>::Error> diff --git a/src/backend/drm/eglstream/mod.rs b/src/backend/drm/eglstream/mod.rs index c579c2c..869127d 100644 --- a/src/backend/drm/eglstream/mod.rs +++ b/src/backend/drm/eglstream/mod.rs @@ -91,6 +91,7 @@ pub struct EglStreamDevice { links: Vec, } +// SurfaceInternalRef does not implement debug, so we have to impl Debug manually impl fmt::Debug for EglStreamDevice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("EglStreamDevice"); diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 6012a3b..fc26adf 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -457,6 +457,7 @@ pub struct EGLBufferReader { gl: gl_ffi::Gles2, } +// Gles2 does not implement debug, so we have to impl Debug manually #[cfg(feature = "use_system_lib")] impl fmt::Debug for EGLBufferReader { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index f03c311..a6d1ea3 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -269,6 +269,7 @@ pub struct EGLImages { gl: gl_ffi::Gles2, } +// Gles2 does not implement debug, so we have to impl Debug manually #[cfg(feature = "wayland_frontend")] impl fmt::Debug for EGLImages { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/backend/graphics/glium.rs b/src/backend/graphics/glium.rs index 8168ab5..96f2226 100644 --- a/src/backend/graphics/glium.rs +++ b/src/backend/graphics/glium.rs @@ -23,6 +23,7 @@ pub struct GliumGraphicsBackend { error_channel: Rc>>>, } +// GLGraphicsBackend is a trait, so we have to impl Debug manually impl fmt::Debug for GliumGraphicsBackend { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { struct BackendDebug<'a, T: GLGraphicsBackend>(&'a Rc>); diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index 1c16236..cf3d31d 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -427,6 +427,7 @@ impl From for backend::MouseButtonState { #[cfg(feature = "backend_session")] pub struct LibinputSessionInterface(S); +// Session is a trait, so we have to impl Debug manually #[cfg(feature = "backend_session")] impl fmt::Debug for LibinputSessionInterface { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index c51a49c..f55fd07 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -71,6 +71,7 @@ struct LogindSessionImpl { logger: ::slog::Logger, } +// DBusConnection does not implement debug, so we have to impl Debug manually impl fmt::Debug for LogindSessionImpl { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("LogindSessionImpl ") diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 45fe192..2b6cab0 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -63,6 +63,7 @@ pub struct UdevBackend { logger: ::slog::Logger, } +// MonitorSocket does not implement debug, so we have to impl Debug manually impl fmt::Debug for UdevBackend { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use udev::AsRaw; diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 5a501ea..48e5d1c 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -66,6 +66,7 @@ enum Window { }, } +// WlEglSurface does not implement debug, so we have to impl Debug manually impl fmt::Debug for Window { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/src/signaling.rs b/src/signaling.rs index 9a6743d..2e41121 100644 --- a/src/signaling.rs +++ b/src/signaling.rs @@ -111,6 +111,7 @@ struct SignalInner { pending_events: RefCell>, } +// WeakCallback does not implement debug, so we have to impl Debug manually impl fmt::Debug for SignalInner { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SignalInner") diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 40b5e1b..a1d419c 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -172,6 +172,7 @@ pub struct SurfaceAttributes { pub user_data: UserDataMap, } +// UserDataMap does not implement debug, so we have to impl Debug manually impl fmt::Debug for SurfaceAttributes { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SurfaceAttributes") diff --git a/src/wayland/seat/keyboard.rs b/src/wayland/seat/keyboard.rs index 7244f92..8ad7c5f 100644 --- a/src/wayland/seat/keyboard.rs +++ b/src/wayland/seat/keyboard.rs @@ -120,6 +120,7 @@ struct KbdInternal { focus_hook: Box)>, } +// focus_hook does not implement debug, so we have to impl Debug manually impl fmt::Debug for KbdInternal { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("KbdInternal") diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index 385dca8..9c2c982 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -74,6 +74,7 @@ pub(crate) struct SeatRc { name: String, } +// UserDataMap does not implement debug, so we have to impl Debug manually impl fmt::Debug for SeatRc { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SeatRc") diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 0933ded..d09837f 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -35,6 +35,7 @@ enum GrabStatus { Borrowed, } +// PointerGrab is a trait, so we have to impl Debug manually impl fmt::Debug for GrabStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -55,6 +56,7 @@ struct PointerInternal { image_callback: Box, } +// image_callback does not implement debug, so we have to impl Debug manually impl fmt::Debug for PointerInternal { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Point") From 804a6cb59fcb200a3980b67e14671665921283ab Mon Sep 17 00:00:00 2001 From: Poly Date: Tue, 23 Feb 2021 20:20:12 +0100 Subject: [PATCH 8/9] [Debug Trait] Add missing comment --- src/backend/session/direct.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/session/direct.rs b/src/backend/session/direct.rs index f84d5c8..0c2a080 100644 --- a/src/backend/session/direct.rs +++ b/src/backend/session/direct.rs @@ -170,6 +170,7 @@ impl fmt::Debug for DirectSessionNotifier { .field("signaler", &self.signaler) .field("signal", &self.signal) .field("logger", &self.logger) + // Signal deos not implement Debug` .field( "source", &match self.source { From d2373fdddde14b3db07f3bf0cddbd15c6122c572 Mon Sep 17 00:00:00 2001 From: Poly Date: Tue, 23 Feb 2021 20:21:20 +0100 Subject: [PATCH 9/9] [Debug Trait] Remove unnecessary manual imps --- src/backend/drm/common/fallback.rs | 34 ++---------------------------- src/backend/libinput/mod.rs | 21 +----------------- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/src/backend/drm/common/fallback.rs b/src/backend/drm/common/fallback.rs index 306b7b6..b853001 100644 --- a/src/backend/drm/common/fallback.rs +++ b/src/backend/drm/common/fallback.rs @@ -43,6 +43,7 @@ use wayland_server::Display; /// [`Device`](::backend::drm::Device) Wrapper to assist fallback /// in case initialization of the preferred device type fails. +#[derive(Debug)] pub enum FallbackDevice { /// Variant for successful initialization of the preferred device Preference(D1), @@ -50,22 +51,6 @@ pub enum FallbackDevice { Fallback(D2), } -// Device is a trait, so we have to impl Debug manually -impl fmt::Debug for FallbackDevice { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - FallbackDevice::Preference(d) => f - .debug_struct("FallbackDevice::Preference") - .field("device_id", &d.device_id()) - .finish(), - FallbackDevice::Fallback(d) => f - .debug_struct("FallbackDevice::Preference") - .field("device_id", &d.device_id()) - .finish(), - } - } -} - struct FallbackDeviceHandlerD1( Box> + 'static>, ) @@ -146,6 +131,7 @@ where /// [`Surface`](::backend::drm::Surface) Wrapper to assist fallback /// in case initialization of the preferred device type fails. +#[derive(Debug)] pub enum FallbackSurface { /// Variant for successful initialization of the preferred device Preference(S1), @@ -153,22 +139,6 @@ pub enum FallbackSurface { Fallback(S2), } -// Surface is a trait, so we have to impl Debug manually -impl fmt::Debug for FallbackSurface { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - FallbackSurface::Preference(s) => f - .debug_struct("FallbackDevice::Preference") - .field("crtc", &s.crtc()) - .finish(), - FallbackSurface::Fallback(s) => f - .debug_struct("FallbackDevice::Preference") - .field("crtc", &s.crtc()) - .finish(), - } - } -} - /// Enum uniting two kinds of possible errors. #[derive(Debug, thiserror::Error)] pub enum EitherError { diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index cf3d31d..6559b08 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -425,28 +425,9 @@ impl From for backend::MouseButtonState { /// Wrapper for types implementing the [`Session`] trait to provide /// a [`libinput::LibinputInterface`] implementation. #[cfg(feature = "backend_session")] +#[derive(Debug)] pub struct LibinputSessionInterface(S); -// Session is a trait, so we have to impl Debug manually -#[cfg(feature = "backend_session")] -impl fmt::Debug for LibinputSessionInterface { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - struct SessionDebug<'a, S: Session>(&'a S); - impl<'a, S: Session> fmt::Debug for SessionDebug<'a, S> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Session") - .field("is_active", &self.0.is_active()) - .field("seat", &self.0.seat()) - .finish() - } - } - - f.debug_tuple("LibinputSessionInterface") - .field(&SessionDebug(&self.0)) - .finish() - } -} - #[cfg(feature = "backend_session")] impl From for LibinputSessionInterface { fn from(session: S) -> LibinputSessionInterface {