Skip to content

Commit

Permalink
Rename VideoMode to VideoModeHandle (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Dec 26, 2023
1 parent 34e42ff commit 658f49b
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 17 additions & 13 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::cmp::Ordering> {
impl PartialOrd for VideoModeHandle {
fn partial_cmp(&self, other: &VideoModeHandle) -> Option<std::cmp::Ordering> {
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())
Expand All @@ -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<u32> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<u32> {
self.inner.refresh_rate_millihertz()
Expand Down Expand Up @@ -161,9 +165,9 @@ impl MonitorHandle {
///
/// - **Web:** Always returns an empty iterator
#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
self.inner
.video_modes()
.map(|video_mode| VideoMode { video_mode })
.map(|video_mode| VideoModeHandle { video_mode })
}
}
10 changes: 5 additions & 5 deletions src/platform/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use objc2::rc::Id;

use crate::{
event_loop::EventLoop,
monitor::{MonitorHandle, VideoMode},
monitor::{MonitorHandle, VideoModeHandle},
window::{Window, WindowBuilder},
};

Expand Down Expand Up @@ -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 {
Expand All @@ -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(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,11 +1090,11 @@ impl MonitorHandle {
None
}

pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
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,
Expand All @@ -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<u32> {
self.size.into()
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) use self::{
event_loop::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
},
monitor::{MonitorHandle, VideoMode},
monitor::{MonitorHandle, VideoModeHandle},
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
};

Expand Down
22 changes: 11 additions & 11 deletions src/platform_impl/ios/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -48,23 +48,23 @@ impl<T: IsRetainable + Message> PartialEq for MainThreadBoundDelegateImpls<T> {
impl<T: IsRetainable + Message> Eq for MainThreadBoundDelegateImpls<T> {}

#[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,
screen_mode: MainThreadBoundDelegateImpls<UIScreenMode>,
pub(crate) monitor: MonitorHandle,
}

impl VideoMode {
impl VideoModeHandle {
fn new(
uiscreen: Id<UIScreen>,
screen_mode: Id<UIScreenMode>,
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,
Expand Down Expand Up @@ -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| {
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();

Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,38 +254,38 @@ impl MonitorHandle {
}

#[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()))
}
}

#[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<u32> {
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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/platform_impl/linux/wayland/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -98,14 +98,14 @@ impl MonitorHandle {
}

#[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 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,
Expand Down Expand Up @@ -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<u32>,
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<u32> {
self.size
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod window;
mod xdisplay;

pub(crate) use self::{
monitor::{MonitorHandle, VideoMode},
monitor::{MonitorHandle, VideoModeHandle},
window::UnownedWindow,
xdisplay::XConnection,
};
Expand Down
12 changes: 6 additions & 6 deletions src/platform_impl/linux/x11/monitor.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,15 +22,15 @@ 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,
pub(crate) native_mode: randr::Mode,
pub(crate) monitor: Option<MonitorHandle>,
}

impl VideoMode {
impl VideoModeHandle {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.size.into()
Expand Down Expand Up @@ -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<VideoMode>,
video_modes: Vec<VideoModeHandle>,
}

impl PartialEq for MonitorHandle {
Expand Down Expand Up @@ -191,11 +191,11 @@ impl MonitorHandle {
}

#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> {
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoModeHandle> {
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)
})
}
}
Expand Down
Loading

0 comments on commit 658f49b

Please sign in to comment.