From a3cba838ea59c4d409176ed4ef06b6065afa3c6e Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 26 Aug 2023 18:56:44 +0200 Subject: [PATCH] On Web, never return a `MonitorHandle` (#3051) --- CHANGELOG.md | 1 + src/event_loop.rs | 2 +- src/monitor.rs | 13 --------- .../web/event_loop/window_target.rs | 2 +- src/platform_impl/web/monitor.rs | 27 +++++++++---------- src/platform_impl/web/window.rs | 6 ++--- src/window.rs | 1 + 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ee8b52..bb638803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ And please only add new entries to the top of this list, right below the `# Unre - Fix window size sometimes being invalid when resizing on macOS. - On Web, `ControlFlow::Poll` and `ControlFlow::WaitUntil` are now using the Prioritized Task Scheduling API. `setTimeout()` with a trick to circumvent throttling to 4ms is used as a fallback. +- On Web, never return a `MonitorHandle`. # 0.29.1-beta diff --git a/src/event_loop.rs b/src/event_loop.rs index b4b10f16..38cc38d8 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -355,7 +355,7 @@ impl EventLoopWindowTarget { /// /// ## Platform-specific /// - /// **Wayland:** Always returns `None`. + /// **Wayland / Web:** Always returns `None`. #[inline] pub fn primary_monitor(&self) -> Option { self.p diff --git a/src/monitor.rs b/src/monitor.rs index 6c0ae39d..47d32809 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -108,20 +108,12 @@ impl MonitorHandle { /// Returns a human-readable name of the monitor. /// /// Returns `None` if the monitor doesn't exist anymore. - /// - /// ## Platform-specific - /// - /// - **Web:** Always returns None #[inline] pub fn name(&self) -> Option { self.inner.name() } /// Returns the monitor's resolution. - /// - /// ## Platform-specific - /// - /// - **Web:** Always returns (0,0) #[inline] pub fn size(&self) -> PhysicalSize { self.inner.size() @@ -129,10 +121,6 @@ impl MonitorHandle { /// Returns the top-left corner position of the monitor relative to the larger full /// screen area. - /// - /// ## Platform-specific - /// - /// - **Web:** Always returns (0,0) #[inline] pub fn position(&self) -> PhysicalPosition { self.inner.position() @@ -158,7 +146,6 @@ impl MonitorHandle { /// /// - **X11:** Can be overridden using the `WINIT_X11_SCALE_FACTOR` environment variable. /// - **Android:** Always returns 1.0. - /// - **Web:** Always returns 1.0 #[inline] pub fn scale_factor(&self) -> f64 { self.inner.scale_factor() diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index f38b4804..7429e98f 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -746,7 +746,7 @@ impl EventLoopWindowTarget { } pub fn primary_monitor(&self) -> Option { - Some(MonitorHandle) + None } pub fn raw_display_handle(&self) -> RawDisplayHandle { diff --git a/src/platform_impl/web/monitor.rs b/src/platform_impl/web/monitor.rs index 6fdbcae2..5353e7e6 100644 --- a/src/platform_impl/web/monitor.rs +++ b/src/platform_impl/web/monitor.rs @@ -1,3 +1,5 @@ +use std::iter::Empty; + use crate::dpi::{PhysicalPosition, PhysicalSize}; #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -5,30 +7,27 @@ pub struct MonitorHandle; impl MonitorHandle { pub fn scale_factor(&self) -> f64 { - 1.0 + unreachable!() } pub fn position(&self) -> PhysicalPosition { - PhysicalPosition { x: 0, y: 0 } + unreachable!() } pub fn name(&self) -> Option { - None + unreachable!() } pub fn refresh_rate_millihertz(&self) -> Option { - None + unreachable!() } pub fn size(&self) -> PhysicalSize { - PhysicalSize { - width: 0, - height: 0, - } + unreachable!() } - pub fn video_modes(&self) -> impl Iterator { - std::iter::empty() + pub fn video_modes(&self) -> Empty { + unreachable!() } } @@ -37,18 +36,18 @@ pub struct VideoMode; impl VideoMode { pub fn size(&self) -> PhysicalSize { - unimplemented!(); + unreachable!(); } pub fn bit_depth(&self) -> u16 { - unimplemented!(); + unreachable!(); } pub fn refresh_rate_millihertz(&self) -> u32 { - 32000 + unreachable!(); } pub fn monitor(&self) -> MonitorHandle { - MonitorHandle + unreachable!(); } } diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index b655d3ed..dc9768ec 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -274,7 +274,7 @@ impl Inner { #[inline] pub(crate) fn fullscreen(&self) -> Option { if self.canvas.borrow().is_fullscreen() { - Some(Fullscreen::Borderless(Some(MonitorHandle))) + Some(Fullscreen::Borderless(None)) } else { None } @@ -335,7 +335,7 @@ impl Inner { #[inline] pub fn current_monitor(&self) -> Option { - Some(MonitorHandle) + None } #[inline] @@ -345,7 +345,7 @@ impl Inner { #[inline] pub fn primary_monitor(&self) -> Option { - Some(MonitorHandle) + None } #[inline] diff --git a/src/window.rs b/src/window.rs index 678a9ebe..dbe41cbe 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1050,6 +1050,7 @@ impl Window { /// - **iOS:** Can only be called on the main thread. /// - **Android / Orbital:** Will always return `None`. /// - **Wayland:** Can return `Borderless(None)` when there are no monitors. + /// - **Web:** Can only return `None` or `Borderless(None)`. #[inline] pub fn fullscreen(&self) -> Option { self.window