Rename VideoMode to VideoModeHandle (#3328)

This commit is contained in:
daxpedda
2023-12-26 22:12:33 +01:00
committed by GitHub
parent 34e42ff94d
commit 658f49b014
23 changed files with 111 additions and 104 deletions

View File

@@ -25,6 +25,7 @@ Unreleased` header.
- **Breaking:** Bump MSRV from `1.65` to `1.70`. - **Breaking:** Bump MSRV from `1.65` to `1.70`.
- On Web, add the ability to toggle calling `Event.preventDefault()` on `Window`. - On Web, add the ability to toggle calling `Event.preventDefault()` on `Window`.
- **Breaking:** Remove `WindowAttributes::fullscreen()` and expose as field directly. - **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 # 0.29.6

View File

@@ -10,28 +10,32 @@ use crate::{
platform_impl, platform_impl,
}; };
/// Deprecated! Use `VideoModeHandle` instead.
#[deprecated = "Renamed to `VideoModeHandle`"]
pub type VideoMode = VideoModeHandle;
/// Describes a fullscreen video mode of a monitor. /// Describes a fullscreen video mode of a monitor.
/// ///
/// Can be acquired with [`MonitorHandle::video_modes`]. /// Can be acquired with [`MonitorHandle::video_modes`].
#[derive(Clone, PartialEq, Eq, Hash)] #[derive(Clone, PartialEq, Eq, Hash)]
pub struct VideoMode { pub struct VideoModeHandle {
pub(crate) video_mode: platform_impl::VideoMode, 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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.video_mode.fmt(f) self.video_mode.fmt(f)
} }
} }
impl PartialOrd for VideoMode { impl PartialOrd for VideoModeHandle {
fn partial_cmp(&self, other: &VideoMode) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &VideoModeHandle) -> Option<std::cmp::Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl Ord for VideoMode { impl Ord for VideoModeHandle {
fn cmp(&self, other: &VideoMode) -> std::cmp::Ordering { fn cmp(&self, other: &VideoModeHandle) -> std::cmp::Ordering {
self.monitor().cmp(&other.monitor()).then( self.monitor().cmp(&other.monitor()).then(
self.size() self.size()
.cmp(&other.size()) .cmp(&other.size())
@@ -45,7 +49,7 @@ impl Ord for VideoMode {
} }
} }
impl VideoMode { impl VideoModeHandle {
/// Returns the resolution of this video mode. /// Returns the resolution of this video mode.
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
@@ -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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!( write!(
f, f,
@@ -131,8 +135,8 @@ impl MonitorHandle {
/// Return `Some` if succeed, or `None` if failed, which usually happens when the monitor /// Return `Some` if succeed, or `None` if failed, which usually happens when the monitor
/// the window is on is removed. /// the window is on is removed.
/// ///
/// When using exclusive fullscreen, the refresh rate of the [`VideoMode`] that was used to /// When using exclusive fullscreen, the refresh rate of the [`VideoModeHandle`] that was
/// enter fullscreen should be used instead. /// used to enter fullscreen should be used instead.
#[inline] #[inline]
pub fn refresh_rate_millihertz(&self) -> Option<u32> { pub fn refresh_rate_millihertz(&self) -> Option<u32> {
self.inner.refresh_rate_millihertz() self.inner.refresh_rate_millihertz()
@@ -161,9 +165,9 @@ impl MonitorHandle {
/// ///
/// - **Web:** Always returns an empty iterator /// - **Web:** Always returns an empty iterator
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
self.inner self.inner
.video_modes() .video_modes()
.map(|video_mode| VideoMode { video_mode }) .map(|video_mode| VideoModeHandle { video_mode })
} }
} }

View File

@@ -5,7 +5,7 @@ use objc2::rc::Id;
use crate::{ use crate::{
event_loop::EventLoop, event_loop::EventLoop,
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
window::{Window, WindowBuilder}, window::{Window, WindowBuilder},
}; };
@@ -230,10 +230,10 @@ pub trait MonitorHandleExtIOS {
/// [`UIScreen`]: https://developer.apple.com/documentation/uikit/uiscreen?language=objc /// [`UIScreen`]: https://developer.apple.com/documentation/uikit/uiscreen?language=objc
fn ui_screen(&self) -> *mut c_void; 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). /// 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 { impl MonitorHandleExtIOS for MonitorHandle {
@@ -245,8 +245,8 @@ impl MonitorHandleExtIOS for MonitorHandle {
} }
#[inline] #[inline]
fn preferred_video_mode(&self) -> VideoMode { fn preferred_video_mode(&self) -> VideoModeHandle {
VideoMode { VideoModeHandle {
video_mode: self.inner.preferred_video_mode(), video_mode: self.inner.preferred_video_mode(),
} }
} }

View File

@@ -1090,11 +1090,11 @@ impl MonitorHandle {
None None
} }
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
let size = self.size().into(); let size = self.size().into();
// FIXME this is not the real refresh rate // FIXME this is not the real refresh rate
// (it is guaranteed to support 32 bit color though) // (it is guaranteed to support 32 bit color though)
std::iter::once(VideoMode { std::iter::once(VideoModeHandle {
size, size,
bit_depth: 32, bit_depth: 32,
refresh_rate_millihertz: 60000, refresh_rate_millihertz: 60000,
@@ -1104,14 +1104,14 @@ impl MonitorHandle {
} }
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct VideoMode { pub struct VideoModeHandle {
size: (u32, u32), size: (u32, u32),
bit_depth: u16, bit_depth: u16,
refresh_rate_millihertz: u32, refresh_rate_millihertz: u32,
monitor: MonitorHandle, monitor: MonitorHandle,
} }
impl VideoMode { impl VideoModeHandle {
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size.into() self.size.into()
} }

View File

@@ -72,7 +72,7 @@ pub(crate) use self::{
event_loop::{ event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
}, },
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}, window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
}; };

View File

@@ -13,7 +13,7 @@ use objc2::Message;
use super::uikit::{UIScreen, UIScreenMode}; use super::uikit::{UIScreen, UIScreenMode};
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
monitor::VideoMode as RootVideoMode, monitor::VideoModeHandle as RootVideoModeHandle,
platform_impl::platform::app_state, platform_impl::platform::app_state,
}; };
@@ -48,7 +48,7 @@ impl<T: IsRetainable + Message> PartialEq for MainThreadBoundDelegateImpls<T> {
impl<T: IsRetainable + Message> Eq for MainThreadBoundDelegateImpls<T> {} impl<T: IsRetainable + Message> Eq for MainThreadBoundDelegateImpls<T> {}
#[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct VideoMode { pub struct VideoModeHandle {
pub(crate) size: (u32, u32), pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32, pub(crate) refresh_rate_millihertz: u32,
@@ -56,15 +56,15 @@ pub struct VideoMode {
pub(crate) monitor: MonitorHandle, pub(crate) monitor: MonitorHandle,
} }
impl VideoMode { impl VideoModeHandle {
fn new( fn new(
uiscreen: Id<UIScreen>, uiscreen: Id<UIScreen>,
screen_mode: Id<UIScreenMode>, screen_mode: Id<UIScreenMode>,
mtm: MainThreadMarker, mtm: MainThreadMarker,
) -> VideoMode { ) -> VideoModeHandle {
let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen); let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen);
let size = screen_mode.size(); let size = screen_mode.size();
VideoMode { VideoModeHandle {
size: (size.width as u32, size.height as u32), size: (size.width as u32, size.height as u32),
bit_depth: 32, bit_depth: 32,
refresh_rate_millihertz, refresh_rate_millihertz,
@@ -196,16 +196,16 @@ impl MonitorHandle {
) )
} }
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
MainThreadMarker::run_on_main(|mtm| { MainThreadMarker::run_on_main(|mtm| {
let ui_screen = self.ui_screen(mtm); let ui_screen = self.ui_screen(mtm);
// Use Ord impl of RootVideoMode // Use Ord impl of RootVideoModeHandle
let modes: BTreeSet<_> = ui_screen let modes: BTreeSet<_> = ui_screen
.availableModes() .availableModes()
.into_iter() .into_iter()
.map(|mode| RootVideoMode { .map(|mode| RootVideoModeHandle {
video_mode: VideoMode::new(ui_screen.clone(), mode, mtm), video_mode: VideoModeHandle::new(ui_screen.clone(), mode, mtm),
}) })
.collect(); .collect();
@@ -217,9 +217,9 @@ impl MonitorHandle {
self.ui_screen.get(mtm) self.ui_screen.get(mtm)
} }
pub fn preferred_video_mode(&self) -> VideoMode { pub fn preferred_video_mode(&self) -> VideoModeHandle {
MainThreadMarker::run_on_main(|mtm| { MainThreadMarker::run_on_main(|mtm| {
VideoMode::new( VideoModeHandle::new(
self.ui_screen(mtm).clone(), self.ui_screen(mtm).clone(),
self.ui_screen(mtm).preferredMode().unwrap(), self.ui_screen(mtm).preferredMode().unwrap(),
mtm, mtm,

View File

@@ -254,38 +254,38 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> { pub fn video_modes(&self) -> Box<dyn Iterator<Item = VideoModeHandle>> {
x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes())) x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes()))
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum VideoMode { pub enum VideoModeHandle {
#[cfg(x11_platform)] #[cfg(x11_platform)]
X(x11::VideoMode), X(x11::VideoModeHandle),
#[cfg(wayland_platform)] #[cfg(wayland_platform)]
Wayland(wayland::VideoMode), Wayland(wayland::VideoModeHandle),
} }
impl VideoMode { impl VideoModeHandle {
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
x11_or_wayland!(match self; VideoMode(m) => m.size()) x11_or_wayland!(match self; VideoModeHandle(m) => m.size())
} }
#[inline] #[inline]
pub fn bit_depth(&self) -> u16 { 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] #[inline]
pub fn refresh_rate_millihertz(&self) -> u32 { 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] #[inline]
pub fn monitor(&self) -> MonitorHandle { 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)
} }
} }

View File

@@ -11,7 +11,7 @@ use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy};
pub use crate::platform_impl::platform::{OsError, WindowId}; pub use crate::platform_impl::platform::{OsError, WindowId};
pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget}; pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
pub use output::{MonitorHandle, VideoMode}; pub use output::{MonitorHandle, VideoModeHandle};
pub use window::Window; pub use window::Window;
mod event_loop; mod event_loop;

View File

@@ -4,7 +4,7 @@ use sctk::reexports::client::Proxy;
use sctk::output::OutputData; use sctk::output::OutputData;
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; 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; use super::event_loop::EventLoopWindowTarget;
@@ -98,14 +98,14 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoModeHandle> {
let output_data = self.proxy.data::<OutputData>().unwrap(); let output_data = self.proxy.data::<OutputData>().unwrap();
let modes = output_data.with_output_info(|info| info.modes.clone()); let modes = output_data.with_output_info(|info| info.modes.clone());
let monitor = self.clone(); let monitor = self.clone();
modes.into_iter().map(move |mode| { modes.into_iter().map(move |mode| {
PlatformVideoMode::Wayland(VideoMode { PlatformVideoModeHandle::Wayland(VideoModeHandle {
size: (mode.dimensions.0 as u32, mode.dimensions.1 as u32).into(), size: (mode.dimensions.0 as u32, mode.dimensions.1 as u32).into(),
refresh_rate_millihertz: mode.refresh_rate as u32, refresh_rate_millihertz: mode.refresh_rate as u32,
bit_depth: 32, bit_depth: 32,
@@ -142,14 +142,14 @@ impl std::hash::Hash for MonitorHandle {
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VideoMode { pub struct VideoModeHandle {
pub(crate) size: PhysicalSize<u32>, pub(crate) size: PhysicalSize<u32>,
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32, pub(crate) refresh_rate_millihertz: u32,
pub(crate) monitor: MonitorHandle, pub(crate) monitor: MonitorHandle,
} }
impl VideoMode { impl VideoModeHandle {
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size self.size

View File

@@ -12,7 +12,7 @@ mod window;
mod xdisplay; mod xdisplay;
pub(crate) use self::{ pub(crate) use self::{
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
window::UnownedWindow, window::UnownedWindow,
xdisplay::XConnection, xdisplay::XConnection,
}; };

View File

@@ -1,7 +1,7 @@
use super::{util, X11Error, XConnection}; use super::{util, X11Error, XConnection};
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
platform_impl::VideoMode as PlatformVideoMode, platform_impl::VideoModeHandle as PlatformVideoModeHandle,
}; };
use x11rb::{ use x11rb::{
connection::RequestConnection, connection::RequestConnection,
@@ -22,7 +22,7 @@ impl XConnection {
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VideoMode { pub struct VideoModeHandle {
pub(crate) size: (u32, u32), pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32, pub(crate) refresh_rate_millihertz: u32,
@@ -30,7 +30,7 @@ pub struct VideoMode {
pub(crate) monitor: Option<MonitorHandle>, pub(crate) monitor: Option<MonitorHandle>,
} }
impl VideoMode { impl VideoModeHandle {
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size.into() self.size.into()
@@ -71,7 +71,7 @@ pub struct MonitorHandle {
/// Used to determine which windows are on this monitor /// Used to determine which windows are on this monitor
pub(crate) rect: util::AaRect, pub(crate) rect: util::AaRect,
/// Supported video modes on this monitor /// Supported video modes on this monitor
video_modes: Vec<VideoMode>, video_modes: Vec<VideoModeHandle>,
} }
impl PartialEq for MonitorHandle { impl PartialEq for MonitorHandle {
@@ -191,11 +191,11 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoModeHandle> {
let monitor = self.clone(); let monitor = self.clone();
self.video_modes.clone().into_iter().map(move |mut x| { self.video_modes.clone().into_iter().map(move |mut x| {
x.monitor = Some(monitor.clone()); x.monitor = Some(monitor.clone());
PlatformVideoMode::X(x) PlatformVideoModeHandle::X(x)
}) })
} }
} }

View File

@@ -2,7 +2,7 @@ use std::{env, str, str::FromStr};
use super::*; use super::*;
use crate::platform_impl::platform::x11::monitor; 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 log::warn;
use x11rb::protocol::randr::{self, ConnectionExt as _}; use x11rb::protocol::randr::{self, ConnectionExt as _};
@@ -46,7 +46,7 @@ impl XConnection {
&self, &self,
resources: &monitor::ScreenResources, resources: &monitor::ScreenResources,
crtc: &randr::GetCrtcInfoReply, crtc: &randr::GetCrtcInfoReply,
) -> Option<(String, f64, Vec<VideoMode>)> { ) -> Option<(String, f64, Vec<VideoModeHandle>)> {
let output_info = match self let output_info = match self
.xcb_connection() .xcb_connection()
.randr_get_output_info(crtc.outputs[0], x11rb::CURRENT_TIME) .randr_get_output_info(crtc.outputs[0], x11rb::CURRENT_TIME)
@@ -70,7 +70,7 @@ impl XConnection {
// modes in the array in XRRScreenResources // modes in the array in XRRScreenResources
.filter(|x| output_modes.iter().any(|id| x.id == *id)) .filter(|x| output_modes.iter().any(|id| x.id == *id))
.map(|mode| { .map(|mode| {
VideoMode { VideoModeHandle {
size: (mode.width.into(), mode.height.into()), size: (mode.width.into(), mode.height.into()),
refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode) refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode)
.unwrap_or(0), .unwrap_or(0),

View File

@@ -32,7 +32,7 @@ use crate::{
X11Error, X11Error,
}, },
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode, PlatformSpecificWindowBuilderAttributes, VideoModeHandle as PlatformVideoModeHandle,
}, },
window::{ window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes, CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
@@ -754,10 +754,10 @@ impl UnownedWindow {
// fullscreen, so we can restore it upon exit, as XRandR does not // fullscreen, so we can restore it upon exit, as XRandR does not
// provide a mechanism to set this per app-session or restore this // provide a mechanism to set this per app-session or restore this
// to the desktop video mode as macOS and Windows do // 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::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(); let monitor = video_mode.monitor.as_ref().unwrap();
shared_state_lock.desktop_video_mode = Some(( shared_state_lock.desktop_video_mode = Some((
@@ -793,7 +793,7 @@ impl UnownedWindow {
} }
Some(fullscreen) => { Some(fullscreen) => {
let (video_mode, monitor) = match 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()) (Some(video_mode), video_mode.monitor.clone().unwrap())
} }
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => { Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {

View File

@@ -22,7 +22,7 @@ pub(crate) use self::{
event_loop::{ event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
}, },
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
window::{PlatformSpecificWindowBuilderAttributes, WindowId}, window::{PlatformSpecificWindowBuilderAttributes, WindowId},
}; };
use crate::event::DeviceId as RootDeviceId; use crate::event::DeviceId as RootDeviceId;

View File

@@ -18,7 +18,7 @@ use super::ffi;
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
#[derive(Clone)] #[derive(Clone)]
pub struct VideoMode { pub struct VideoModeHandle {
size: PhysicalSize<u32>, size: PhysicalSize<u32>,
bit_depth: u16, bit_depth: u16,
refresh_rate_millihertz: u32, refresh_rate_millihertz: u32,
@@ -26,7 +26,7 @@ pub struct VideoMode {
pub(crate) native_mode: NativeDisplayMode, pub(crate) native_mode: NativeDisplayMode,
} }
impl PartialEq for VideoMode { impl PartialEq for VideoModeHandle {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.size == other.size self.size == other.size
&& self.bit_depth == other.bit_depth && 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<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state); self.size.hash(state);
self.bit_depth.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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoMode") f.debug_struct("VideoModeHandle")
.field("size", &self.size) .field("size", &self.size)
.field("bit_depth", &self.bit_depth) .field("bit_depth", &self.bit_depth)
.field("refresh_rate_millihertz", &self.refresh_rate_millihertz) .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<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size self.size
} }
@@ -239,7 +239,7 @@ impl MonitorHandle {
} }
} }
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
let refresh_rate_millihertz = self.refresh_rate_millihertz().unwrap_or(0); let refresh_rate_millihertz = self.refresh_rate_millihertz().unwrap_or(0);
let monitor = self.clone(); let monitor = self.clone();
@@ -283,7 +283,7 @@ impl MonitorHandle {
unimplemented!() unimplemented!()
}; };
VideoMode { VideoModeHandle {
size: PhysicalSize::new( size: PhysicalSize::new(
ffi::CGDisplayModeGetPixelWidth(mode) as u32, ffi::CGDisplayModeGetPixelWidth(mode) as u32,
ffi::CGDisplayModeGetPixelHeight(mode) as u32, ffi::CGDisplayModeGetPixelHeight(mode) as u32,

View File

@@ -18,7 +18,7 @@ use crate::{
app_state::AppState, app_state::AppState,
event_loop::EventLoopWindowTarget, event_loop::EventLoopWindowTarget,
ffi, ffi,
monitor::{self, MonitorHandle, VideoMode}, monitor::{self, MonitorHandle, VideoModeHandle},
view::WinitView, view::WinitView,
window_delegate::WinitWindowDelegate, window_delegate::WinitWindowDelegate,
Fullscreen, OsError, Fullscreen, OsError,
@@ -294,7 +294,7 @@ impl WinitWindow {
let this = autoreleasepool(|_| { let this = autoreleasepool(|_| {
let screen = match attrs.fullscreen.clone().map(Into::into) { let screen = match attrs.fullscreen.clone().map(Into::into) {
Some(Fullscreen::Borderless(Some(monitor))) Some(Fullscreen::Borderless(Some(monitor)))
| Some(Fullscreen::Exclusive(VideoMode { monitor, .. })) => { | Some(Fullscreen::Exclusive(VideoModeHandle { monitor, .. })) => {
monitor.ns_screen(mtm).or_else(|| NSScreen::mainScreen(mtm)) monitor.ns_screen(mtm).or_else(|| NSScreen::mainScreen(mtm))
} }
Some(Fullscreen::Borderless(None)) => NSScreen::mainScreen(mtm), Some(Fullscreen::Borderless(None)) => NSScreen::mainScreen(mtm),

View File

@@ -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; use crate::window::Fullscreen as RootFullscreen;
#[cfg(windows_platform)] #[cfg(windows_platform)]
@@ -25,10 +25,10 @@ mod platform;
pub use self::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)] #[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Fullscreen { pub(crate) enum Fullscreen {
Exclusive(VideoMode), Exclusive(VideoModeHandle),
Borderless(Option<MonitorHandle>), Borderless(Option<MonitorHandle>),
} }
@@ -45,7 +45,9 @@ impl From<RootFullscreen> for Fullscreen {
impl From<Fullscreen> for RootFullscreen { impl From<Fullscreen> for RootFullscreen {
fn from(f: Fullscreen) -> Self { fn from(f: Fullscreen) -> Self {
match f { match f {
Fullscreen::Exclusive(video_mode) => Self::Exclusive(RootVideoMode { video_mode }), Fullscreen::Exclusive(video_mode) => {
Self::Exclusive(RootVideoModeHandle { video_mode })
}
Fullscreen::Borderless(Some(inner)) => { Fullscreen::Borderless(Some(inner)) => {
Self::Borderless(Some(RootMonitorHandle { inner })) Self::Borderless(Some(RootMonitorHandle { inner }))
} }

View File

@@ -222,11 +222,11 @@ impl MonitorHandle {
None None
} }
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
let size = self.size().into(); let size = self.size().into();
// FIXME this is not the real refresh rate // FIXME this is not the real refresh rate
// (it is guaranteed to support 32 bit color though) // (it is guaranteed to support 32 bit color though)
std::iter::once(VideoMode { std::iter::once(VideoModeHandle {
size, size,
bit_depth: 32, bit_depth: 32,
refresh_rate_millihertz: 60000, refresh_rate_millihertz: 60000,
@@ -236,14 +236,14 @@ impl MonitorHandle {
} }
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct VideoMode { pub struct VideoModeHandle {
size: (u32, u32), size: (u32, u32),
bit_depth: u16, bit_depth: u16,
refresh_rate_millihertz: u32, refresh_rate_millihertz: u32,
monitor: MonitorHandle, monitor: MonitorHandle,
} }
impl VideoMode { impl VideoModeHandle {
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size.into() self.size.into()
} }

View File

@@ -35,7 +35,7 @@ pub use self::error::OsError;
pub(crate) use self::event_loop::{ pub(crate) use self::event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
}; };
pub use self::monitor::{MonitorHandle, VideoMode}; pub use self::monitor::{MonitorHandle, VideoModeHandle};
pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}; pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId};
pub(crate) use self::keyboard::KeyEventExtra; pub(crate) use self::keyboard::KeyEventExtra;

View File

@@ -26,15 +26,15 @@ impl MonitorHandle {
unreachable!() unreachable!()
} }
pub fn video_modes(&self) -> Empty<VideoMode> { pub fn video_modes(&self) -> Empty<VideoModeHandle> {
unreachable!() unreachable!()
} }
} }
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct VideoMode; pub struct VideoModeHandle;
impl VideoMode { impl VideoModeHandle {
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
unreachable!(); unreachable!();
} }

View File

@@ -11,7 +11,7 @@ pub(crate) use self::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes, EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
}, },
icon::{SelectedCursor, WinIcon}, icon::{SelectedCursor, WinIcon},
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
window::Window, window::Window,
}; };

View File

@@ -17,7 +17,7 @@ use windows_sys::Win32::{
use super::util::decode_wide; use super::util::decode_wide;
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
monitor::VideoMode as RootVideoMode, monitor::VideoModeHandle as RootVideoModeHandle,
platform_impl::platform::{ platform_impl::platform::{
dpi::{dpi_to_scale_factor, get_monitor_dpi}, dpi::{dpi_to_scale_factor, get_monitor_dpi},
util::has_flag, util::has_flag,
@@ -26,7 +26,7 @@ use crate::{
}; };
#[derive(Clone)] #[derive(Clone)]
pub struct VideoMode { pub struct VideoModeHandle {
pub(crate) size: (u32, u32), pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32, pub(crate) refresh_rate_millihertz: u32,
@@ -35,7 +35,7 @@ pub struct VideoMode {
pub(crate) native_video_mode: Box<DEVMODEW>, pub(crate) native_video_mode: Box<DEVMODEW>,
} }
impl PartialEq for VideoMode { impl PartialEq for VideoModeHandle {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.size == other.size self.size == other.size
&& self.bit_depth == other.bit_depth && 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<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state); self.size.hash(state);
self.bit_depth.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 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoMode") f.debug_struct("VideoModeHandle")
.field("size", &self.size) .field("size", &self.size)
.field("bit_depth", &self.bit_depth) .field("bit_depth", &self.bit_depth)
.field("refresh_rate_millihertz", &self.refresh_rate_millihertz) .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<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size.into() self.size.into()
} }
@@ -226,12 +226,12 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
// EnumDisplaySettingsExW can return duplicate values (or some of the // EnumDisplaySettingsExW can return duplicate values (or some of the
// fields are probably changing, but we aren't looking at those fields // fields are probably changing, but we aren't looking at those fields
// anyway), so we're using a BTreeSet deduplicate // anyway), so we're using a BTreeSet deduplicate
let mut modes = BTreeSet::<RootVideoMode>::new(); let mut modes = BTreeSet::<RootVideoModeHandle>::new();
let mod_map = |mode: RootVideoMode| mode.video_mode; let mod_map = |mode: RootVideoModeHandle| mode.video_mode;
let monitor_info = match get_monitor_info(self.0) { let monitor_info = match get_monitor_info(self.0) {
Ok(monitor_info) => monitor_info, Ok(monitor_info) => monitor_info,
@@ -255,9 +255,9 @@ impl MonitorHandle {
DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
assert!(has_flag(mode.dmFields, REQUIRED_FIELDS)); assert!(has_flag(mode.dmFields, REQUIRED_FIELDS));
// Use Ord impl of RootVideoMode // Use Ord impl of RootVideoModeHandle
modes.insert(RootVideoMode { modes.insert(RootVideoModeHandle {
video_mode: VideoMode { video_mode: VideoModeHandle {
size: (mode.dmPelsWidth, mode.dmPelsHeight), size: (mode.dmPelsWidth, mode.dmPelsHeight),
bit_depth: mode.dmBitsPerPel as u16, bit_depth: mode.dmBitsPerPel as u16,
refresh_rate_millihertz: mode.dmDisplayFrequency * 1000, refresh_rate_millihertz: mode.dmDisplayFrequency * 1000,

View File

@@ -5,7 +5,7 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size}, dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError}, error::{ExternalError, NotSupportedError, OsError},
event_loop::EventLoopWindowTarget, event_loop::EventLoopWindowTarget,
monitor::{MonitorHandle, VideoMode}, monitor::{MonitorHandle, VideoModeHandle},
platform_impl, platform_impl,
}; };
@@ -1669,7 +1669,7 @@ impl From<ResizeDirection> for CursorIcon {
/// Fullscreen modes. /// Fullscreen modes.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum Fullscreen { pub enum Fullscreen {
Exclusive(VideoMode), Exclusive(VideoModeHandle),
/// Providing `None` to `Borderless` will fullscreen on the current monitor. /// Providing `None` to `Borderless` will fullscreen on the current monitor.
Borderless(Option<MonitorHandle>), Borderless(Option<MonitorHandle>),