On Web, never return a MonitorHandle (#3051)

This commit is contained in:
daxpedda 2023-08-26 18:56:44 +02:00 committed by GitHub
parent 48abf52aac
commit a3cba838ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 32 deletions

View file

@ -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. - 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, `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 # 0.29.1-beta

View file

@ -355,7 +355,7 @@ impl<T> EventLoopWindowTarget<T> {
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// **Wayland:** Always returns `None`. /// **Wayland / Web:** Always returns `None`.
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.p self.p

View file

@ -108,20 +108,12 @@ impl MonitorHandle {
/// Returns a human-readable name of the monitor. /// Returns a human-readable name of the monitor.
/// ///
/// Returns `None` if the monitor doesn't exist anymore. /// Returns `None` if the monitor doesn't exist anymore.
///
/// ## Platform-specific
///
/// - **Web:** Always returns None
#[inline] #[inline]
pub fn name(&self) -> Option<String> { pub fn name(&self) -> Option<String> {
self.inner.name() self.inner.name()
} }
/// Returns the monitor's resolution. /// Returns the monitor's resolution.
///
/// ## Platform-specific
///
/// - **Web:** Always returns (0,0)
#[inline] #[inline]
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.inner.size() self.inner.size()
@ -129,10 +121,6 @@ impl MonitorHandle {
/// Returns the top-left corner position of the monitor relative to the larger full /// Returns the top-left corner position of the monitor relative to the larger full
/// screen area. /// screen area.
///
/// ## Platform-specific
///
/// - **Web:** Always returns (0,0)
#[inline] #[inline]
pub fn position(&self) -> PhysicalPosition<i32> { pub fn position(&self) -> PhysicalPosition<i32> {
self.inner.position() self.inner.position()
@ -158,7 +146,6 @@ impl MonitorHandle {
/// ///
/// - **X11:** Can be overridden using the `WINIT_X11_SCALE_FACTOR` environment variable. /// - **X11:** Can be overridden using the `WINIT_X11_SCALE_FACTOR` environment variable.
/// - **Android:** Always returns 1.0. /// - **Android:** Always returns 1.0.
/// - **Web:** Always returns 1.0
#[inline] #[inline]
pub fn scale_factor(&self) -> f64 { pub fn scale_factor(&self) -> f64 {
self.inner.scale_factor() self.inner.scale_factor()

View file

@ -746,7 +746,7 @@ impl<T> EventLoopWindowTarget<T> {
} }
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle) None
} }
pub fn raw_display_handle(&self) -> RawDisplayHandle { pub fn raw_display_handle(&self) -> RawDisplayHandle {

View file

@ -1,3 +1,5 @@
use std::iter::Empty;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -5,30 +7,27 @@ pub struct MonitorHandle;
impl MonitorHandle { impl MonitorHandle {
pub fn scale_factor(&self) -> f64 { pub fn scale_factor(&self) -> f64 {
1.0 unreachable!()
} }
pub fn position(&self) -> PhysicalPosition<i32> { pub fn position(&self) -> PhysicalPosition<i32> {
PhysicalPosition { x: 0, y: 0 } unreachable!()
} }
pub fn name(&self) -> Option<String> { pub fn name(&self) -> Option<String> {
None unreachable!()
} }
pub fn refresh_rate_millihertz(&self) -> Option<u32> { pub fn refresh_rate_millihertz(&self) -> Option<u32> {
None unreachable!()
} }
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
PhysicalSize { unreachable!()
width: 0,
height: 0,
}
} }
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> { pub fn video_modes(&self) -> Empty<VideoMode> {
std::iter::empty() unreachable!()
} }
} }
@ -37,18 +36,18 @@ pub struct VideoMode;
impl VideoMode { impl VideoMode {
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
unimplemented!(); unreachable!();
} }
pub fn bit_depth(&self) -> u16 { pub fn bit_depth(&self) -> u16 {
unimplemented!(); unreachable!();
} }
pub fn refresh_rate_millihertz(&self) -> u32 { pub fn refresh_rate_millihertz(&self) -> u32 {
32000 unreachable!();
} }
pub fn monitor(&self) -> MonitorHandle { pub fn monitor(&self) -> MonitorHandle {
MonitorHandle unreachable!();
} }
} }

View file

@ -274,7 +274,7 @@ impl Inner {
#[inline] #[inline]
pub(crate) 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(MonitorHandle))) Some(Fullscreen::Borderless(None))
} else { } else {
None None
} }
@ -335,7 +335,7 @@ impl Inner {
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle) None
} }
#[inline] #[inline]
@ -345,7 +345,7 @@ impl Inner {
#[inline] #[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle) None
} }
#[inline] #[inline]

View file

@ -1050,6 +1050,7 @@ impl Window {
/// - **iOS:** Can only be called on the main thread. /// - **iOS:** Can only be called on the main thread.
/// - **Android / Orbital:** Will always return `None`. /// - **Android / Orbital:** Will always return `None`.
/// - **Wayland:** Can return `Borderless(None)` when there are no monitors. /// - **Wayland:** Can return `Borderless(None)` when there are no monitors.
/// - **Web:** Can only return `None` or `Borderless(None)`.
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
self.window self.window