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. ///