From 6b63d11ab3d696107ef31c078476b4fedc8c58b0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 28 Feb 2025 14:39:19 +0100 Subject: [PATCH] Properly implement Debug for Window and EventLoop types For EventLoop, EventLoopBuilder, EventLoopProxy and by requiring it as a supertrait of Window and ActiveEventLoop. It is especially useful for downstream consumers to be able to know that Window is Debug. --- examples/child_window.rs | 3 ++- examples/control_flow.rs | 2 +- examples/dnd.rs | 1 + examples/pump_events.rs | 2 +- examples/run_on_demand.rs | 2 +- examples/window.rs | 2 +- examples/x11_embed.rs | 1 + src/event_loop.rs | 27 ++++--------------- src/platform_impl/android/mod.rs | 18 ++++++++++++- src/platform_impl/apple/appkit/event_loop.rs | 8 ++++++ src/platform_impl/apple/appkit/window.rs | 1 + src/platform_impl/apple/uikit/event_loop.rs | 1 + src/platform_impl/apple/uikit/window.rs | 1 + src/platform_impl/linux/mod.rs | 1 + .../linux/wayland/event_loop/mod.rs | 3 +++ .../linux/wayland/event_loop/proxy.rs | 1 + .../linux/wayland/event_loop/sink.rs | 2 +- .../linux/wayland/seat/pointer/mod.rs | 1 + .../wayland/seat/pointer/relative_pointer.rs | 1 + .../linux/wayland/seat/text_input/mod.rs | 1 + src/platform_impl/linux/wayland/state.rs | 1 + .../linux/wayland/types/xdg_activation.rs | 1 + src/platform_impl/linux/wayland/window/mod.rs | 1 + .../linux/wayland/window/state.rs | 3 ++- src/platform_impl/linux/x11/dnd.rs | 1 + .../linux/x11/event_processor.rs | 1 + src/platform_impl/linux/x11/ime/mod.rs | 7 +++++ src/platform_impl/linux/x11/mod.rs | 7 ++++- src/platform_impl/linux/x11/window.rs | 2 ++ src/platform_impl/orbital/event_loop.rs | 5 +++- src/platform_impl/orbital/mod.rs | 2 ++ src/platform_impl/orbital/window.rs | 1 + src/platform_impl/web/async/wrapper.rs | 2 ++ src/platform_impl/web/event_loop/mod.rs | 1 + src/platform_impl/web/event_loop/proxy.rs | 2 ++ src/platform_impl/web/event_loop/runner.rs | 19 ++++++++++++- .../web/event_loop/window_target.rs | 4 +-- src/platform_impl/web/window.rs | 7 +++++ src/platform_impl/windows/event_loop.rs | 20 +++++++++++++- .../windows/event_loop/runner.rs | 10 ++++++- src/platform_impl/windows/window.rs | 3 ++- src/platform_impl/windows/window_state.rs | 13 ++++++--- src/window.rs | 2 +- 43 files changed, 152 insertions(+), 42 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index 52bbbaaad7..e87207828b 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -13,6 +13,7 @@ fn main() -> Result<(), impl std::error::Error> { #[path = "util/fill.rs"] mod fill; + #[derive(Debug)] struct WindowData { window: Box, color: u32, @@ -24,7 +25,7 @@ fn main() -> Result<(), impl std::error::Error> { } } - #[derive(Default)] + #[derive(Default, Debug)] struct Application { parent_window_id: Option, windows: HashMap, diff --git a/examples/control_flow.rs b/examples/control_flow.rs index 47a518c181..8fb09bb3f0 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -46,7 +46,7 @@ fn main() -> Result<(), impl std::error::Error> { event_loop.run_app(ControlFlowDemo::default()) } -#[derive(Default)] +#[derive(Default, Debug)] struct ControlFlowDemo { mode: Mode, request_redraw: bool, diff --git a/examples/dnd.rs b/examples/dnd.rs index a05e12d57c..51d1ee4501 100644 --- a/examples/dnd.rs +++ b/examples/dnd.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), Box> { } /// Application state and event handling. +#[derive(Debug)] struct Application { window: Option>, } diff --git a/examples/pump_events.rs b/examples/pump_events.rs index 3ec8abe38b..8622fe28a2 100644 --- a/examples/pump_events.rs +++ b/examples/pump_events.rs @@ -16,7 +16,7 @@ fn main() -> std::process::ExitCode { #[path = "util/fill.rs"] mod fill; - #[derive(Default)] + #[derive(Default, Debug)] struct PumpDemo { window: Option>, } diff --git a/examples/run_on_demand.rs b/examples/run_on_demand.rs index e6d105ad5e..8740b6b66f 100644 --- a/examples/run_on_demand.rs +++ b/examples/run_on_demand.rs @@ -14,7 +14,7 @@ fn main() -> Result<(), Box> { #[path = "util/fill.rs"] mod fill; - #[derive(Default)] + #[derive(Default, Debug)] struct App { idx: usize, window_id: Option, diff --git a/examples/window.rs b/examples/window.rs index e70c462674..c0db0bcf77 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -12,7 +12,7 @@ use winit::window::{Window, WindowAttributes, WindowId}; #[path = "util/fill.rs"] mod fill; -#[derive(Default)] +#[derive(Default, Debug)] struct App { window: Option>, } diff --git a/examples/x11_embed.rs b/examples/x11_embed.rs index 1b9a796ff6..e600a5d052 100644 --- a/examples/x11_embed.rs +++ b/examples/x11_embed.rs @@ -12,6 +12,7 @@ fn main() -> Result<(), Box> { #[path = "util/fill.rs"] mod fill; + #[derive(Debug)] pub struct XEmbedDemo { parent_window_id: u32, window: Option>, diff --git a/src/event_loop.rs b/src/event_loop.rs index 059613459b..3577520d86 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -43,6 +43,7 @@ use crate::window::{CustomCursor, CustomCursorSource, Theme, Window, WindowAttri /// [`EventLoopProxy`] allows you to wake up an `EventLoop` from another thread. /// /// [`Window`]: crate::window::Window +#[derive(Debug)] pub struct EventLoop { pub(crate) event_loop: platform_impl::EventLoop, pub(crate) _marker: PhantomData<*mut ()>, // Not Send nor Sync @@ -54,7 +55,7 @@ pub struct EventLoop { /// easier. But note that constructing multiple event loops is not supported. /// /// This can be created using [`EventLoop::builder`]. -#[derive(Default, PartialEq, Eq, Hash)] +#[derive(Default, Debug, PartialEq, Eq, Hash)] pub struct EventLoopBuilder { pub(crate) platform_specific: platform_impl::PlatformSpecificEventLoopAttributes, } @@ -117,18 +118,6 @@ impl EventLoopBuilder { } } -impl fmt::Debug for EventLoopBuilder { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("EventLoopBuilder").finish_non_exhaustive() - } -} - -impl fmt::Debug for EventLoop { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("EventLoop").finish_non_exhaustive() - } -} - /// Set through [`ActiveEventLoop::set_control_flow()`]. /// /// Indicates the desired behavior of the event loop after [`about_to_wait`] is called. @@ -309,7 +298,7 @@ impl AsRawFd for EventLoop { } } -pub trait ActiveEventLoop: AsAny { +pub trait ActiveEventLoop: AsAny + fmt::Debug { /// Creates an [`EventLoopProxy`] that can be used to dispatch user events /// to the main event loop, possibly from another thread. fn create_proxy(&self) -> EventLoopProxy; @@ -463,23 +452,17 @@ impl PartialEq for OwnedDisplayHandle { impl Eq for OwnedDisplayHandle {} -pub(crate) trait EventLoopProxyProvider: Send + Sync { +pub(crate) trait EventLoopProxyProvider: Send + Sync + fmt::Debug { /// See [`EventLoopProxy::wake_up`] for details. fn wake_up(&self); } /// Control the [`EventLoop`], possibly from a different thread, without referencing it directly. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct EventLoopProxy { pub(crate) proxy: Arc, } -impl fmt::Debug for EventLoopProxy { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("EventLoopProxy").finish_non_exhaustive() - } -} - impl EventLoopProxy { /// Wake up the [`EventLoop`], resulting in [`ApplicationHandler::proxy_wake_up()`] being /// called. diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index df4250f077..9630656029 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -44,7 +44,7 @@ fn min_timeout(a: Option, b: Option) -> Option { a.map_or(b, |a_timeout| b.map_or(Some(a_timeout), |b_timeout| Some(a_timeout.min(b_timeout)))) } -#[derive(Clone)] +#[derive(Clone, Debug)] struct SharedFlagSetter { flag: Arc, } @@ -54,6 +54,7 @@ impl SharedFlagSetter { } } +#[derive(Debug)] struct SharedFlag { flag: Arc, } @@ -82,6 +83,12 @@ pub struct RedrawRequester { waker: AndroidAppWaker, } +impl fmt::Debug for RedrawRequester { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RedrawRequester").field("flag", &self.flag).finish_non_exhaustive() + } +} + impl RedrawRequester { fn new(flag: &SharedFlag, waker: AndroidAppWaker) -> Self { RedrawRequester { flag: flag.setter(), waker } @@ -96,6 +103,7 @@ impl RedrawRequester { } } +#[derive(Debug)] pub struct EventLoop { pub(crate) android_app: AndroidApp, window_target: ActiveEventLoop, @@ -639,6 +647,12 @@ pub struct EventLoopProxy { waker: AndroidAppWaker, } +impl fmt::Debug for EventLoopProxy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EventLoopProxy").field("wake_up", &self.wake_up).finish_non_exhaustive() + } +} + impl EventLoopProxy { fn new(waker: AndroidAppWaker) -> Self { Self { wake_up: AtomicBool::new(false), waker } @@ -652,6 +666,7 @@ impl EventLoopProxyProvider for EventLoopProxy { } } +#[derive(Debug)] pub struct ActiveEventLoop { pub(crate) app: AndroidApp, control_flow: Cell, @@ -744,6 +759,7 @@ impl rwh_06::HasDisplayHandle for OwnedDisplayHandle { #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct PlatformSpecificWindowAttributes; +#[derive(Debug)] pub(crate) struct Window { app: AndroidApp, redraw_requester: RedrawRequester, diff --git a/src/platform_impl/apple/appkit/event_loop.rs b/src/platform_impl/apple/appkit/event_loop.rs index 64d16ea2c2..179df8f15e 100644 --- a/src/platform_impl/apple/appkit/event_loop.rs +++ b/src/platform_impl/apple/appkit/event_loop.rs @@ -1,5 +1,6 @@ use std::any::Any; use std::cell::Cell; +use std::fmt; use std::panic::{catch_unwind, resume_unwind, RefUnwindSafe, UnwindSafe}; use std::rc::{Rc, Weak}; use std::sync::Arc; @@ -39,6 +40,12 @@ pub struct PanicInfo { inner: Cell>>, } +impl fmt::Debug for PanicInfo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("PanicInfo").finish_non_exhaustive() + } +} + // WARNING: // As long as this struct is used through its `impl`, it is UnwindSafe. // (If `get_mut` is called on `inner`, unwind safety may get broken.) @@ -161,6 +168,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop { } } +#[derive(Debug)] pub struct EventLoop { /// Store a reference to the application for convenience. /// diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 5317c5eeda..0f1c5ab119 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -16,6 +16,7 @@ use crate::window::{ WindowAttributes, WindowButtons, WindowId, WindowLevel, }; +#[derive(Debug)] pub(crate) struct Window { window: MainThreadBound>, /// The window only keeps a weak reference to this, so we must keep it around here. diff --git a/src/platform_impl/apple/uikit/event_loop.rs b/src/platform_impl/apple/uikit/event_loop.rs index 8c17dbd620..a86ceda824 100644 --- a/src/platform_impl/apple/uikit/event_loop.rs +++ b/src/platform_impl/apple/uikit/event_loop.rs @@ -116,6 +116,7 @@ impl HasDisplayHandle for OwnedDisplayHandle { } } +#[derive(Debug)] pub struct EventLoop { mtm: MainThreadMarker, window_target: ActiveEventLoop, diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 2bf9e0fe83..85248de5a0 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -459,6 +459,7 @@ impl Inner { } } +#[derive(Debug)] pub struct Window { inner: MainThreadBound, } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index a3da3a24eb..eb76a9c06c 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -231,6 +231,7 @@ unsafe extern "C" fn x_error_callback( 0 } +#[derive(Debug)] pub enum EventLoop { #[cfg(wayland_platform)] Wayland(Box), diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 615634751f..9d1270ca26 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -45,6 +45,7 @@ pub(crate) enum Event { } /// The Wayland event loop. +#[derive(Debug)] pub struct EventLoop { /// Has `run` or `run_on_demand` been called or a call to `pump_events` that starts the loop loop_running: bool, @@ -546,6 +547,7 @@ impl AsRawFd for EventLoop { } } +#[derive(Debug)] pub struct ActiveEventLoop { /// Event loop proxy event_loop_proxy: CoreEventLoopProxy, @@ -665,6 +667,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop { } } +#[derive(Debug)] pub struct OwnedDisplayHandle { pub(crate) connection: Connection, } diff --git a/src/platform_impl/linux/wayland/event_loop/proxy.rs b/src/platform_impl/linux/wayland/event_loop/proxy.rs index 7eaec87389..f48e3e8483 100644 --- a/src/platform_impl/linux/wayland/event_loop/proxy.rs +++ b/src/platform_impl/linux/wayland/event_loop/proxy.rs @@ -7,6 +7,7 @@ use sctk::reexports::calloop::ping::Ping; use crate::event_loop::{EventLoopProxy as CoreEventLoopProxy, EventLoopProxyProvider}; /// A handle that can be sent across the threads and used to wake up the `EventLoop`. +#[derive(Debug)] pub struct EventLoopProxy { ping: Ping, } diff --git a/src/platform_impl/linux/wayland/event_loop/sink.rs b/src/platform_impl/linux/wayland/event_loop/sink.rs index c1c08b5ce6..0622ee2be0 100644 --- a/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -8,7 +8,7 @@ use crate::window::WindowId; /// An event loop's sink to deliver events from the Wayland event callbacks /// to the winit's user. -#[derive(Default)] +#[derive(Default, Debug)] pub struct EventSink { pub(crate) window_events: Vec, } diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 8f1f74d40b..91f8f9d159 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -414,6 +414,7 @@ impl WinitPointerDataExt for WlPointer { } } +#[derive(Debug)] pub struct PointerConstraintsState { pointer_constraints: ZwpPointerConstraintsV1, } diff --git a/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs b/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs index 4e7c7ec179..674927280e 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/relative_pointer.rs @@ -16,6 +16,7 @@ use crate::event::DeviceEvent; use crate::platform_impl::wayland::state::WinitState; /// Wrapper around the relative pointer. +#[derive(Debug)] pub struct RelativePointerState { manager: ZwpRelativePointerManagerV1, } diff --git a/src/platform_impl/linux/wayland/seat/text_input/mod.rs b/src/platform_impl/linux/wayland/seat/text_input/mod.rs index 45a0f6c9fd..140f7dfc2b 100644 --- a/src/platform_impl/linux/wayland/seat/text_input/mod.rs +++ b/src/platform_impl/linux/wayland/seat/text_input/mod.rs @@ -14,6 +14,7 @@ use crate::platform_impl::wayland; use crate::platform_impl::wayland::state::WinitState; use crate::window::ImePurpose; +#[derive(Debug)] pub struct TextInputState { text_input_manager: ZwpTextInputManagerV3, } diff --git a/src/platform_impl/linux/wayland/state.rs b/src/platform_impl/linux/wayland/state.rs index bec0a55d3a..37f7e34f3b 100644 --- a/src/platform_impl/linux/wayland/state.rs +++ b/src/platform_impl/linux/wayland/state.rs @@ -36,6 +36,7 @@ use crate::platform_impl::wayland::window::{WindowRequests, WindowState}; use crate::platform_impl::wayland::WindowId; /// Winit's Wayland state. +#[derive(Debug)] pub struct WinitState { /// The WlRegistry. pub registry_state: RegistryState, diff --git a/src/platform_impl/linux/wayland/types/xdg_activation.rs b/src/platform_impl/linux/wayland/types/xdg_activation.rs index dda87222b1..6866ff795c 100644 --- a/src/platform_impl/linux/wayland/types/xdg_activation.rs +++ b/src/platform_impl/linux/wayland/types/xdg_activation.rs @@ -16,6 +16,7 @@ use crate::event_loop::AsyncRequestSerial; use crate::platform_impl::wayland::state::WinitState; use crate::window::{ActivationToken, WindowId}; +#[derive(Debug)] pub struct XdgActivationState { xdg_activation: XdgActivationV1, } diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 761ea7ffa5..df449d8614 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -34,6 +34,7 @@ pub(crate) mod state; pub use state::WindowState; /// The Wayland window. +#[derive(Debug)] pub struct Window { /// Reference to the underlying SCTK window. window: SctkWindow, diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 69430d79b0..fdbeb04c0d 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -51,6 +51,7 @@ pub type WinitFrame = sctk::shell::xdg::fallback_frame::FallbackFrame = LogicalSize::new(2, 1); /// The state of the window which is being updated from the [`WinitState`]. +#[derive(Debug)] pub struct WindowState { /// The connection to Wayland server. pub handle: Arc, @@ -1097,7 +1098,7 @@ impl Drop for WindowState { } /// The state of the cursor grabs. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] struct GrabState { /// The grab mode requested by the user. user_grab_mode: CursorGrabMode, diff --git a/src/platform_impl/linux/x11/dnd.rs b/src/platform_impl/linux/x11/dnd.rs index f5988aaad6..a165085402 100644 --- a/src/platform_impl/linux/x11/dnd.rs +++ b/src/platform_impl/linux/x11/dnd.rs @@ -39,6 +39,7 @@ impl From for DndDataParseError { } } +#[derive(Debug)] pub struct Dnd { xconn: Arc, // Populated by XdndEnter event handler diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 82ef47ef61..4c57028014 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -45,6 +45,7 @@ pub const MAX_MOD_REPLAY_LEN: usize = 32; /// The X11 documentation states: "Keycodes lie in the inclusive range `[8, 255]`". const KEYCODE_OFFSET: u8 = 8; +#[derive(Debug)] pub struct EventProcessor { pub dnd: Dnd, pub ime_receiver: ImeReceiver, diff --git a/src/platform_impl/linux/x11/ime/mod.rs b/src/platform_impl/linux/x11/ime/mod.rs index 0a419c8d50..650ccf9ee3 100644 --- a/src/platform_impl/linux/x11/ime/mod.rs +++ b/src/platform_impl/linux/x11/ime/mod.rs @@ -5,6 +5,7 @@ mod context; mod inner; mod input_method; +use std::fmt; use std::sync::mpsc::{Receiver, Sender}; use std::sync::Arc; @@ -56,6 +57,12 @@ pub(crate) struct Ime { inner: Box, } +impl fmt::Debug for Ime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Ime").finish_non_exhaustive() + } +} + impl Ime { pub fn new( xconn: Arc, diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 20424ece1e..41cd999e76 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -71,6 +71,7 @@ type X11rbConnection = x11rb::xcb_ffi::XCBConnection; type X11Source = Generic>; +#[derive(Debug)] struct WakeSender { sender: Sender, waker: Ping, @@ -91,6 +92,7 @@ impl WakeSender { } } +#[derive(Debug)] struct PeekableReceiver { recv: Receiver, first: Option, @@ -127,6 +129,7 @@ impl PeekableReceiver { } } +#[derive(Debug)] pub struct ActiveEventLoop { xconn: Arc, wm_delete_window: xproto::Atom, @@ -144,6 +147,7 @@ pub struct ActiveEventLoop { device_events: Cell, } +#[derive(Debug)] pub struct EventLoop { loop_running: bool, event_loop: Loop<'static, EventLoopState>, @@ -157,6 +161,7 @@ pub struct EventLoop { type ActivationToken = (WindowId, crate::event_loop::AsyncRequestSerial); +#[derive(Debug)] struct EventLoopState { /// The latest readiness state for the x11 file descriptor x11_readiness: Readiness, @@ -762,7 +767,7 @@ impl Deref for DeviceInfo<'_> { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct EventLoopProxy { ping: Ping, } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 94888261e0..7d7f7442c8 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -39,6 +39,7 @@ use crate::window::{ WindowAttributes, WindowButtons, WindowId, WindowLevel, }; +#[derive(Debug)] pub(crate) struct Window(Arc); impl Deref for Window { @@ -411,6 +412,7 @@ impl SharedState { unsafe impl Send for UnownedWindow {} unsafe impl Sync for UnownedWindow {} +#[derive(Debug)] pub struct UnownedWindow { pub(crate) xconn: Arc, // never changes xwindow: xproto::Window, // never changes diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 410846b6bd..a1c04a2ade 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -165,7 +165,7 @@ bitflags! { } } -#[derive(Default)] +#[derive(Default, Debug)] struct EventState { keyboard: KeyboardModifierState, mouse: MouseButtonState, @@ -274,6 +274,7 @@ impl EventState { } } +#[derive(Debug)] pub struct EventLoop { windows: Vec<(Arc, EventState)>, window_target: ActiveEventLoop, @@ -661,6 +662,7 @@ impl EventLoop { } } +#[derive(Debug)] pub struct EventLoopProxy { user_events_sender: mpsc::SyncSender<()>, pub(super) wake_socket: TimeSocket, @@ -678,6 +680,7 @@ impl EventLoopProxyProvider for EventLoopProxy { impl Unpin for EventLoopProxy {} +#[derive(Debug)] pub struct ActiveEventLoop { control_flow: Cell, exit: Cell, diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index 7799417f8b..9f717106f6 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -15,6 +15,7 @@ pub(crate) use crate::cursor::{ }; pub(crate) use crate::icon::NoIcon as PlatformIcon; +#[derive(Debug)] struct RedoxSocket { fd: usize, } @@ -67,6 +68,7 @@ impl Drop for RedoxSocket { } } +#[derive(Debug)] pub struct TimeSocket(RedoxSocket); impl TimeSocket { diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 0699b1fe10..72e3a7f309 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -20,6 +20,7 @@ const ORBITAL_FLAG_MAXIMIZED: char = 'm'; const ORBITAL_FLAG_RESIZABLE: char = 'r'; const ORBITAL_FLAG_TRANSPARENT: char = 't'; +#[derive(Debug)] pub struct Window { window_socket: Arc, redraws: Arc>>, diff --git a/src/platform_impl/web/async/wrapper.rs b/src/platform_impl/web/async/wrapper.rs index c26df39c79..4b037def77 100644 --- a/src/platform_impl/web/async/wrapper.rs +++ b/src/platform_impl/web/async/wrapper.rs @@ -9,6 +9,7 @@ use super::super::main_thread::MainThreadMarker; // Unsafe wrapper type that allows us to use `T` when it's not `Send` from other threads. // `value` **must** only be accessed on the main thread. +#[derive(Debug)] pub struct Wrapper { value: Value, handler: fn(&RefCell>, E), @@ -16,6 +17,7 @@ pub struct Wrapper { sender_handler: fn(&S, E), } +#[derive(Debug)] struct Value { // SAFETY: // This value must not be accessed if not on the main thread. diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index 112dd7d237..fe2f0d13aa 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -11,6 +11,7 @@ mod window_target; pub(crate) use window_target::ActiveEventLoop; +#[derive(Debug)] pub struct EventLoop { elw: ActiveEventLoop, } diff --git a/src/platform_impl/web/event_loop/proxy.rs b/src/platform_impl/web/event_loop/proxy.rs index c148deaf0f..dfb64cdc41 100644 --- a/src/platform_impl/web/event_loop/proxy.rs +++ b/src/platform_impl/web/event_loop/proxy.rs @@ -8,8 +8,10 @@ use crate::event_loop::EventLoopProxyProvider; use crate::platform_impl::web::event_loop::runner::WeakShared; use crate::platform_impl::web::r#async::{AtomicWaker, Wrapper}; +#[derive(Debug)] pub struct EventLoopProxy(Wrapper, ()>); +#[derive(Debug)] struct State { awoken: AtomicBool, waker: AtomicWaker, diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index b5022c9253..3a6db3a6b0 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -1,9 +1,9 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashSet, VecDeque}; -use std::iter; use std::ops::Deref; use std::rc::{Rc, Weak}; use std::sync::Arc; +use std::{fmt, iter}; use wasm_bindgen::prelude::Closure; use wasm_bindgen::JsCast; @@ -26,6 +26,7 @@ use crate::platform_impl::platform::r#async::DispatchRunner; use crate::platform_impl::platform::window::Inner; use crate::window::WindowId; +#[derive(Debug)] pub struct Shared(Rc); impl Clone for Shared { @@ -68,6 +69,12 @@ struct Execution { on_visibility_change: OnEventHandle, } +impl fmt::Debug for Execution { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Execution").finish_non_exhaustive() + } +} + enum RunnerEnum { /// The `EventLoop` is created but not being run. Pending, @@ -96,6 +103,16 @@ struct Runner { event_loop: ActiveEventLoop, } +impl fmt::Debug for Runner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Runner") + .field("state", &self.state) + .field("app", &"") + .field("event_loop", &self.event_loop) + .finish() + } +} + impl Runner { pub fn new(app: Box, event_loop: ActiveEventLoop) -> Self { Runner { state: State::Init, app, event_loop } diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 08d333dec8..a5a266858b 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -25,7 +25,7 @@ use crate::platform_impl::web::event_loop::proxy::EventLoopProxy; use crate::platform_impl::Window; use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId}; -#[derive(Default)] +#[derive(Default, Debug)] struct ModifiersShared(Rc>); impl ModifiersShared { @@ -44,7 +44,7 @@ impl Clone for ModifiersShared { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ActiveEventLoop { pub(crate) runner: runner::Shared, modifiers: ModifiersShared, diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 352a231a6a..9ae561213d 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -1,4 +1,5 @@ use std::cell::Ref; +use std::fmt; use std::rc::Rc; use std::sync::Arc; @@ -23,6 +24,12 @@ pub struct Window { inner: Dispatcher, } +impl fmt::Debug for Window { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Window").finish_non_exhaustive() + } +} + pub struct Inner { id: WindowId, pub window: web_sys::Window, diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 3a5778c0d8..bb4ec8d211 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -9,7 +9,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::{Arc, Mutex, MutexGuard}; use std::time::{Duration, Instant}; -use std::{mem, panic, ptr}; +use std::{fmt, mem, panic, ptr}; use windows_sys::Win32::Foundation::{ GetLastError, FALSE, HANDLE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_FAILED, WPARAM, @@ -147,12 +147,27 @@ pub struct EventLoop { high_resolution_timer: Option, } +impl fmt::Debug for EventLoop { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EventLoop").finish_non_exhaustive() + } +} + pub(crate) struct PlatformSpecificEventLoopAttributes { pub(crate) any_thread: bool, pub(crate) dpi_aware: bool, pub(crate) msg_hook: Option bool + 'static>>, } +impl fmt::Debug for PlatformSpecificEventLoopAttributes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("PlatformSpecificEventLoopAttributes") + .field("any_thread", &self.any_thread) + .field("dpi_aware", &self.dpi_aware) + .finish_non_exhaustive() + } +} + impl Default for PlatformSpecificEventLoopAttributes { fn default() -> Self { Self { any_thread: false, dpi_aware: true, msg_hook: None } @@ -379,6 +394,7 @@ impl Drop for EventLoop { } #[repr(transparent)] +#[derive(Debug)] pub(crate) struct ActiveEventLoop(pub Rc); impl ActiveEventLoop { @@ -681,6 +697,7 @@ fn wait_for_messages_impl( } } +#[derive(Debug)] pub(crate) struct EventLoopThreadExecutor { thread_id: u32, target_window: HWND, @@ -731,6 +748,7 @@ impl EventLoopThreadExecutor { type ThreadExecFn = Box>; +#[derive(Debug)] pub struct EventLoopProxy { target_window: HWND, } diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index e6183d6d17..ab6516544a 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -4,7 +4,7 @@ use std::collections::VecDeque; use std::rc::Rc; use std::sync::{Arc, Mutex}; use std::time::Instant; -use std::{mem, panic}; +use std::{fmt, mem, panic}; use windows_sys::Win32::Foundation::HWND; @@ -40,6 +40,14 @@ pub(crate) struct EventLoopRunner { panic_error: Cell>, } +impl fmt::Debug for EventLoopRunner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EventLoopRunner") + .field("thread_msg_target", &self.thread_msg_target) + .finish_non_exhaustive() + } +} + pub type PanicError = Box; /// See `move_state_to` function for details on how the state loop works. diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index a38370c339..3134ad0583 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -76,7 +76,7 @@ use crate::window::{ WindowLevel, }; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] #[repr(transparent)] /// We need to pass the window handle to the event loop thread, which means it needs to be /// Send+Sync. @@ -92,6 +92,7 @@ impl SyncWindowHandle { } /// The Win32 implementation of the main `Window` object. +#[derive(Debug)] pub(crate) struct Window { /// Main handle for the window. window: SyncWindowHandle, diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index d128c1d9dc..28b5c3bb09 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -1,5 +1,5 @@ use std::sync::MutexGuard; -use std::{io, ptr}; +use std::{fmt, io, ptr}; use bitflags::bitflags; use windows_sys::Win32::Foundation::{HWND, RECT}; @@ -23,6 +23,7 @@ use crate::platform_impl::platform::{event_loop, util, Fullscreen, SelectedCurso use crate::window::{Theme, WindowAttributes}; /// Contains information about states and the window that the callback is going to use. +#[derive(Debug)] pub(crate) struct WindowState { pub mouse: MouseProperties, @@ -65,7 +66,13 @@ pub struct SavedWindow { pub placement: WINDOWPLACEMENT, } -#[derive(Clone)] +impl fmt::Debug for SavedWindow { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SavedWindow").finish_non_exhaustive() + } +} + +#[derive(Clone, Debug)] pub struct MouseProperties { pub(crate) selected_cursor: SelectedCursor, pub capture_count: u32, @@ -129,7 +136,7 @@ bitflags! { } } -#[derive(Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Hash)] pub enum ImeState { Disabled, Enabled, diff --git a/src/window.rs b/src/window.rs index 0a0504bafc..3c5c2431c5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -431,7 +431,7 @@ impl WindowAttributes { /// /// **Web:** The [`Window`], which is represented by a `HTMLElementCanvas`, can /// not be closed by dropping the [`Window`]. -pub trait Window: AsAny + Send + Sync { +pub trait Window: AsAny + Send + Sync + fmt::Debug { /// Returns an identifier unique to the window. fn id(&self) -> WindowId;