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`.
#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.p.primary_monitor()
self.p
.primary_monitor()
.map(|inner| MonitorHandle { inner })
}
/// Change [`DeviceEvent`] filter mode.

View file

@ -78,7 +78,9 @@ impl VideoMode {
/// a separate set of valid video modes.
#[inline]
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
#[inline]
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]
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,
};
use crate::platform_impl::Fullscreen;
use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error,
event::{self, VirtualKeyCode},
event_loop::{self, ControlFlow},
monitor,
window::{self, CursorGrabMode},
};
@ -636,10 +636,8 @@ pub struct EventLoopWindowTarget<T: 'static> {
}
impl<T: 'static> EventLoopWindowTarget<T> {
pub fn primary_monitor(&self) -> Option<monitor::MonitorHandle> {
Some(monitor::MonitorHandle {
inner: MonitorHandle,
})
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
@ -686,7 +684,7 @@ impl DeviceId {
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct PlatformSpecificWindowBuilderAttributes;
pub struct Window;
pub(crate) struct Window;
impl Window {
pub(crate) fn new<T: 'static>(
@ -702,10 +700,8 @@ impl Window {
WindowId
}
pub fn primary_monitor(&self) -> Option<monitor::MonitorHandle> {
Some(monitor::MonitorHandle {
inner: MonitorHandle,
})
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
@ -714,10 +710,8 @@ impl Window {
v
}
pub fn current_monitor(&self) -> Option<monitor::MonitorHandle> {
Some(monitor::MonitorHandle {
inner: MonitorHandle,
})
pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}
pub fn scale_factor(&self) -> f64 {
@ -785,11 +779,11 @@ impl Window {
false
}
pub fn set_fullscreen(&self, _monitor: Option<window::Fullscreen>) {
pub fn set_fullscreen(&self, _monitor: Option<Fullscreen>) {
warn!("Cannot set fullscreen on Android");
}
pub fn fullscreen(&self) -> Option<window::Fullscreen> {
pub fn fullscreen(&self) -> Option<Fullscreen> {
None
}
@ -907,17 +901,15 @@ impl MonitorHandle {
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();
// FIXME this is not the real refresh rate
// (it is guaranteed to support 32 bit color though)
std::iter::once(monitor::VideoMode {
video_mode: VideoMode {
std::iter::once(VideoMode {
size,
bit_depth: 32,
refresh_rate_millihertz: 60000,
monitor: self.clone(),
},
})
}
}
@ -943,9 +935,7 @@ impl VideoMode {
self.refresh_rate_millihertz
}
pub fn monitor(&self) -> monitor::MonitorHandle {
monitor::MonitorHandle {
inner: self.monitor.clone(),
}
pub fn monitor(&self) -> MonitorHandle {
self.monitor.clone()
}
}

View file

@ -24,7 +24,6 @@ use crate::{
event_loop::{
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
},
monitor::MonitorHandle as RootMonitorHandle,
platform::ios::Idiom,
};
@ -60,11 +59,11 @@ impl<T: 'static> EventLoopWindowTarget<T> {
unsafe { monitor::uiscreens() }
}
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
// guaranteed to be on main thread
let monitor = unsafe { monitor::main_uiscreen() };
Some(RootMonitorHandle { inner: monitor })
Some(monitor)
}
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(self) use crate::platform_impl::Fullscreen;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,13 +15,12 @@ use x11_dl::xlib::TrueColor;
use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError as RootOsError},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
platform_impl::{
x11::{ime::ImeContextCreationError, MonitorHandle as X11MonitorHandle},
MonitorHandle as PlatformMonitorHandle, OsError, PlatformSpecificWindowBuilderAttributes,
VideoMode as PlatformVideoMode,
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
},
window::{CursorGrabMode, CursorIcon, Fullscreen, Icon, UserAttentionType, WindowAttributes},
window::{CursorGrabMode, CursorIcon, Icon, UserAttentionType, WindowAttributes},
};
use super::{
@ -40,9 +39,9 @@ pub struct SharedState {
pub is_decorated: bool,
pub last_monitor: X11MonitorHandle,
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
pub desired_fullscreen: Option<Option<Fullscreen>>,
pub(crate) desired_fullscreen: Option<Option<Fullscreen>>,
// Used to restore position after exiting fullscreen
pub restore_position: Option<(i32, i32)>,
// 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
// provide a mechanism to set this per app-session or restore this
// to the desktop video mode as macOS and Windows do
(
&None,
&Some(Fullscreen::Exclusive(RootVideoMode {
video_mode: PlatformVideoMode::X(ref video_mode),
})),
)
(&None, &Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))))
| (
&Some(Fullscreen::Borderless(_)),
&Some(Fullscreen::Exclusive(RootVideoMode {
video_mode: PlatformVideoMode::X(ref video_mode),
})),
&Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))),
) => {
let monitor = video_mode.monitor.as_ref().unwrap();
shared_state_lock.desktop_video_mode =
@ -679,12 +671,12 @@ impl UnownedWindow {
}
Some(fullscreen) => {
let (video_mode, monitor) = match fullscreen {
Fullscreen::Exclusive(RootVideoMode {
video_mode: PlatformVideoMode::X(ref video_mode),
}) => (Some(video_mode), video_mode.monitor.clone().unwrap()),
Fullscreen::Borderless(Some(RootMonitorHandle {
inner: PlatformMonitorHandle::X(monitor),
})) => (None, monitor),
Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode)) => {
(Some(video_mode), video_mode.monitor.clone().unwrap())
}
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
(None, monitor)
}
Fullscreen::Borderless(None) => (None, self.current_monitor()),
#[cfg(feature = "wayland")]
_ => unreachable!(),
@ -737,7 +729,7 @@ impl UnownedWindow {
}
#[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> {
pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
let shared_state = self.shared_state_lock();
shared_state
@ -747,7 +739,7 @@ impl UnownedWindow {
}
#[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) {
flusher
.sync()

View file

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

View file

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

View file

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

View file

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

View file

@ -17,8 +17,9 @@ use crate::{
event::{EventProxy, EventWrapper},
util,
window::WinitWindow,
Fullscreen,
},
window::{Fullscreen, WindowId},
window::WindowId,
};
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")]
#[path = "windows/mod.rs"]
@ -25,6 +26,37 @@ mod platform;
#[path = "web/mod.rs"]
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(
not(target_os = "ios"),
not(target_os = "windows"),

View file

@ -15,7 +15,6 @@ use crate::event::{
WindowEvent,
};
use crate::event_loop::ControlFlow;
use crate::monitor::MonitorHandle as RootMH;
use crate::window::{Theme, WindowId as RootWindowId};
pub struct EventLoopWindowTarget<T: 'static> {
@ -283,10 +282,8 @@ impl<T> EventLoopWindowTarget<T> {
VecDeque::new().into_iter()
}
pub fn primary_monitor(&self) -> Option<RootMH> {
Some(RootMH {
inner: MonitorHandle,
})
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}
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(crate) use crate::icon::NoIcon as PlatformIcon;
pub(self) use crate::platform_impl::Fullscreen;
#[derive(Clone, Copy)]
pub(crate) struct ScaleChangeArgs {

View file

@ -1,5 +1,4 @@
use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
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()
}
}
@ -49,9 +48,7 @@ impl VideoMode {
32000
}
pub fn monitor(&self) -> RootMonitorHandle {
RootMonitorHandle {
inner: MonitorHandle,
}
pub fn monitor(&self) -> MonitorHandle {
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::event;
use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMH;
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 super::{backend, monitor::MonitorHandle, EventLoopWindowTarget};
use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget, Fullscreen};
use std::cell::{Ref, RefCell};
use std::collections::vec_deque::IntoIter as VecDequeIter;
@ -281,7 +280,7 @@ impl Window {
}
#[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> {
pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
if self.canvas.borrow().is_fullscreen() {
Some(Fullscreen::Borderless(Some(self.current_monitor_inner())))
} else {
@ -290,8 +289,8 @@ impl Window {
}
#[inline]
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
if monitor.is_some() {
pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
if fullscreen.is_some() {
self.canvas.borrow().request_fullscreen();
} else if self.canvas.borrow().is_fullscreen() {
backend::exit_fullscreen();
@ -339,14 +338,12 @@ impl Window {
#[inline]
// Allow directly accessing the current monitor internally without unwrapping.
fn current_monitor_inner(&self) -> RootMH {
RootMH {
inner: MonitorHandle,
}
fn current_monitor_inner(&self) -> MonitorHandle {
MonitorHandle
}
#[inline]
pub fn current_monitor(&self) -> Option<RootMH> {
pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(self.current_monitor_inner())
}
@ -356,10 +353,8 @@ impl Window {
}
#[inline]
pub fn primary_monitor(&self) -> Option<RootMH> {
Some(RootMH {
inner: MonitorHandle,
})
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
}
#[inline]

View file

@ -79,7 +79,6 @@ use crate::{
event_loop::{
ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW,
},
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{
dark_mode::try_theme,
dpi::{become_dpi_aware, dpi_to_scale_factor},
@ -90,9 +89,9 @@ use crate::{
raw_input, util,
window::InitData,
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};
@ -322,9 +321,9 @@ impl<T> EventLoopWindowTarget<T> {
monitor::available_monitors()
}
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = monitor::primary_monitor();
Some(RootMonitorHandle { inner: monitor })
Some(monitor)
}
pub fn raw_display_handle(&self) -> RawDisplayHandle {
@ -1111,7 +1110,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
if new_monitor != 0
&& fullscreen_monitor
.as_ref()
.map(|monitor| new_monitor != monitor.inner.hmonitor())
.map(|monitor| new_monitor != monitor.hmonitor())
.unwrap_or(true)
{
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.cy = new_monitor_rect.bottom - new_monitor_rect.top;
}
*fullscreen_monitor = Some(crate::monitor::MonitorHandle {
inner: MonitorHandle::new(new_monitor),
});
*fullscreen_monitor = Some(MonitorHandle::new(new_monitor));
}
}
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) {
let old_monitor_rect = old_monitor_info.monitorInfo.rcMonitor;
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(self) use crate::platform_impl::Fullscreen;
use crate::event::DeviceId as RootDeviceId;
use crate::icon::Icon;

View file

@ -17,7 +17,7 @@ use windows_sys::Win32::{
use super::util::decode_wide;
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
monitor::VideoMode as RootVideoMode,
platform_impl::platform::{
dpi::{dpi_to_scale_factor, get_monitor_dpi},
util::has_flag,
@ -79,10 +79,8 @@ impl VideoMode {
self.refresh_rate_millihertz
}
pub fn monitor(&self) -> RootMonitorHandle {
RootMonitorHandle {
inner: self.monitor.clone(),
}
pub fn monitor(&self) -> MonitorHandle {
self.monitor.clone()
}
}
@ -136,9 +134,9 @@ impl Window {
available_monitors()
}
pub fn primary_monitor(&self) -> Option<RootMonitorHandle> {
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
let monitor = primary_monitor();
Some(RootMonitorHandle { inner: monitor })
Some(monitor)
}
}
@ -224,7 +222,7 @@ impl MonitorHandle {
}
#[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
// fields are probably changing, but we aren't looking at those fields
// anyway), so we're using a BTreeSet deduplicate
@ -246,6 +244,7 @@ impl MonitorHandle {
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY) as u32;
assert!(has_flag(mode.dmFields, REQUIRED_FIELDS));
// Use Ord impl of RootVideoMode
modes.insert(RootVideoMode {
video_mode: VideoMode {
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},
error::{ExternalError, NotSupportedError, OsError as RootOsError},
icon::Icon,
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{
dark_mode::try_theme,
definitions::{
@ -66,15 +65,16 @@ use crate::{
event_loop::{self, EventLoopWindowTarget, DESTROY_MSG_ID},
icon::{self, IconType},
ime::ImeContext,
monitor, util,
monitor::{self, MonitorHandle},
util,
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.
pub struct Window {
pub(crate) struct Window {
/// Main handle for the window.
window: WindowWrapper,
@ -463,12 +463,12 @@ impl Window {
match (&old_fullscreen, &fullscreen) {
(_, Some(Fullscreen::Exclusive(video_mode))) => {
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 {
ChangeDisplaySettingsExW(
monitor_info.szDevice.as_ptr(),
&*video_mode.video_mode.native_video_mode,
&*video_mode.native_video_mode,
0,
CDS_FULLSCREEN,
ptr::null(),
@ -549,9 +549,7 @@ impl Window {
let monitor = match &fullscreen {
Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
Fullscreen::Borderless(None) => RootMonitorHandle {
inner: monitor::current_monitor(window.0),
},
Fullscreen::Borderless(None) => monitor::current_monitor(window.0),
};
let position: (i32, i32) = monitor.position().into();
@ -619,10 +617,8 @@ impl Window {
}
#[inline]
pub fn current_monitor(&self) -> Option<RootMonitorHandle> {
Some(RootMonitorHandle {
inner: monitor::current_monitor(self.hwnd()),
})
pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(monitor::current_monitor(self.hwnd()))
}
#[inline]

View file

@ -2,8 +2,8 @@ use crate::{
dpi::{PhysicalPosition, PhysicalSize, Size},
event::ModifiersState,
icon::Icon,
platform_impl::platform::{event_loop, util},
window::{CursorIcon, Fullscreen, Theme, WindowAttributes},
platform_impl::platform::{event_loop, util, Fullscreen},
window::{CursorIcon, Theme, WindowAttributes},
};
use std::io;
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.
pub struct WindowState {
pub(crate) struct WindowState {
pub mouse: MouseProperties,
/// Used by `WM_GETMINMAXINFO`.

View file

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