[Debug Trait] input.rs, udev.rs, winit.rs

smithay/smithay#258
This commit is contained in:
Poly 2021-02-09 20:57:14 +01:00
parent 991eba216d
commit f6a63d351d
3 changed files with 39 additions and 8 deletions

View File

@ -87,6 +87,7 @@ pub trait Event {
/// that is not used by an [`InputBackend`] implementation. Initialization is not /// that is not used by an [`InputBackend`] implementation. Initialization is not
/// possible, making accidental use impossible and enabling a lot of possible /// possible, making accidental use impossible and enabling a lot of possible
/// compiler optimizations. /// compiler optimizations.
#[derive(Debug)]
pub enum UnusedEvent {} pub enum UnusedEvent {}
impl Event for UnusedEvent { impl Event for UnusedEvent {
@ -537,6 +538,7 @@ pub trait InputBackend: Sized {
} }
/// Different events that can be generated by an input backend /// Different events that can be generated by an input backend
#[derive(Debug)]
pub enum InputEvent<B: InputBackend> { pub enum InputEvent<B: InputBackend> {
/// A new seat has been created /// A new seat has been created
NewSeat(Seat), NewSeat(Seat),

View File

@ -43,6 +43,7 @@ use nix::sys::stat::{dev_t, stat};
use std::{ use std::{
collections::HashMap, collections::HashMap,
ffi::OsString, ffi::OsString,
fmt,
io::Result as IoResult, io::Result as IoResult,
os::unix::io::{AsRawFd, RawFd}, os::unix::io::{AsRawFd, RawFd},
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -62,6 +63,17 @@ pub struct UdevBackend {
logger: ::slog::Logger, 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 { impl AsRawFd for UdevBackend {
fn as_raw_fd(&self) -> RawFd { fn as_raw_fd(&self) -> RawFd {
self.monitor.as_raw_fd() 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 /// Events generated by the [`UdevBackend`], notifying you of changes in system devices
#[derive(Debug)]
pub enum UdevEvent { pub enum UdevEvent {
/// A new device has been detected /// A new device has been detected
Added { Added {

View File

@ -16,6 +16,7 @@ use nix::libc::c_void;
use std::{ use std::{
cell::{Ref, RefCell}, cell::{Ref, RefCell},
convert::TryInto, convert::TryInto,
fmt,
rc::Rc, rc::Rc,
time::Instant, 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 { impl Window {
fn window(&self) -> Ref<'_, WinitWindow> { fn window(&self) -> Ref<'_, WinitWindow> {
match *self { match *self {
@ -74,6 +85,7 @@ impl Window {
} }
} }
#[derive(Debug)]
struct WindowSize { struct WindowSize {
physical_size: PhysicalSize<u32>, physical_size: PhysicalSize<u32>,
scale_factor: f64, scale_factor: f64,
@ -81,6 +93,7 @@ struct WindowSize {
/// Window with an active EGL Context created by `winit`. Implements the /// Window with an active EGL Context created by `winit`. Implements the
/// [`EGLGraphicsBackend`] and [`GLGraphicsBackend`] graphics backend trait /// [`EGLGraphicsBackend`] and [`GLGraphicsBackend`] graphics backend trait
#[derive(Debug)]
pub struct WinitGraphicsBackend { pub struct WinitGraphicsBackend {
window: Rc<Window>, window: Rc<Window>,
size: Rc<RefCell<WindowSize>>, size: Rc<RefCell<WindowSize>>,
@ -91,6 +104,7 @@ pub struct WinitGraphicsBackend {
/// ///
/// You need to call [`dispatch_new_events`](InputBackend::dispatch_new_events) /// You need to call [`dispatch_new_events`](InputBackend::dispatch_new_events)
/// periodically to receive any events. /// periodically to receive any events.
#[derive(Debug)]
pub struct WinitInputBackend { pub struct WinitInputBackend {
events_loop: EventLoop<()>, events_loop: EventLoop<()>,
window: Rc<Window>, window: Rc<Window>,
@ -226,6 +240,7 @@ where
} }
/// Specific events generated by Winit /// Specific events generated by Winit
#[derive(Debug)]
pub enum WinitEvent { pub enum WinitEvent {
/// The window has been resized /// The window has been resized
Resized { Resized {
@ -358,8 +373,8 @@ pub enum WinitInputError {
WindowClosed, WindowClosed,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
/// Winit-Backend internal event wrapping `winit`'s types into a [`KeyboardKeyEvent`] /// Winit-Backend internal event wrapping `winit`'s types into a [`KeyboardKeyEvent`]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WinitKeyboardInputEvent { pub struct WinitKeyboardInputEvent {
time: u32, time: u32,
key: u32, key: u32,
@ -387,8 +402,8 @@ impl KeyboardKeyEvent for WinitKeyboardInputEvent {
} }
} }
#[derive(Clone)]
/// Winit-Backend internal event wrapping `winit`'s types into a [`PointerMotionAbsoluteEvent`] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerMotionAbsoluteEvent`]
#[derive(Debug, Clone)]
pub struct WinitMouseMovedEvent { pub struct WinitMouseMovedEvent {
size: Rc<RefCell<WindowSize>>, size: Rc<RefCell<WindowSize>>,
time: u32, 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`] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerAxisEvent`]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct WinitMouseWheelEvent { pub struct WinitMouseWheelEvent {
time: u32, time: u32,
delta: MouseScrollDelta, 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`] /// Winit-Backend internal event wrapping `winit`'s types into a [`PointerButtonEvent`]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WinitMouseInputEvent { pub struct WinitMouseInputEvent {
time: u32, time: u32,
button: WinitMouseButton, button: WinitMouseButton,
@ -488,8 +503,8 @@ impl PointerButtonEvent for WinitMouseInputEvent {
} }
} }
#[derive(Clone)]
/// Winit-Backend internal event wrapping `winit`'s types into a [`TouchDownEvent`] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchDownEvent`]
#[derive(Debug, Clone)]
pub struct WinitTouchStartedEvent { pub struct WinitTouchStartedEvent {
size: Rc<RefCell<WindowSize>>, size: Rc<RefCell<WindowSize>>,
time: u32, time: u32,
@ -531,8 +546,8 @@ impl TouchDownEvent for WinitTouchStartedEvent {
} }
} }
#[derive(Clone)]
/// Winit-Backend internal event wrapping `winit`'s types into a [`TouchMotionEvent`] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchMotionEvent`]
#[derive(Debug, Clone)]
pub struct WinitTouchMovedEvent { pub struct WinitTouchMovedEvent {
size: Rc<RefCell<WindowSize>>, size: Rc<RefCell<WindowSize>>,
time: u32, 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` /// Winit-Backend internal event wrapping `winit`'s types into a `TouchUpEvent`
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WinitTouchEndedEvent { pub struct WinitTouchEndedEvent {
time: u32, time: u32,
id: u64, 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`] /// Winit-Backend internal event wrapping `winit`'s types into a [`TouchCancelEvent`]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WinitTouchCancelledEvent { pub struct WinitTouchCancelledEvent {
time: u32, time: u32,
id: u64, id: u64,
@ -615,6 +630,7 @@ impl TouchCancelEvent for WinitTouchCancelledEvent {
/// Input config for Winit /// Input config for Winit
/// ///
/// This backend does not allow any input configuration, so this type does nothing. /// This backend does not allow any input configuration, so this type does nothing.
#[derive(Debug)]
pub struct WinitInputConfig; pub struct WinitInputConfig;
impl InputBackend for WinitInputBackend { impl InputBackend for WinitInputBackend {