From 658f49b014a9e46beb19954855106413507c732b Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 26 Dec 2023 22:12:33 +0100 Subject: [PATCH] Rename `VideoMode` to `VideoModeHandle` (#3328) --- CHANGELOG.md | 1 + src/monitor.rs | 30 +++++++++++++---------- src/platform/ios.rs | 10 ++++---- src/platform_impl/android/mod.rs | 8 +++--- src/platform_impl/ios/mod.rs | 2 +- src/platform_impl/ios/monitor.rs | 22 ++++++++--------- src/platform_impl/linux/mod.rs | 18 +++++++------- src/platform_impl/linux/wayland/mod.rs | 2 +- src/platform_impl/linux/wayland/output.rs | 10 ++++---- src/platform_impl/linux/x11/mod.rs | 2 +- src/platform_impl/linux/x11/monitor.rs | 12 ++++----- src/platform_impl/linux/x11/util/randr.rs | 6 ++--- src/platform_impl/linux/x11/window.rs | 8 +++--- src/platform_impl/macos/mod.rs | 2 +- src/platform_impl/macos/monitor.rs | 18 +++++++------- src/platform_impl/macos/window.rs | 4 +-- src/platform_impl/mod.rs | 10 +++++--- src/platform_impl/orbital/mod.rs | 8 +++--- src/platform_impl/web/mod.rs | 2 +- src/platform_impl/web/monitor.rs | 6 ++--- src/platform_impl/windows/mod.rs | 2 +- src/platform_impl/windows/monitor.rs | 28 ++++++++++----------- src/window.rs | 4 +-- 23 files changed, 111 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b22a07acbe..d8b23bb291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Unreleased` header. - **Breaking:** Bump MSRV from `1.65` to `1.70`. - On Web, add the ability to toggle calling `Event.preventDefault()` on `Window`. - **Breaking:** Remove `WindowAttributes::fullscreen()` and expose as field directly. +- **Breaking:** Rename `VideoMode` to `VideoModeHandle` to represent that it doesn't hold static data. # 0.29.6 diff --git a/src/monitor.rs b/src/monitor.rs index 45c355e529..7fe7e23494 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -10,28 +10,32 @@ use crate::{ platform_impl, }; +/// Deprecated! Use `VideoModeHandle` instead. +#[deprecated = "Renamed to `VideoModeHandle`"] +pub type VideoMode = VideoModeHandle; + /// Describes a fullscreen video mode of a monitor. /// /// Can be acquired with [`MonitorHandle::video_modes`]. #[derive(Clone, PartialEq, Eq, Hash)] -pub struct VideoMode { - pub(crate) video_mode: platform_impl::VideoMode, +pub struct VideoModeHandle { + pub(crate) video_mode: platform_impl::VideoModeHandle, } -impl std::fmt::Debug for VideoMode { +impl std::fmt::Debug for VideoModeHandle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.video_mode.fmt(f) } } -impl PartialOrd for VideoMode { - fn partial_cmp(&self, other: &VideoMode) -> Option { +impl PartialOrd for VideoModeHandle { + fn partial_cmp(&self, other: &VideoModeHandle) -> Option { Some(self.cmp(other)) } } -impl Ord for VideoMode { - fn cmp(&self, other: &VideoMode) -> std::cmp::Ordering { +impl Ord for VideoModeHandle { + fn cmp(&self, other: &VideoModeHandle) -> std::cmp::Ordering { self.monitor().cmp(&other.monitor()).then( self.size() .cmp(&other.size()) @@ -45,7 +49,7 @@ impl Ord for VideoMode { } } -impl VideoMode { +impl VideoModeHandle { /// Returns the resolution of this video mode. #[inline] pub fn size(&self) -> PhysicalSize { @@ -81,7 +85,7 @@ impl VideoMode { } } -impl std::fmt::Display for VideoMode { +impl std::fmt::Display for VideoModeHandle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, @@ -131,8 +135,8 @@ impl MonitorHandle { /// Return `Some` if succeed, or `None` if failed, which usually happens when the monitor /// the window is on is removed. /// - /// When using exclusive fullscreen, the refresh rate of the [`VideoMode`] that was used to - /// enter fullscreen should be used instead. + /// When using exclusive fullscreen, the refresh rate of the [`VideoModeHandle`] that was + /// used to enter fullscreen should be used instead. #[inline] pub fn refresh_rate_millihertz(&self) -> Option { self.inner.refresh_rate_millihertz() @@ -161,9 +165,9 @@ impl MonitorHandle { /// /// - **Web:** Always returns an empty iterator #[inline] - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { self.inner .video_modes() - .map(|video_mode| VideoMode { video_mode }) + .map(|video_mode| VideoModeHandle { video_mode }) } } diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 49be3129ae..2cb0704450 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -5,7 +5,7 @@ use objc2::rc::Id; use crate::{ event_loop::EventLoop, - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, window::{Window, WindowBuilder}, }; @@ -230,10 +230,10 @@ pub trait MonitorHandleExtIOS { /// [`UIScreen`]: https://developer.apple.com/documentation/uikit/uiscreen?language=objc fn ui_screen(&self) -> *mut c_void; - /// Returns the preferred [`VideoMode`] for this monitor. + /// Returns the preferred [`VideoModeHandle`] for this monitor. /// /// This translates to a call to [`-[UIScreen preferredMode]`](https://developer.apple.com/documentation/uikit/uiscreen/1617823-preferredmode?language=objc). - fn preferred_video_mode(&self) -> VideoMode; + fn preferred_video_mode(&self) -> VideoModeHandle; } impl MonitorHandleExtIOS for MonitorHandle { @@ -245,8 +245,8 @@ impl MonitorHandleExtIOS for MonitorHandle { } #[inline] - fn preferred_video_mode(&self) -> VideoMode { - VideoMode { + fn preferred_video_mode(&self) -> VideoModeHandle { + VideoModeHandle { video_mode: self.inner.preferred_video_mode(), } } diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 7ecb13d3fe..450138f276 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -1090,11 +1090,11 @@ impl MonitorHandle { None } - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { let size = self.size().into(); // FIXME this is not the real refresh rate // (it is guaranteed to support 32 bit color though) - std::iter::once(VideoMode { + std::iter::once(VideoModeHandle { size, bit_depth: 32, refresh_rate_millihertz: 60000, @@ -1104,14 +1104,14 @@ impl MonitorHandle { } #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct VideoMode { +pub struct VideoModeHandle { size: (u32, u32), bit_depth: u16, refresh_rate_millihertz: u32, monitor: MonitorHandle, } -impl VideoMode { +impl VideoModeHandle { pub fn size(&self) -> PhysicalSize { self.size.into() } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index d4d5a77f39..54ca1342f6 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -72,7 +72,7 @@ pub(crate) use self::{ event_loop::{ EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, }, - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}, }; diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index 2621e8b27e..dff73ba506 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -13,7 +13,7 @@ use objc2::Message; use super::uikit::{UIScreen, UIScreenMode}; use crate::{ dpi::{PhysicalPosition, PhysicalSize}, - monitor::VideoMode as RootVideoMode, + monitor::VideoModeHandle as RootVideoModeHandle, platform_impl::platform::app_state, }; @@ -48,7 +48,7 @@ impl PartialEq for MainThreadBoundDelegateImpls { impl Eq for MainThreadBoundDelegateImpls {} #[derive(Debug, PartialEq, Eq, Hash, Clone)] -pub struct VideoMode { +pub struct VideoModeHandle { pub(crate) size: (u32, u32), pub(crate) bit_depth: u16, pub(crate) refresh_rate_millihertz: u32, @@ -56,15 +56,15 @@ pub struct VideoMode { pub(crate) monitor: MonitorHandle, } -impl VideoMode { +impl VideoModeHandle { fn new( uiscreen: Id, screen_mode: Id, mtm: MainThreadMarker, - ) -> VideoMode { + ) -> VideoModeHandle { let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen); let size = screen_mode.size(); - VideoMode { + VideoModeHandle { size: (size.width as u32, size.height as u32), bit_depth: 32, refresh_rate_millihertz, @@ -196,16 +196,16 @@ impl MonitorHandle { ) } - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { MainThreadMarker::run_on_main(|mtm| { let ui_screen = self.ui_screen(mtm); - // Use Ord impl of RootVideoMode + // Use Ord impl of RootVideoModeHandle let modes: BTreeSet<_> = ui_screen .availableModes() .into_iter() - .map(|mode| RootVideoMode { - video_mode: VideoMode::new(ui_screen.clone(), mode, mtm), + .map(|mode| RootVideoModeHandle { + video_mode: VideoModeHandle::new(ui_screen.clone(), mode, mtm), }) .collect(); @@ -217,9 +217,9 @@ impl MonitorHandle { self.ui_screen.get(mtm) } - pub fn preferred_video_mode(&self) -> VideoMode { + pub fn preferred_video_mode(&self) -> VideoModeHandle { MainThreadMarker::run_on_main(|mtm| { - VideoMode::new( + VideoModeHandle::new( self.ui_screen(mtm).clone(), self.ui_screen(mtm).preferredMode().unwrap(), mtm, diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 91aea4d5eb..6a68fab08a 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -254,38 +254,38 @@ impl MonitorHandle { } #[inline] - pub fn video_modes(&self) -> Box> { + pub fn video_modes(&self) -> Box> { x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes())) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum VideoMode { +pub enum VideoModeHandle { #[cfg(x11_platform)] - X(x11::VideoMode), + X(x11::VideoModeHandle), #[cfg(wayland_platform)] - Wayland(wayland::VideoMode), + Wayland(wayland::VideoModeHandle), } -impl VideoMode { +impl VideoModeHandle { #[inline] pub fn size(&self) -> PhysicalSize { - x11_or_wayland!(match self; VideoMode(m) => m.size()) + x11_or_wayland!(match self; VideoModeHandle(m) => m.size()) } #[inline] pub fn bit_depth(&self) -> u16 { - x11_or_wayland!(match self; VideoMode(m) => m.bit_depth()) + x11_or_wayland!(match self; VideoModeHandle(m) => m.bit_depth()) } #[inline] pub fn refresh_rate_millihertz(&self) -> u32 { - x11_or_wayland!(match self; VideoMode(m) => m.refresh_rate_millihertz()) + x11_or_wayland!(match self; VideoModeHandle(m) => m.refresh_rate_millihertz()) } #[inline] pub fn monitor(&self) -> MonitorHandle { - x11_or_wayland!(match self; VideoMode(m) => m.monitor(); as MonitorHandle) + x11_or_wayland!(match self; VideoModeHandle(m) => m.monitor(); as MonitorHandle) } } diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 6d232b0d8a..408ad289f0 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -11,7 +11,7 @@ use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy}; pub use crate::platform_impl::platform::{OsError, WindowId}; pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}; -pub use output::{MonitorHandle, VideoMode}; +pub use output::{MonitorHandle, VideoModeHandle}; pub use window::Window; mod event_loop; diff --git a/src/platform_impl/linux/wayland/output.rs b/src/platform_impl/linux/wayland/output.rs index d6fe61bc78..c54cc2cf11 100644 --- a/src/platform_impl/linux/wayland/output.rs +++ b/src/platform_impl/linux/wayland/output.rs @@ -4,7 +4,7 @@ use sctk::reexports::client::Proxy; use sctk::output::OutputData; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; -use crate::platform_impl::platform::VideoMode as PlatformVideoMode; +use crate::platform_impl::platform::VideoModeHandle as PlatformVideoModeHandle; use super::event_loop::EventLoopWindowTarget; @@ -98,14 +98,14 @@ impl MonitorHandle { } #[inline] - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { let output_data = self.proxy.data::().unwrap(); let modes = output_data.with_output_info(|info| info.modes.clone()); let monitor = self.clone(); modes.into_iter().map(move |mode| { - PlatformVideoMode::Wayland(VideoMode { + PlatformVideoModeHandle::Wayland(VideoModeHandle { size: (mode.dimensions.0 as u32, mode.dimensions.1 as u32).into(), refresh_rate_millihertz: mode.refresh_rate as u32, bit_depth: 32, @@ -142,14 +142,14 @@ impl std::hash::Hash for MonitorHandle { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct VideoMode { +pub struct VideoModeHandle { pub(crate) size: PhysicalSize, pub(crate) bit_depth: u16, pub(crate) refresh_rate_millihertz: u32, pub(crate) monitor: MonitorHandle, } -impl VideoMode { +impl VideoModeHandle { #[inline] pub fn size(&self) -> PhysicalSize { self.size diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index dc1604a81c..0efef5adfd 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -12,7 +12,7 @@ mod window; mod xdisplay; pub(crate) use self::{ - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, window::UnownedWindow, xdisplay::XConnection, }; diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index a44e5458cb..09e42d6605 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -1,7 +1,7 @@ use super::{util, X11Error, XConnection}; use crate::{ dpi::{PhysicalPosition, PhysicalSize}, - platform_impl::VideoMode as PlatformVideoMode, + platform_impl::VideoModeHandle as PlatformVideoModeHandle, }; use x11rb::{ connection::RequestConnection, @@ -22,7 +22,7 @@ impl XConnection { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct VideoMode { +pub struct VideoModeHandle { pub(crate) size: (u32, u32), pub(crate) bit_depth: u16, pub(crate) refresh_rate_millihertz: u32, @@ -30,7 +30,7 @@ pub struct VideoMode { pub(crate) monitor: Option, } -impl VideoMode { +impl VideoModeHandle { #[inline] pub fn size(&self) -> PhysicalSize { self.size.into() @@ -71,7 +71,7 @@ pub struct MonitorHandle { /// Used to determine which windows are on this monitor pub(crate) rect: util::AaRect, /// Supported video modes on this monitor - video_modes: Vec, + video_modes: Vec, } impl PartialEq for MonitorHandle { @@ -191,11 +191,11 @@ impl MonitorHandle { } #[inline] - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { let monitor = self.clone(); self.video_modes.clone().into_iter().map(move |mut x| { x.monitor = Some(monitor.clone()); - PlatformVideoMode::X(x) + PlatformVideoModeHandle::X(x) }) } } diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index 52ec1f2a00..cee617dd52 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -2,7 +2,7 @@ use std::{env, str, str::FromStr}; use super::*; use crate::platform_impl::platform::x11::monitor; -use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoMode}; +use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoModeHandle}; use log::warn; use x11rb::protocol::randr::{self, ConnectionExt as _}; @@ -46,7 +46,7 @@ impl XConnection { &self, resources: &monitor::ScreenResources, crtc: &randr::GetCrtcInfoReply, - ) -> Option<(String, f64, Vec)> { + ) -> Option<(String, f64, Vec)> { let output_info = match self .xcb_connection() .randr_get_output_info(crtc.outputs[0], x11rb::CURRENT_TIME) @@ -70,7 +70,7 @@ impl XConnection { // modes in the array in XRRScreenResources .filter(|x| output_modes.iter().any(|id| x.id == *id)) .map(|mode| { - VideoMode { + VideoModeHandle { size: (mode.width.into(), mode.height.into()), refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode) .unwrap_or(0), diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 7be7f7c468..11c18d0986 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -32,7 +32,7 @@ use crate::{ X11Error, }, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon, - PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode, + PlatformSpecificWindowBuilderAttributes, VideoModeHandle as PlatformVideoModeHandle, }, window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, @@ -754,10 +754,10 @@ impl UnownedWindow { // fullscreen, so we can restore it upon exit, as XRandR does not // provide a mechanism to set this per app-session or restore this // to the desktop video mode as macOS and Windows do - (&None, &Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode)))) + (&None, &Some(Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode)))) | ( &Some(Fullscreen::Borderless(_)), - &Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))), + &Some(Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode))), ) => { let monitor = video_mode.monitor.as_ref().unwrap(); shared_state_lock.desktop_video_mode = Some(( @@ -793,7 +793,7 @@ impl UnownedWindow { } Some(fullscreen) => { let (video_mode, monitor) = match fullscreen { - Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode)) => { + Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode)) => { (Some(video_mode), video_mode.monitor.clone().unwrap()) } Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => { diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index 04aae45c69..8dbc981e56 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -22,7 +22,7 @@ pub(crate) use self::{ event_loop::{ EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, }, - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, window::{PlatformSpecificWindowBuilderAttributes, WindowId}, }; use crate::event::DeviceId as RootDeviceId; diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index c184f7ad3c..17972c9d96 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -18,7 +18,7 @@ use super::ffi; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; #[derive(Clone)] -pub struct VideoMode { +pub struct VideoModeHandle { size: PhysicalSize, bit_depth: u16, refresh_rate_millihertz: u32, @@ -26,7 +26,7 @@ pub struct VideoMode { pub(crate) native_mode: NativeDisplayMode, } -impl PartialEq for VideoMode { +impl PartialEq for VideoModeHandle { fn eq(&self, other: &Self) -> bool { self.size == other.size && self.bit_depth == other.bit_depth @@ -35,9 +35,9 @@ impl PartialEq for VideoMode { } } -impl Eq for VideoMode {} +impl Eq for VideoModeHandle {} -impl std::hash::Hash for VideoMode { +impl std::hash::Hash for VideoModeHandle { fn hash(&self, state: &mut H) { self.size.hash(state); self.bit_depth.hash(state); @@ -46,9 +46,9 @@ impl std::hash::Hash for VideoMode { } } -impl std::fmt::Debug for VideoMode { +impl std::fmt::Debug for VideoModeHandle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("VideoMode") + f.debug_struct("VideoModeHandle") .field("size", &self.size) .field("bit_depth", &self.bit_depth) .field("refresh_rate_millihertz", &self.refresh_rate_millihertz) @@ -79,7 +79,7 @@ impl Clone for NativeDisplayMode { } } -impl VideoMode { +impl VideoModeHandle { pub fn size(&self) -> PhysicalSize { self.size } @@ -239,7 +239,7 @@ impl MonitorHandle { } } - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { let refresh_rate_millihertz = self.refresh_rate_millihertz().unwrap_or(0); let monitor = self.clone(); @@ -283,7 +283,7 @@ impl MonitorHandle { unimplemented!() }; - VideoMode { + VideoModeHandle { size: PhysicalSize::new( ffi::CGDisplayModeGetPixelWidth(mode) as u32, ffi::CGDisplayModeGetPixelHeight(mode) as u32, diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index bea85d5970..ab890cafe5 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -18,7 +18,7 @@ use crate::{ app_state::AppState, event_loop::EventLoopWindowTarget, ffi, - monitor::{self, MonitorHandle, VideoMode}, + monitor::{self, MonitorHandle, VideoModeHandle}, view::WinitView, window_delegate::WinitWindowDelegate, Fullscreen, OsError, @@ -294,7 +294,7 @@ impl WinitWindow { let this = autoreleasepool(|_| { let screen = match attrs.fullscreen.clone().map(Into::into) { Some(Fullscreen::Borderless(Some(monitor))) - | Some(Fullscreen::Exclusive(VideoMode { monitor, .. })) => { + | Some(Fullscreen::Exclusive(VideoModeHandle { monitor, .. })) => { monitor.ns_screen(mtm).or_else(|| NSScreen::mainScreen(mtm)) } Some(Fullscreen::Borderless(None)) => NSScreen::mainScreen(mtm), diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index 3b2b261344..c893377706 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -1,4 +1,4 @@ -use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}; +use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoModeHandle as RootVideoModeHandle}; use crate::window::Fullscreen as RootFullscreen; #[cfg(windows_platform)] @@ -25,10 +25,10 @@ mod platform; pub use self::platform::*; -/// Helper for converting between platform-specific and generic VideoMode/MonitorHandle +/// Helper for converting between platform-specific and generic [`VideoModeHandle`]/[`MonitorHandle`] #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) enum Fullscreen { - Exclusive(VideoMode), + Exclusive(VideoModeHandle), Borderless(Option), } @@ -45,7 +45,9 @@ impl From for Fullscreen { impl From for RootFullscreen { fn from(f: Fullscreen) -> Self { match f { - Fullscreen::Exclusive(video_mode) => Self::Exclusive(RootVideoMode { video_mode }), + Fullscreen::Exclusive(video_mode) => { + Self::Exclusive(RootVideoModeHandle { video_mode }) + } Fullscreen::Borderless(Some(inner)) => { Self::Borderless(Some(RootMonitorHandle { inner })) } diff --git a/src/platform_impl/orbital/mod.rs b/src/platform_impl/orbital/mod.rs index e2ad1ce08c..937e9c12b6 100644 --- a/src/platform_impl/orbital/mod.rs +++ b/src/platform_impl/orbital/mod.rs @@ -222,11 +222,11 @@ impl MonitorHandle { None } - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { let size = self.size().into(); // FIXME this is not the real refresh rate // (it is guaranteed to support 32 bit color though) - std::iter::once(VideoMode { + std::iter::once(VideoModeHandle { size, bit_depth: 32, refresh_rate_millihertz: 60000, @@ -236,14 +236,14 @@ impl MonitorHandle { } #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct VideoMode { +pub struct VideoModeHandle { size: (u32, u32), bit_depth: u16, refresh_rate_millihertz: u32, monitor: MonitorHandle, } -impl VideoMode { +impl VideoModeHandle { pub fn size(&self) -> PhysicalSize { self.size.into() } diff --git a/src/platform_impl/web/mod.rs b/src/platform_impl/web/mod.rs index f3c063e218..dc4b2a50a8 100644 --- a/src/platform_impl/web/mod.rs +++ b/src/platform_impl/web/mod.rs @@ -35,7 +35,7 @@ pub use self::error::OsError; pub(crate) use self::event_loop::{ EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, }; -pub use self::monitor::{MonitorHandle, VideoMode}; +pub use self::monitor::{MonitorHandle, VideoModeHandle}; pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}; pub(crate) use self::keyboard::KeyEventExtra; diff --git a/src/platform_impl/web/monitor.rs b/src/platform_impl/web/monitor.rs index 5353e7e624..1870284a89 100644 --- a/src/platform_impl/web/monitor.rs +++ b/src/platform_impl/web/monitor.rs @@ -26,15 +26,15 @@ impl MonitorHandle { unreachable!() } - pub fn video_modes(&self) -> Empty { + pub fn video_modes(&self) -> Empty { unreachable!() } } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct VideoMode; +pub struct VideoModeHandle; -impl VideoMode { +impl VideoModeHandle { pub fn size(&self) -> PhysicalSize { unreachable!(); } diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 13f4ecc6e0..6978f4969b 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -11,7 +11,7 @@ pub(crate) use self::{ EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, }, icon::{SelectedCursor, WinIcon}, - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, window::Window, }; diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 1548bc05e1..3bccc59032 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -17,7 +17,7 @@ use windows_sys::Win32::{ use super::util::decode_wide; use crate::{ dpi::{PhysicalPosition, PhysicalSize}, - monitor::VideoMode as RootVideoMode, + monitor::VideoModeHandle as RootVideoModeHandle, platform_impl::platform::{ dpi::{dpi_to_scale_factor, get_monitor_dpi}, util::has_flag, @@ -26,7 +26,7 @@ use crate::{ }; #[derive(Clone)] -pub struct VideoMode { +pub struct VideoModeHandle { pub(crate) size: (u32, u32), pub(crate) bit_depth: u16, pub(crate) refresh_rate_millihertz: u32, @@ -35,7 +35,7 @@ pub struct VideoMode { pub(crate) native_video_mode: Box, } -impl PartialEq for VideoMode { +impl PartialEq for VideoModeHandle { fn eq(&self, other: &Self) -> bool { self.size == other.size && self.bit_depth == other.bit_depth @@ -44,9 +44,9 @@ impl PartialEq for VideoMode { } } -impl Eq for VideoMode {} +impl Eq for VideoModeHandle {} -impl std::hash::Hash for VideoMode { +impl std::hash::Hash for VideoModeHandle { fn hash(&self, state: &mut H) { self.size.hash(state); self.bit_depth.hash(state); @@ -55,9 +55,9 @@ impl std::hash::Hash for VideoMode { } } -impl std::fmt::Debug for VideoMode { +impl std::fmt::Debug for VideoModeHandle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("VideoMode") + f.debug_struct("VideoModeHandle") .field("size", &self.size) .field("bit_depth", &self.bit_depth) .field("refresh_rate_millihertz", &self.refresh_rate_millihertz) @@ -66,7 +66,7 @@ impl std::fmt::Debug for VideoMode { } } -impl VideoMode { +impl VideoModeHandle { pub fn size(&self) -> PhysicalSize { self.size.into() } @@ -226,12 +226,12 @@ impl MonitorHandle { } #[inline] - pub fn video_modes(&self) -> impl Iterator { + pub fn video_modes(&self) -> impl Iterator { // EnumDisplaySettingsExW can return duplicate values (or some of the // fields are probably changing, but we aren't looking at those fields // anyway), so we're using a BTreeSet deduplicate - let mut modes = BTreeSet::::new(); - let mod_map = |mode: RootVideoMode| mode.video_mode; + let mut modes = BTreeSet::::new(); + let mod_map = |mode: RootVideoModeHandle| mode.video_mode; let monitor_info = match get_monitor_info(self.0) { Ok(monitor_info) => monitor_info, @@ -255,9 +255,9 @@ impl MonitorHandle { DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; assert!(has_flag(mode.dmFields, REQUIRED_FIELDS)); - // Use Ord impl of RootVideoMode - modes.insert(RootVideoMode { - video_mode: VideoMode { + // Use Ord impl of RootVideoModeHandle + modes.insert(RootVideoModeHandle { + video_mode: VideoModeHandle { size: (mode.dmPelsWidth, mode.dmPelsHeight), bit_depth: mode.dmBitsPerPel as u16, refresh_rate_millihertz: mode.dmDisplayFrequency * 1000, diff --git a/src/window.rs b/src/window.rs index adc30e92bc..7257e16b23 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use crate::{ dpi::{PhysicalPosition, PhysicalSize, Position, Size}, error::{ExternalError, NotSupportedError, OsError}, event_loop::EventLoopWindowTarget, - monitor::{MonitorHandle, VideoMode}, + monitor::{MonitorHandle, VideoModeHandle}, platform_impl, }; @@ -1669,7 +1669,7 @@ impl From for CursorIcon { /// Fullscreen modes. #[derive(Clone, Debug, PartialEq, Eq)] pub enum Fullscreen { - Exclusive(VideoMode), + Exclusive(VideoModeHandle), /// Providing `None` to `Borderless` will fullscreen on the current monitor. Borderless(Option),