Simplify internal type construction

This commit is contained in:
Mads Marquart 2022-09-21 10:04:28 +02:00 committed by GitHub
parent 25b129362f
commit fafdedfb7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 242 additions and 285 deletions

View file

@ -312,7 +312,9 @@ impl<T> EventLoopWindowTarget<T> {
/// **Wayland:** Always returns `None`. /// **Wayland:** Always returns `None`.
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.p.primary_monitor() self.p
.primary_monitor()
.map(|inner| MonitorHandle { inner })
} }
/// Change [`DeviceEvent`] filter mode. /// Change [`DeviceEvent`] filter mode.

View file

@ -78,7 +78,9 @@ impl VideoMode {
/// a separate set of valid video modes. /// a separate set of valid video modes.
#[inline] #[inline]
pub fn monitor(&self) -> MonitorHandle { pub fn monitor(&self) -> MonitorHandle {
self.video_mode.monitor() MonitorHandle {
inner: self.video_mode.monitor(),
}
} }
} }
@ -169,6 +171,8 @@ 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 = VideoMode> {
self.inner.video_modes() self.inner
.video_modes()
.map(|video_mode| VideoMode { video_mode })
} }
} }

View file

@ -257,7 +257,9 @@ impl MonitorHandleExtIOS for MonitorHandle {
#[inline] #[inline]
fn preferred_video_mode(&self) -> VideoMode { fn preferred_video_mode(&self) -> VideoMode {
self.inner.preferred_video_mode() VideoMode {
video_mode: self.inner.preferred_video_mode(),
}
} }
} }

View file

@ -18,12 +18,12 @@ use raw_window_handle::{
AndroidDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, AndroidDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
}; };
use crate::platform_impl::Fullscreen;
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size}, dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error, error,
event::{self, VirtualKeyCode}, event::{self, VirtualKeyCode},
event_loop::{self, ControlFlow}, event_loop::{self, ControlFlow},
monitor,
window::{self, CursorGrabMode}, window::{self, CursorGrabMode},
}; };
@ -636,10 +636,8 @@ pub struct EventLoopWindowTarget<T: 'static> {
} }
impl<T: 'static> EventLoopWindowTarget<T> { impl<T: 'static> EventLoopWindowTarget<T> {
pub fn primary_monitor(&self) -> Option<monitor::MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(monitor::MonitorHandle { Some(MonitorHandle)
inner: MonitorHandle,
})
} }
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> { pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
@ -686,7 +684,7 @@ impl DeviceId {
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowBuilderAttributes; pub struct PlatformSpecificWindowBuilderAttributes;
pub struct Window; pub(crate) struct Window;
impl Window { impl Window {
pub(crate) fn new<T: 'static>( pub(crate) fn new<T: 'static>(
@ -702,10 +700,8 @@ impl Window {
WindowId WindowId
} }
pub fn primary_monitor(&self) -> Option<monitor::MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(monitor::MonitorHandle { Some(MonitorHandle)
inner: MonitorHandle,
})
} }
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> { pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
@ -714,10 +710,8 @@ impl Window {
v v
} }
pub fn current_monitor(&self) -> Option<monitor::MonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(monitor::MonitorHandle { Some(MonitorHandle)
inner: MonitorHandle,
})
} }
pub fn scale_factor(&self) -> f64 { pub fn scale_factor(&self) -> f64 {
@ -785,11 +779,11 @@ impl Window {
false false
} }
pub fn set_fullscreen(&self, _monitor: Option<window::Fullscreen>) { pub fn set_fullscreen(&self, _monitor: Option<Fullscreen>) {
warn!("Cannot set fullscreen on Android"); warn!("Cannot set fullscreen on Android");
} }
pub fn fullscreen(&self) -> Option<window::Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
None None
} }
@ -907,17 +901,15 @@ impl MonitorHandle {
None None
} }
pub fn video_modes(&self) -> impl Iterator<Item = monitor::VideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
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(monitor::VideoMode { std::iter::once(VideoMode {
video_mode: VideoMode { size,
size, bit_depth: 32,
bit_depth: 32, refresh_rate_millihertz: 60000,
refresh_rate_millihertz: 60000, monitor: self.clone(),
monitor: self.clone(),
},
}) })
} }
} }
@ -943,9 +935,7 @@ impl VideoMode {
self.refresh_rate_millihertz self.refresh_rate_millihertz
} }
pub fn monitor(&self) -> monitor::MonitorHandle { pub fn monitor(&self) -> MonitorHandle {
monitor::MonitorHandle { self.monitor.clone()
inner: self.monitor.clone(),
}
} }
} }

View file

@ -24,7 +24,6 @@ use crate::{
event_loop::{ event_loop::{
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget, ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
}, },
monitor::MonitorHandle as RootMonitorHandle,
platform::ios::Idiom, platform::ios::Idiom,
}; };
@ -60,11 +59,11 @@ impl<T: 'static> EventLoopWindowTarget<T> {
unsafe { monitor::uiscreens() } unsafe { monitor::uiscreens() }
} }
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
// guaranteed to be on main thread // guaranteed to be on main thread
let monitor = unsafe { monitor::main_uiscreen() }; let monitor = unsafe { monitor::main_uiscreen() };
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
pub fn raw_display_handle(&self) -> RawDisplayHandle { pub fn raw_display_handle(&self) -> RawDisplayHandle {

View file

@ -88,6 +88,7 @@ pub(crate) use self::{
}; };
pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId { pub struct DeviceId {

View file

@ -9,7 +9,7 @@ use objc2::{class, msg_send};
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}, monitor::VideoMode as RootVideoMode,
platform_impl::platform::{ platform_impl::platform::{
app_state, app_state,
ffi::{id, nil, CGFloat, CGRect, CGSize}, ffi::{id, nil, CGFloat, CGRect, CGSize},
@ -87,10 +87,8 @@ impl VideoMode {
self.refresh_rate_millihertz self.refresh_rate_millihertz
} }
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> MonitorHandle {
RootMonitorHandle { self.monitor.clone()
inner: self.monitor.clone(),
}
} }
} }
@ -220,7 +218,7 @@ impl Inner {
Some(refresh_rate_millihertz(self.uiscreen)) Some(refresh_rate_millihertz(self.uiscreen))
} }
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
let mut modes = BTreeSet::new(); let mut modes = BTreeSet::new();
unsafe { unsafe {
let available_modes: id = msg_send![self.uiscreen, availableModes]; let available_modes: id = msg_send![self.uiscreen, availableModes];
@ -228,13 +226,14 @@ impl Inner {
for i in 0..available_mode_count { for i in 0..available_mode_count {
let mode: id = msg_send![available_modes, objectAtIndex: i]; let mode: id = msg_send![available_modes, objectAtIndex: i];
// Use Ord impl of RootVideoMode
modes.insert(RootVideoMode { modes.insert(RootVideoMode {
video_mode: VideoMode::retained_new(self.uiscreen, mode), video_mode: VideoMode::retained_new(self.uiscreen, mode),
}); });
} }
} }
modes.into_iter() modes.into_iter().map(|mode| mode.video_mode)
} }
} }
@ -268,12 +267,10 @@ impl Inner {
self.uiscreen self.uiscreen
} }
pub fn preferred_video_mode(&self) -> RootVideoMode { pub fn preferred_video_mode(&self) -> VideoMode {
unsafe { unsafe {
let mode: id = msg_send![self.uiscreen, preferredMode]; let mode: id = msg_send![self.uiscreen, preferredMode];
RootVideoMode { VideoMode::retained_new(self.uiscreen, mode)
video_mode: VideoMode::retained_new(self.uiscreen, mode),
}
} }
} }
} }

View file

@ -9,7 +9,6 @@ use super::uikit::{UIResponder, UIViewController, UIWindow};
use crate::{ use crate::{
dpi::PhysicalPosition, dpi::PhysicalPosition,
event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent}, event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent},
platform::ios::MonitorHandleExtIOS,
platform_impl::platform::{ platform_impl::platform::{
app_state, app_state,
event_loop::{self, EventProxy, EventWrapper}, event_loop::{self, EventProxy, EventWrapper},
@ -18,9 +17,9 @@ use crate::{
UIRectEdge, UITouchPhase, UITouchType, UIRectEdge, UITouchPhase, UITouchType,
}, },
window::PlatformSpecificWindowBuilderAttributes, window::PlatformSpecificWindowBuilderAttributes,
DeviceId, DeviceId, Fullscreen,
}, },
window::{Fullscreen, WindowAttributes, WindowId as RootWindowId}, window::{WindowAttributes, WindowId as RootWindowId},
}; };
// requires main thread // requires main thread
@ -464,7 +463,7 @@ pub(crate) unsafe fn create_window(
match window_attributes.fullscreen { match window_attributes.fullscreen {
Some(Fullscreen::Exclusive(ref video_mode)) => { Some(Fullscreen::Exclusive(ref video_mode)) => {
let uiscreen = video_mode.monitor().ui_screen() as id; let uiscreen = video_mode.monitor().ui_screen() as id;
let _: () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode.0]; let _: () = msg_send![uiscreen, setCurrentMode: video_mode.screen_mode.0];
msg_send![window, setScreen:video_mode.monitor().ui_screen()] msg_send![window, setScreen:video_mode.monitor().ui_screen()]
} }
Some(Fullscreen::Borderless(ref monitor)) => { Some(Fullscreen::Borderless(ref monitor)) => {

View file

@ -12,8 +12,7 @@ use crate::{
error::{ExternalError, NotSupportedError, OsError as RootOsError}, error::{ExternalError, NotSupportedError, OsError as RootOsError},
event::{Event, WindowEvent}, event::{Event, WindowEvent},
icon::Icon, icon::Icon,
monitor::MonitorHandle as RootMonitorHandle, platform::ios::{ScreenEdge, ValidOrientations},
platform::ios::{MonitorHandleExtIOS, ScreenEdge, ValidOrientations},
platform_impl::platform::{ platform_impl::platform::{
app_state, app_state,
event_loop::{self, EventProxy, EventWrapper}, event_loop::{self, EventProxy, EventWrapper},
@ -21,11 +20,10 @@ use crate::{
id, CGFloat, CGPoint, CGRect, CGSize, UIEdgeInsets, UIInterfaceOrientationMask, id, CGFloat, CGPoint, CGRect, CGSize, UIEdgeInsets, UIInterfaceOrientationMask,
UIRectEdge, UIScreenOverscanCompensation, UIRectEdge, UIScreenOverscanCompensation,
}, },
monitor, view, EventLoopWindowTarget, MonitorHandle, monitor, view, EventLoopWindowTarget, Fullscreen, MonitorHandle,
}, },
window::{ window::{
CursorGrabMode, CursorIcon, Fullscreen, UserAttentionType, WindowAttributes, CursorGrabMode, CursorIcon, UserAttentionType, WindowAttributes, WindowId as RootWindowId,
WindowId as RootWindowId,
}, },
}; };
@ -217,18 +215,18 @@ impl Inner {
false false
} }
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
unsafe { unsafe {
let uiscreen = match monitor { let uiscreen = match monitor {
Some(Fullscreen::Exclusive(video_mode)) => { Some(Fullscreen::Exclusive(video_mode)) => {
let uiscreen = video_mode.video_mode.monitor.ui_screen() as id; let uiscreen = video_mode.monitor.ui_screen() as id;
let _: () = let _: () = msg_send![uiscreen, setCurrentMode: video_mode.screen_mode.0];
msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode.0];
uiscreen uiscreen
} }
Some(Fullscreen::Borderless(monitor)) => monitor Some(Fullscreen::Borderless(Some(monitor))) => monitor.ui_screen() as id,
.unwrap_or_else(|| self.current_monitor_inner()) Some(Fullscreen::Borderless(None)) => {
.ui_screen() as id, self.current_monitor_inner().ui_screen() as id
}
None => { None => {
warn!("`Window::set_fullscreen(None)` ignored on iOS"); warn!("`Window::set_fullscreen(None)` ignored on iOS");
return; return;
@ -254,10 +252,10 @@ impl Inner {
} }
} }
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
unsafe { unsafe {
let monitor = self.current_monitor_inner(); let monitor = self.current_monitor_inner();
let uiscreen = monitor.inner.ui_screen(); let uiscreen = monitor.ui_screen();
let screen_space_bounds = self.screen_frame(); let screen_space_bounds = self.screen_frame();
let screen_bounds: CGRect = msg_send![uiscreen, bounds]; let screen_bounds: CGRect = msg_send![uiscreen, bounds];
@ -308,16 +306,14 @@ impl Inner {
} }
// Allow directly accessing the current monitor internally without unwrapping. // Allow directly accessing the current monitor internally without unwrapping.
fn current_monitor_inner(&self) -> RootMonitorHandle { fn current_monitor_inner(&self) -> MonitorHandle {
unsafe { unsafe {
let uiscreen: id = msg_send![self.window, screen]; let uiscreen: id = msg_send![self.window, screen];
RootMonitorHandle { MonitorHandle::retained_new(uiscreen)
inner: MonitorHandle::retained_new(uiscreen),
}
} }
} }
pub fn current_monitor(&self) -> Option<RootMonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(self.current_monitor_inner()) Some(self.current_monitor_inner())
} }
@ -325,9 +321,9 @@ impl Inner {
unsafe { monitor::uiscreens() } unsafe { monitor::uiscreens() }
} }
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = unsafe { monitor::main_uiscreen() }; let monitor = unsafe { monitor::main_uiscreen() };
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
pub fn id(&self) -> WindowId { pub fn id(&self) -> WindowId {
@ -395,10 +391,8 @@ impl Window {
unsafe { unsafe {
let screen = match window_attributes.fullscreen { let screen = match window_attributes.fullscreen {
Some(Fullscreen::Exclusive(ref video_mode)) => { Some(Fullscreen::Exclusive(ref video_mode)) => video_mode.monitor.ui_screen() as id,
video_mode.video_mode.monitor.ui_screen() as id Some(Fullscreen::Borderless(Some(ref monitor))) => monitor.ui_screen(),
}
Some(Fullscreen::Borderless(Some(ref monitor))) => monitor.inner.ui_screen(),
Some(Fullscreen::Borderless(None)) | None => { Some(Fullscreen::Borderless(None)) | None => {
monitor::main_uiscreen().ui_screen() as id monitor::main_uiscreen().ui_screen() as id
} }

View file

@ -41,11 +41,11 @@ use crate::{
ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW, ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW,
}, },
icon::Icon, icon::Icon,
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}, window::{CursorGrabMode, CursorIcon, UserAttentionType, WindowAttributes},
window::{CursorGrabMode, CursorIcon, Fullscreen, UserAttentionType, WindowAttributes},
}; };
pub(crate) use crate::icon::RgbaIcon as PlatformIcon; pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
pub mod wayland; pub mod wayland;
@ -268,7 +268,7 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> Box<dyn Iterator<Item = RootVideoMode>> { pub fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> {
x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes())) x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes()))
} }
} }
@ -298,7 +298,7 @@ impl VideoMode {
} }
#[inline] #[inline]
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> MonitorHandle {
x11_or_wayland!(match self; VideoMode(m) => m.monitor()) x11_or_wayland!(match self; VideoMode(m) => m.monitor())
} }
} }
@ -458,12 +458,12 @@ impl Window {
} }
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
x11_or_wayland!(match self; Window(w) => w.fullscreen()) x11_or_wayland!(match self; Window(w) => w.fullscreen())
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
x11_or_wayland!(match self; Window(w) => w.set_fullscreen(monitor)) x11_or_wayland!(match self; Window(w) => w.set_fullscreen(monitor))
} }
@ -531,21 +531,17 @@ impl Window {
} }
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<RootMonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
match self { match self {
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
Window::X(ref window) => { Window::X(ref window) => {
let current_monitor = MonitorHandle::X(window.current_monitor()); let current_monitor = MonitorHandle::X(window.current_monitor());
Some(RootMonitorHandle { Some(current_monitor)
inner: current_monitor,
})
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
Window::Wayland(ref window) => { Window::Wayland(ref window) => {
let current_monitor = MonitorHandle::Wayland(window.current_monitor()?); let current_monitor = MonitorHandle::Wayland(window.current_monitor()?);
Some(RootMonitorHandle { Some(current_monitor)
inner: current_monitor,
})
} }
} }
} }
@ -569,14 +565,12 @@ impl Window {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
match self { match self {
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
Window::X(ref window) => { Window::X(ref window) => {
let primary_monitor = MonitorHandle::X(window.primary_monitor()); let primary_monitor = MonitorHandle::X(window.primary_monitor());
Some(RootMonitorHandle { Some(primary_monitor)
inner: primary_monitor,
})
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
Window::Wayland(ref window) => window.primary_monitor(), Window::Wayland(ref window) => window.primary_monitor(),
@ -813,16 +807,14 @@ impl<T> EventLoopWindowTarget<T> {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
match *self { match *self {
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
EventLoopWindowTarget::Wayland(ref evlp) => evlp.primary_monitor(), EventLoopWindowTarget::Wayland(ref evlp) => evlp.primary_monitor(),
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
EventLoopWindowTarget::X(ref evlp) => { EventLoopWindowTarget::X(ref evlp) => {
let primary_monitor = MonitorHandle::X(evlp.x_connection().primary_monitor()); let primary_monitor = MonitorHandle::X(evlp.x_connection().primary_monitor());
Some(RootMonitorHandle { Some(primary_monitor)
inner: primary_monitor,
})
} }
} }
} }

View file

@ -8,7 +8,6 @@ use sctk::environment::Environment;
use sctk::output::OutputStatusListener; use sctk::output::OutputStatusListener;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
use crate::platform_impl::platform::{ use crate::platform_impl::platform::{
MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode, MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode,
}; };
@ -183,19 +182,19 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> {
let modes = sctk::output::with_output_info(&self.proxy, |info| info.modes.clone()) let modes = sctk::output::with_output_info(&self.proxy, |info| info.modes.clone())
.unwrap_or_default(); .unwrap_or_default();
let monitor = self.clone(); let monitor = self.clone();
modes.into_iter().map(move |mode| RootVideoMode { modes.into_iter().map(move |mode| {
video_mode: PlatformVideoMode::Wayland(VideoMode { PlatformVideoMode::Wayland(VideoMode {
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,
monitor: monitor.clone(), monitor: monitor.clone(),
}), })
}) })
} }
} }
@ -224,10 +223,8 @@ impl VideoMode {
self.refresh_rate_millihertz self.refresh_rate_millihertz
} }
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> PlatformMonitorHandle {
RootMonitorHandle { PlatformMonitorHandle::Wayland(self.monitor.clone())
inner: PlatformMonitorHandle::Wayland(self.monitor.clone()),
}
} }
} }
@ -243,7 +240,7 @@ impl<T> EventLoopWindowTarget<T> {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
// There's no primary monitor on Wayland. // There's no primary monitor on Wayland.
None None
} }

View file

@ -14,14 +14,11 @@ use sctk::window::Decorations;
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
use crate::monitor::MonitorHandle as RootMonitorHandle;
use crate::platform_impl::{ use crate::platform_impl::{
MonitorHandle as PlatformMonitorHandle, OsError, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
PlatformSpecificWindowBuilderAttributes as PlatformAttributes, PlatformSpecificWindowBuilderAttributes as PlatformAttributes,
}; };
use crate::window::{ use crate::window::{CursorGrabMode, CursorIcon, Theme, UserAttentionType, WindowAttributes};
CursorGrabMode, CursorIcon, Fullscreen, Theme, UserAttentionType, WindowAttributes,
};
use super::env::WindowingFeatures; use super::env::WindowingFeatures;
use super::event_loop::WinitState; use super::event_loop::WinitState;
@ -218,12 +215,11 @@ impl Window {
warn!("`Fullscreen::Exclusive` is ignored on Wayland") warn!("`Fullscreen::Exclusive` is ignored on Wayland")
} }
Some(Fullscreen::Borderless(monitor)) => { Some(Fullscreen::Borderless(monitor)) => {
let monitor = let monitor = monitor.and_then(|monitor| match monitor {
monitor.and_then(|RootMonitorHandle { inner: monitor }| match monitor { PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy),
PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy), #[cfg(feature = "x11")]
#[cfg(feature = "x11")] PlatformMonitorHandle::X(_) => None,
PlatformMonitorHandle::X(_) => None, });
});
window.set_fullscreen(monitor.as_ref()); window.set_fullscreen(monitor.as_ref());
} }
@ -469,11 +465,9 @@ impl Window {
} }
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
if self.fullscreen.load(Ordering::Relaxed) { if self.fullscreen.load(Ordering::Relaxed) {
let current_monitor = self.current_monitor().map(|monitor| RootMonitorHandle { let current_monitor = self.current_monitor().map(PlatformMonitorHandle::Wayland);
inner: PlatformMonitorHandle::Wayland(monitor),
});
Some(Fullscreen::Borderless(current_monitor)) Some(Fullscreen::Borderless(current_monitor))
} else { } else {
@ -482,19 +476,18 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
let fullscreen_request = match fullscreen { let fullscreen_request = match fullscreen {
Some(Fullscreen::Exclusive(_)) => { Some(Fullscreen::Exclusive(_)) => {
warn!("`Fullscreen::Exclusive` is ignored on Wayland"); warn!("`Fullscreen::Exclusive` is ignored on Wayland");
return; return;
} }
Some(Fullscreen::Borderless(monitor)) => { Some(Fullscreen::Borderless(monitor)) => {
let monitor = let monitor = monitor.and_then(|monitor| match monitor {
monitor.and_then(|RootMonitorHandle { inner: monitor }| match monitor { PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy),
PlatformMonitorHandle::Wayland(monitor) => Some(monitor.proxy), #[cfg(feature = "x11")]
#[cfg(feature = "x11")] PlatformMonitorHandle::X(_) => None,
PlatformMonitorHandle::X(_) => None, });
});
WindowRequest::Fullscreen(monitor) WindowRequest::Fullscreen(monitor)
} }
@ -603,7 +596,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<PlatformMonitorHandle> {
None None
} }

View file

@ -13,7 +13,6 @@ use super::{
}; };
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
platform_impl::{MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode}, platform_impl::{MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode},
}; };
@ -53,10 +52,8 @@ impl VideoMode {
} }
#[inline] #[inline]
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> PlatformMonitorHandle {
RootMonitorHandle { PlatformMonitorHandle::X(self.monitor.clone().unwrap())
inner: PlatformMonitorHandle::X(self.monitor.clone().unwrap()),
}
} }
} }
@ -199,13 +196,11 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> {
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());
RootVideoMode { PlatformVideoMode::X(x)
video_mode: PlatformVideoMode::X(x),
}
}) })
} }
} }

View file

@ -15,13 +15,12 @@ use x11_dl::xlib::TrueColor;
use crate::{ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size}, dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError as RootOsError}, error::{ExternalError, NotSupportedError, OsError as RootOsError},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
platform_impl::{ platform_impl::{
x11::{ime::ImeContextCreationError, MonitorHandle as X11MonitorHandle}, x11::{ime::ImeContextCreationError, MonitorHandle as X11MonitorHandle},
MonitorHandle as PlatformMonitorHandle, OsError, PlatformSpecificWindowBuilderAttributes, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
VideoMode as PlatformVideoMode, PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
}, },
window::{CursorGrabMode, CursorIcon, Fullscreen, Icon, UserAttentionType, WindowAttributes}, window::{CursorGrabMode, CursorIcon, Icon, UserAttentionType, WindowAttributes},
}; };
use super::{ use super::{
@ -40,9 +39,9 @@ pub struct SharedState {
pub is_decorated: bool, pub is_decorated: bool,
pub last_monitor: X11MonitorHandle, pub last_monitor: X11MonitorHandle,
pub dpi_adjusted: Option<(u32, u32)>, pub dpi_adjusted: Option<(u32, u32)>,
pub fullscreen: Option<Fullscreen>, pub(crate) fullscreen: Option<Fullscreen>,
// Set when application calls `set_fullscreen` when window is not visible // Set when application calls `set_fullscreen` when window is not visible
pub desired_fullscreen: Option<Option<Fullscreen>>, pub(crate) desired_fullscreen: Option<Option<Fullscreen>>,
// Used to restore position after exiting fullscreen // Used to restore position after exiting fullscreen
pub restore_position: Option<(i32, i32)>, pub restore_position: Option<(i32, i32)>,
// Used to restore video mode after exiting fullscreen // Used to restore video mode after exiting fullscreen
@ -638,17 +637,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(RootVideoMode {
video_mode: PlatformVideoMode::X(ref video_mode),
})),
)
| ( | (
&Some(Fullscreen::Borderless(_)), &Some(Fullscreen::Borderless(_)),
&Some(Fullscreen::Exclusive(RootVideoMode { &Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))),
video_mode: PlatformVideoMode::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 = shared_state_lock.desktop_video_mode =
@ -679,12 +671,12 @@ impl UnownedWindow {
} }
Some(fullscreen) => { Some(fullscreen) => {
let (video_mode, monitor) = match fullscreen { let (video_mode, monitor) = match fullscreen {
Fullscreen::Exclusive(RootVideoMode { Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode)) => {
video_mode: PlatformVideoMode::X(ref video_mode), (Some(video_mode), video_mode.monitor.clone().unwrap())
}) => (Some(video_mode), video_mode.monitor.clone().unwrap()), }
Fullscreen::Borderless(Some(RootMonitorHandle { Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
inner: PlatformMonitorHandle::X(monitor), (None, monitor)
})) => (None, monitor), }
Fullscreen::Borderless(None) => (None, self.current_monitor()), Fullscreen::Borderless(None) => (None, self.current_monitor()),
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
_ => unreachable!(), _ => unreachable!(),
@ -737,7 +729,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
let shared_state = self.shared_state_lock(); let shared_state = self.shared_state_lock();
shared_state shared_state
@ -747,7 +739,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
if let Some(flusher) = self.set_fullscreen_inner(fullscreen) { if let Some(flusher) = self.set_fullscreen_inner(fullscreen) {
flusher flusher
.sync() .sync()

View file

@ -25,7 +25,6 @@ use super::appkit::{NSApp, NSApplicationActivationPolicy, NSEvent};
use crate::{ use crate::{
event::Event, event::Event,
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget}, event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget},
monitor::MonitorHandle as RootMonitorHandle,
platform::macos::ActivationPolicy, platform::macos::ActivationPolicy,
platform_impl::platform::{ platform_impl::platform::{
app::WinitApplication, app::WinitApplication,
@ -83,9 +82,9 @@ impl<T: 'static> EventLoopWindowTarget<T> {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = monitor::primary_monitor(); let monitor = monitor::primary_monitor();
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
#[inline] #[inline]

View file

@ -34,6 +34,7 @@ use crate::{
use objc2::rc::{autoreleasepool, Id, Shared}; use objc2::rc::{autoreleasepool, Id, Shared};
pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; pub struct DeviceId;

View file

@ -10,10 +10,7 @@ use objc2::rc::{Id, Shared};
use super::appkit::NSScreen; use super::appkit::NSScreen;
use super::ffi; use super::ffi;
use crate::{ use crate::dpi::{PhysicalPosition, PhysicalSize};
dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
};
#[derive(Clone)] #[derive(Clone)]
pub struct VideoMode { pub struct VideoMode {
@ -89,10 +86,8 @@ impl VideoMode {
self.refresh_rate_millihertz self.refresh_rate_millihertz
} }
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> MonitorHandle {
RootMonitorHandle { self.monitor.clone()
inner: self.monitor.clone(),
}
} }
} }
@ -234,7 +229,7 @@ impl MonitorHandle {
} }
} }
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
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();
@ -279,7 +274,7 @@ impl MonitorHandle {
unimplemented!() unimplemented!()
}; };
let video_mode = VideoMode { VideoMode {
size: ( size: (
ffi::CGDisplayModeGetPixelWidth(mode) as u32, ffi::CGDisplayModeGetPixelWidth(mode) as u32,
ffi::CGDisplayModeGetPixelHeight(mode) as u32, ffi::CGDisplayModeGetPixelHeight(mode) as u32,
@ -288,9 +283,7 @@ impl MonitorHandle {
bit_depth, bit_depth,
monitor: monitor.clone(), monitor: monitor.clone(),
native_mode: NativeDisplayMode(mode), native_mode: NativeDisplayMode(mode),
}; }
RootVideoMode { video_mode }
}) })
} }
} }

View file

@ -18,7 +18,6 @@ use crate::{
}, },
error::{ExternalError, NotSupportedError, OsError as RootOsError}, error::{ExternalError, NotSupportedError, OsError as RootOsError},
icon::Icon, icon::Icon,
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
platform::macos::WindowExtMacOS, platform::macos::WindowExtMacOS,
platform_impl::platform::{ platform_impl::platform::{
app_state::AppState, app_state::AppState,
@ -27,11 +26,10 @@ use crate::{
util, util,
view::WinitView, view::WinitView,
window_delegate::WinitWindowDelegate, window_delegate::WinitWindowDelegate,
OsError, Fullscreen, OsError,
}, },
window::{ window::{
CursorGrabMode, CursorIcon, Fullscreen, UserAttentionType, WindowAttributes, CursorGrabMode, CursorIcon, UserAttentionType, WindowAttributes, WindowId as RootWindowId,
WindowId as RootWindowId,
}, },
}; };
use core_graphics::display::{CGDisplay, CGPoint}; use core_graphics::display::{CGDisplay, CGPoint};
@ -133,14 +131,14 @@ pub struct SharedState {
pub resizable: bool, pub resizable: bool,
/// This field tracks the current fullscreen state of the window /// This field tracks the current fullscreen state of the window
/// (as seen by `WindowDelegate`). /// (as seen by `WindowDelegate`).
pub fullscreen: Option<Fullscreen>, pub(crate) fullscreen: Option<Fullscreen>,
// This is true between windowWillEnterFullScreen and windowDidEnterFullScreen // This is true between windowWillEnterFullScreen and windowDidEnterFullScreen
// or windowWillExitFullScreen and windowDidExitFullScreen. // or windowWillExitFullScreen and windowDidExitFullScreen.
// We must not toggle fullscreen when this is true. // We must not toggle fullscreen when this is true.
pub in_fullscreen_transition: bool, pub in_fullscreen_transition: bool,
// If it is attempted to toggle fullscreen when in_fullscreen_transition is true, // If it is attempted to toggle fullscreen when in_fullscreen_transition is true,
// Set target_fullscreen and do after fullscreen transition is end. // Set target_fullscreen and do after fullscreen transition is end.
pub target_fullscreen: Option<Option<Fullscreen>>, pub(crate) target_fullscreen: Option<Option<Fullscreen>>,
pub maximized: bool, pub maximized: bool,
pub standard_frame: Option<NSRect>, pub standard_frame: Option<NSRect>,
is_simple_fullscreen: bool, is_simple_fullscreen: bool,
@ -211,11 +209,11 @@ impl WinitWindow {
} }
let this = autoreleasepool(|_| { let this = autoreleasepool(|_| {
let screen = match attrs.fullscreen { let screen = match &attrs.fullscreen {
Some(Fullscreen::Borderless(Some(RootMonitorHandle { inner: ref monitor }))) Some(Fullscreen::Borderless(Some(monitor)))
| Some(Fullscreen::Exclusive(RootVideoMode { | Some(Fullscreen::Exclusive(VideoMode { monitor, .. })) => {
video_mode: VideoMode { ref monitor, .. }, monitor.ns_screen().or_else(NSScreen::main)
})) => monitor.ns_screen().or_else(NSScreen::main), }
Some(Fullscreen::Borderless(None)) => NSScreen::main(), Some(Fullscreen::Borderless(None)) => NSScreen::main(),
None => None, None => None,
}; };
@ -758,7 +756,7 @@ impl WinitWindow {
} }
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
let shared_state_lock = self.lock_shared_state("fullscreen"); let shared_state_lock = self.lock_shared_state("fullscreen");
shared_state_lock.fullscreen.clone() shared_state_lock.fullscreen.clone()
} }
@ -769,7 +767,7 @@ impl WinitWindow {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
let mut shared_state_lock = self.lock_shared_state("set_fullscreen"); let mut shared_state_lock = self.lock_shared_state("set_fullscreen");
if shared_state_lock.is_simple_fullscreen { if shared_state_lock.is_simple_fullscreen {
return; return;
@ -791,15 +789,9 @@ impl WinitWindow {
// does not take a screen parameter, but uses the current screen) // does not take a screen parameter, but uses the current screen)
if let Some(ref fullscreen) = fullscreen { if let Some(ref fullscreen) = fullscreen {
let new_screen = match fullscreen { let new_screen = match fullscreen {
Fullscreen::Borderless(borderless) => { Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
let RootMonitorHandle { inner: monitor } = borderless Fullscreen::Borderless(None) => self.current_monitor_inner(),
.clone() Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
.unwrap_or_else(|| self.current_monitor_inner());
monitor
}
Fullscreen::Exclusive(RootVideoMode {
video_mode: VideoMode { ref monitor, .. },
}) => monitor.clone(),
} }
.ns_screen() .ns_screen()
.unwrap(); .unwrap();
@ -827,7 +819,7 @@ impl WinitWindow {
// parameter, which is not consistent with the docs saying that it // parameter, which is not consistent with the docs saying that it
// takes a `NSDictionary`.. // takes a `NSDictionary`..
let display_id = video_mode.monitor().inner.native_identifier(); let display_id = video_mode.monitor().native_identifier();
let mut fade_token = ffi::kCGDisplayFadeReservationInvalidToken; let mut fade_token = ffi::kCGDisplayFadeReservationInvalidToken;
@ -861,7 +853,7 @@ impl WinitWindow {
unsafe { unsafe {
let result = ffi::CGDisplaySetDisplayMode( let result = ffi::CGDisplaySetDisplayMode(
display_id, display_id,
video_mode.video_mode.native_mode.0, video_mode.native_mode.0,
std::ptr::null(), std::ptr::null(),
); );
assert!(result == ffi::kCGErrorSuccess, "failed to set video mode"); assert!(result == ffi::kCGErrorSuccess, "failed to set video mode");
@ -903,9 +895,9 @@ impl WinitWindow {
Arc::downgrade(&*self.shared_state), Arc::downgrade(&*self.shared_state),
); );
} }
(&Some(Fullscreen::Exclusive(RootVideoMode { ref video_mode })), &None) => { (&Some(Fullscreen::Exclusive(ref video_mode)), &None) => {
unsafe { unsafe {
util::restore_display_mode_async(video_mode.monitor().inner.native_identifier()) util::restore_display_mode_async(video_mode.monitor().native_identifier())
}; };
// Rest of the state is restored by `window_did_exit_fullscreen` // Rest of the state is restored by `window_did_exit_fullscreen`
util::toggle_full_screen_async( util::toggle_full_screen_async(
@ -937,10 +929,7 @@ impl WinitWindow {
let _: () = msg_send![self, setLevel: ffi::CGShieldingWindowLevel() + 1]; let _: () = msg_send![self, setLevel: ffi::CGShieldingWindowLevel() + 1];
} }
} }
( (&Some(Fullscreen::Exclusive(ref video_mode)), &Some(Fullscreen::Borderless(_))) => {
&Some(Fullscreen::Exclusive(RootVideoMode { ref video_mode })),
&Some(Fullscreen::Borderless(_)),
) => {
let presentation_options = let presentation_options =
shared_state_lock.save_presentation_opts.unwrap_or_else(|| { shared_state_lock.save_presentation_opts.unwrap_or_else(|| {
NSApplicationPresentationOptions::NSApplicationPresentationFullScreen NSApplicationPresentationOptions::NSApplicationPresentationFullScreen
@ -950,7 +939,7 @@ impl WinitWindow {
NSApp().setPresentationOptions(presentation_options); NSApp().setPresentationOptions(presentation_options);
unsafe { unsafe {
util::restore_display_mode_async(video_mode.monitor().inner.native_identifier()) util::restore_display_mode_async(video_mode.monitor().native_identifier())
}; };
// Restore the normal window level following the Borderless fullscreen // Restore the normal window level following the Borderless fullscreen
@ -1064,15 +1053,13 @@ impl WinitWindow {
#[inline] #[inline]
// Allow directly accessing the current monitor internally without unwrapping. // Allow directly accessing the current monitor internally without unwrapping.
pub(crate) fn current_monitor_inner(&self) -> RootMonitorHandle { pub(crate) fn current_monitor_inner(&self) -> MonitorHandle {
let display_id = self.screen().expect("expected screen").display_id(); let display_id = self.screen().expect("expected screen").display_id();
RootMonitorHandle { MonitorHandle::new(display_id)
inner: MonitorHandle::new(display_id),
}
} }
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<RootMonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(self.current_monitor_inner()) Some(self.current_monitor_inner())
} }
@ -1082,9 +1069,9 @@ impl WinitWindow {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = monitor::primary_monitor(); let monitor = monitor::primary_monitor();
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
#[inline] #[inline]

View file

@ -17,8 +17,9 @@ use crate::{
event::{EventProxy, EventWrapper}, event::{EventProxy, EventWrapper},
util, util,
window::WinitWindow, window::WinitWindow,
Fullscreen,
}, },
window::{Fullscreen, WindowId}, window::WindowId,
}; };
declare_class!( declare_class!(

View file

@ -1,4 +1,5 @@
pub use self::platform::*; use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
use crate::window::Fullscreen as RootFullscreen;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
#[path = "windows/mod.rs"] #[path = "windows/mod.rs"]
@ -25,6 +26,37 @@ mod platform;
#[path = "web/mod.rs"] #[path = "web/mod.rs"]
mod platform; mod platform;
pub use self::platform::*;
/// Helper for converting between platform-specific and generic VideoMode/MonitorHandle
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Fullscreen {
Exclusive(VideoMode),
Borderless(Option<MonitorHandle>),
}
impl From<RootFullscreen> for Fullscreen {
fn from(f: RootFullscreen) -> Self {
match f {
RootFullscreen::Exclusive(mode) => Self::Exclusive(mode.video_mode),
RootFullscreen::Borderless(Some(handle)) => Self::Borderless(Some(handle.inner)),
RootFullscreen::Borderless(None) => Self::Borderless(None),
}
}
}
impl From<Fullscreen> for RootFullscreen {
fn from(f: Fullscreen) -> Self {
match f {
Fullscreen::Exclusive(video_mode) => Self::Exclusive(RootVideoMode { video_mode }),
Fullscreen::Borderless(Some(inner)) => {
Self::Borderless(Some(RootMonitorHandle { inner }))
}
Fullscreen::Borderless(None) => Self::Borderless(None),
}
}
}
#[cfg(all( #[cfg(all(
not(target_os = "ios"), not(target_os = "ios"),
not(target_os = "windows"), not(target_os = "windows"),

View file

@ -15,7 +15,6 @@ use crate::event::{
WindowEvent, WindowEvent,
}; };
use crate::event_loop::ControlFlow; use crate::event_loop::ControlFlow;
use crate::monitor::MonitorHandle as RootMH;
use crate::window::{Theme, WindowId as RootWindowId}; use crate::window::{Theme, WindowId as RootWindowId};
pub struct EventLoopWindowTarget<T: 'static> { pub struct EventLoopWindowTarget<T: 'static> {
@ -283,10 +282,8 @@ impl<T> EventLoopWindowTarget<T> {
VecDeque::new().into_iter() VecDeque::new().into_iter()
} }
pub fn primary_monitor(&self) -> Option<RootMH> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(RootMH { Some(MonitorHandle)
inner: MonitorHandle,
})
} }
pub fn raw_display_handle(&self) -> RawDisplayHandle { pub fn raw_display_handle(&self) -> RawDisplayHandle {

View file

@ -35,6 +35,7 @@ pub use self::monitor::{MonitorHandle, VideoMode};
pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}; pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId};
pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub(crate) struct ScaleChangeArgs { pub(crate) struct ScaleChangeArgs {

View file

@ -1,5 +1,4 @@
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MonitorHandle; pub struct MonitorHandle;
@ -28,7 +27,7 @@ impl MonitorHandle {
} }
} }
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
std::iter::empty() std::iter::empty()
} }
} }
@ -49,9 +48,7 @@ impl VideoMode {
32000 32000
} }
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> MonitorHandle {
RootMonitorHandle { MonitorHandle
inner: MonitorHandle,
}
} }
} }

View file

@ -2,14 +2,13 @@ use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOE}; use crate::error::{ExternalError, NotSupportedError, OsError as RootOE};
use crate::event; use crate::event;
use crate::icon::Icon; use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMH;
use crate::window::{ use crate::window::{
CursorGrabMode, CursorIcon, Fullscreen, UserAttentionType, WindowAttributes, WindowId as RootWI, CursorGrabMode, CursorIcon, UserAttentionType, WindowAttributes, WindowId as RootWI,
}; };
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, WebDisplayHandle, WebWindowHandle}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle, WebDisplayHandle, WebWindowHandle};
use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget}; use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget, Fullscreen};
use std::cell::{Ref, RefCell}; use std::cell::{Ref, RefCell};
use std::collections::vec_deque::IntoIter as VecDequeIter; use std::collections::vec_deque::IntoIter as VecDequeIter;
@ -281,7 +280,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
if self.canvas.borrow().is_fullscreen() { if self.canvas.borrow().is_fullscreen() {
Some(Fullscreen::Borderless(Some(self.current_monitor_inner()))) Some(Fullscreen::Borderless(Some(self.current_monitor_inner())))
} else { } else {
@ -290,8 +289,8 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) { pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
if monitor.is_some() { if fullscreen.is_some() {
self.canvas.borrow().request_fullscreen(); self.canvas.borrow().request_fullscreen();
} else if self.canvas.borrow().is_fullscreen() { } else if self.canvas.borrow().is_fullscreen() {
backend::exit_fullscreen(); backend::exit_fullscreen();
@ -339,14 +338,12 @@ impl Window {
#[inline] #[inline]
// Allow directly accessing the current monitor internally without unwrapping. // Allow directly accessing the current monitor internally without unwrapping.
fn current_monitor_inner(&self) -> RootMH { fn current_monitor_inner(&self) -> MonitorHandle {
RootMH { MonitorHandle
inner: MonitorHandle,
}
} }
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<RootMH> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(self.current_monitor_inner()) Some(self.current_monitor_inner())
} }
@ -356,10 +353,8 @@ impl Window {
} }
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<RootMH> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(RootMH { Some(MonitorHandle)
inner: MonitorHandle,
})
} }
#[inline] #[inline]

View file

@ -79,7 +79,6 @@ use crate::{
event_loop::{ event_loop::{
ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW, ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW,
}, },
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{ platform_impl::platform::{
dark_mode::try_theme, dark_mode::try_theme,
dpi::{become_dpi_aware, dpi_to_scale_factor}, dpi::{become_dpi_aware, dpi_to_scale_factor},
@ -90,9 +89,9 @@ use crate::{
raw_input, util, raw_input, util,
window::InitData, window::InitData,
window_state::{CursorFlags, ImeState, WindowFlags, WindowState}, window_state::{CursorFlags, ImeState, WindowFlags, WindowState},
wrap_device_id, WindowId, DEVICE_ID, wrap_device_id, Fullscreen, WindowId, DEVICE_ID,
}, },
window::{Fullscreen, WindowId as RootWindowId}, window::WindowId as RootWindowId,
}; };
use runner::{EventLoopRunner, EventLoopRunnerShared}; use runner::{EventLoopRunner, EventLoopRunnerShared};
@ -322,9 +321,9 @@ impl<T> EventLoopWindowTarget<T> {
monitor::available_monitors() monitor::available_monitors()
} }
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = monitor::primary_monitor(); let monitor = monitor::primary_monitor();
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
pub fn raw_display_handle(&self) -> RawDisplayHandle { pub fn raw_display_handle(&self) -> RawDisplayHandle {
@ -1111,7 +1110,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
if new_monitor != 0 if new_monitor != 0
&& fullscreen_monitor && fullscreen_monitor
.as_ref() .as_ref()
.map(|monitor| new_monitor != monitor.inner.hmonitor()) .map(|monitor| new_monitor != monitor.hmonitor())
.unwrap_or(true) .unwrap_or(true)
{ {
if let Ok(new_monitor_info) = monitor::get_monitor_info(new_monitor) if let Ok(new_monitor_info) = monitor::get_monitor_info(new_monitor)
@ -1122,13 +1121,11 @@ unsafe fn public_window_callback_inner<T: 'static>(
window_pos.cx = new_monitor_rect.right - new_monitor_rect.left; window_pos.cx = new_monitor_rect.right - new_monitor_rect.left;
window_pos.cy = new_monitor_rect.bottom - new_monitor_rect.top; window_pos.cy = new_monitor_rect.bottom - new_monitor_rect.top;
} }
*fullscreen_monitor = Some(crate::monitor::MonitorHandle { *fullscreen_monitor = Some(MonitorHandle::new(new_monitor));
inner: MonitorHandle::new(new_monitor),
});
} }
} }
Fullscreen::Exclusive(ref video_mode) => { Fullscreen::Exclusive(ref video_mode) => {
let old_monitor = video_mode.video_mode.monitor.hmonitor(); let old_monitor = video_mode.monitor.hmonitor();
if let Ok(old_monitor_info) = monitor::get_monitor_info(old_monitor) { if let Ok(old_monitor_info) = monitor::get_monitor_info(old_monitor) {
let old_monitor_rect = old_monitor_info.monitorInfo.rcMonitor; let old_monitor_rect = old_monitor_info.monitorInfo.rcMonitor;
window_pos.x = old_monitor_rect.left; window_pos.x = old_monitor_rect.left;

View file

@ -15,6 +15,7 @@ pub(crate) use self::{
}; };
pub use self::icon::WinIcon as PlatformIcon; pub use self::icon::WinIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
use crate::event::DeviceId as RootDeviceId; use crate::event::DeviceId as RootDeviceId;
use crate::icon::Icon; use crate::icon::Icon;

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::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}, monitor::VideoMode as RootVideoMode,
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,
@ -79,10 +79,8 @@ impl VideoMode {
self.refresh_rate_millihertz self.refresh_rate_millihertz
} }
pub fn monitor(&self) -> RootMonitorHandle { pub fn monitor(&self) -> MonitorHandle {
RootMonitorHandle { self.monitor.clone()
inner: self.monitor.clone(),
}
} }
} }
@ -136,9 +134,9 @@ impl Window {
available_monitors() available_monitors()
} }
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = primary_monitor(); let monitor = primary_monitor();
Some(RootMonitorHandle { inner: monitor }) Some(monitor)
} }
} }
@ -224,7 +222,7 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> { pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
// 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
@ -246,6 +244,7 @@ impl MonitorHandle {
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY) as u32; (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY) as u32;
assert!(has_flag(mode.dmFields, REQUIRED_FIELDS)); assert!(has_flag(mode.dmFields, REQUIRED_FIELDS));
// Use Ord impl of RootVideoMode
modes.insert(RootVideoMode { modes.insert(RootVideoMode {
video_mode: VideoMode { video_mode: VideoMode {
size: (mode.dmPelsWidth, mode.dmPelsHeight), size: (mode.dmPelsWidth, mode.dmPelsHeight),
@ -258,6 +257,6 @@ impl MonitorHandle {
} }
} }
modes.into_iter() modes.into_iter().map(|mode| mode.video_mode)
} }
} }

View file

@ -55,7 +55,6 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size}, dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError as RootOsError}, error::{ExternalError, NotSupportedError, OsError as RootOsError},
icon::Icon, icon::Icon,
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{ platform_impl::platform::{
dark_mode::try_theme, dark_mode::try_theme,
definitions::{ definitions::{
@ -66,15 +65,16 @@ use crate::{
event_loop::{self, EventLoopWindowTarget, DESTROY_MSG_ID}, event_loop::{self, EventLoopWindowTarget, DESTROY_MSG_ID},
icon::{self, IconType}, icon::{self, IconType},
ime::ImeContext, ime::ImeContext,
monitor, util, monitor::{self, MonitorHandle},
util,
window_state::{CursorFlags, SavedWindow, WindowFlags, WindowState}, window_state::{CursorFlags, SavedWindow, WindowFlags, WindowState},
Parent, PlatformSpecificWindowBuilderAttributes, WindowId, Fullscreen, Parent, PlatformSpecificWindowBuilderAttributes, WindowId,
}, },
window::{CursorGrabMode, CursorIcon, Fullscreen, Theme, UserAttentionType, WindowAttributes}, window::{CursorGrabMode, CursorIcon, Theme, UserAttentionType, WindowAttributes},
}; };
/// The Win32 implementation of the main `Window` object. /// The Win32 implementation of the main `Window` object.
pub struct Window { pub(crate) struct Window {
/// Main handle for the window. /// Main handle for the window.
window: WindowWrapper, window: WindowWrapper,
@ -463,12 +463,12 @@ impl Window {
match (&old_fullscreen, &fullscreen) { match (&old_fullscreen, &fullscreen) {
(_, Some(Fullscreen::Exclusive(video_mode))) => { (_, Some(Fullscreen::Exclusive(video_mode))) => {
let monitor = video_mode.monitor(); let monitor = video_mode.monitor();
let monitor_info = monitor::get_monitor_info(monitor.inner.hmonitor()).unwrap(); let monitor_info = monitor::get_monitor_info(monitor.hmonitor()).unwrap();
let res = unsafe { let res = unsafe {
ChangeDisplaySettingsExW( ChangeDisplaySettingsExW(
monitor_info.szDevice.as_ptr(), monitor_info.szDevice.as_ptr(),
&*video_mode.video_mode.native_video_mode, &*video_mode.native_video_mode,
0, 0,
CDS_FULLSCREEN, CDS_FULLSCREEN,
ptr::null(), ptr::null(),
@ -549,9 +549,7 @@ impl Window {
let monitor = match &fullscreen { let monitor = match &fullscreen {
Fullscreen::Exclusive(video_mode) => video_mode.monitor(), Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
Fullscreen::Borderless(Some(monitor)) => monitor.clone(), Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
Fullscreen::Borderless(None) => RootMonitorHandle { Fullscreen::Borderless(None) => monitor::current_monitor(window.0),
inner: monitor::current_monitor(window.0),
},
}; };
let position: (i32, i32) = monitor.position().into(); let position: (i32, i32) = monitor.position().into();
@ -619,10 +617,8 @@ impl Window {
} }
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<RootMonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(RootMonitorHandle { Some(monitor::current_monitor(self.hwnd()))
inner: monitor::current_monitor(self.hwnd()),
})
} }
#[inline] #[inline]

View file

@ -2,8 +2,8 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Size}, dpi::{PhysicalPosition, PhysicalSize, Size},
event::ModifiersState, event::ModifiersState,
icon::Icon, icon::Icon,
platform_impl::platform::{event_loop, util}, platform_impl::platform::{event_loop, util, Fullscreen},
window::{CursorIcon, Fullscreen, Theme, WindowAttributes}, window::{CursorIcon, Theme, WindowAttributes},
}; };
use std::io; use std::io;
use std::sync::MutexGuard; use std::sync::MutexGuard;
@ -24,7 +24,7 @@ use windows_sys::Win32::{
}; };
/// Contains information about states and the window that the callback is going to use. /// Contains information about states and the window that the callback is going to use.
pub struct WindowState { pub(crate) struct WindowState {
pub mouse: MouseProperties, pub mouse: MouseProperties,
/// Used by `WM_GETMINMAXINFO`. /// Used by `WM_GETMINMAXINFO`.

View file

@ -127,7 +127,7 @@ pub(crate) struct WindowAttributes {
pub position: Option<Position>, pub position: Option<Position>,
pub resizable: bool, pub resizable: bool,
pub title: String, pub title: String,
pub fullscreen: Option<Fullscreen>, pub fullscreen: Option<platform_impl::Fullscreen>,
pub maximized: bool, pub maximized: bool,
pub visible: bool, pub visible: bool,
pub transparent: bool, pub transparent: bool,
@ -258,7 +258,7 @@ impl WindowBuilder {
/// See [`Window::set_fullscreen`] for details. /// See [`Window::set_fullscreen`] for details.
#[inline] #[inline]
pub fn with_fullscreen(mut self, fullscreen: Option<Fullscreen>) -> Self { pub fn with_fullscreen(mut self, fullscreen: Option<Fullscreen>) -> Self {
self.window.fullscreen = fullscreen; self.window.fullscreen = fullscreen.map(|f| f.into());
self self
} }
@ -766,7 +766,7 @@ impl Window {
/// - **Android:** Unsupported. /// - **Android:** Unsupported.
#[inline] #[inline]
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) { pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
self.window.set_fullscreen(fullscreen) self.window.set_fullscreen(fullscreen.map(|f| f.into()))
} }
/// Gets the window's current fullscreen state. /// Gets the window's current fullscreen state.
@ -778,7 +778,7 @@ impl Window {
/// - **Wayland:** Can return `Borderless(None)` when there are no monitors. /// - **Wayland:** Can return `Borderless(None)` when there are no monitors.
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
self.window.fullscreen() self.window.fullscreen().map(|f| f.into())
} }
/// Turn window decorations on or off. /// Turn window decorations on or off.
@ -1038,7 +1038,9 @@ impl Window {
/// **iOS:** Can only be called on the main thread. /// **iOS:** Can only be called on the main thread.
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
self.window.current_monitor() self.window
.current_monitor()
.map(|inner| MonitorHandle { inner })
} }
/// Returns the list of all the monitors available on the system. /// Returns the list of all the monitors available on the system.
@ -1072,7 +1074,9 @@ impl Window {
/// [`EventLoopWindowTarget::primary_monitor`]: crate::event_loop::EventLoopWindowTarget::primary_monitor /// [`EventLoopWindowTarget::primary_monitor`]: crate::event_loop::EventLoopWindowTarget::primary_monitor
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.window.primary_monitor() self.window
.primary_monitor()
.map(|inner| MonitorHandle { inner })
} }
} }
unsafe impl HasRawWindowHandle for Window { unsafe impl HasRawWindowHandle for Window {