Skip to content

Commit

Permalink
On Web, never return a MonitorHandle (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Aug 26, 2023
1 parent 48abf52 commit a3cba83
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl<T> EventLoopWindowTarget<T> {
///
/// ## Platform-specific
///
/// **Wayland:** Always returns `None`.
/// **Wayland / Web:** Always returns `None`.
#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
self.p
Expand Down
13 changes: 0 additions & 13 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,19 @@ 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<String> {
self.inner.name()
}

/// Returns the monitor's resolution.
///
/// ## Platform-specific
///
/// - **Web:** Always returns (0,0)
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.inner.size()
}

/// 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<i32> {
self.inner.position()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/event_loop/window_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl<T> EventLoopWindowTarget<T> {
}

pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
None
}

pub fn raw_display_handle(&self) -> RawDisplayHandle {
Expand Down
27 changes: 13 additions & 14 deletions src/platform_impl/web/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
use std::iter::Empty;

use crate::dpi::{PhysicalPosition, PhysicalSize};

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MonitorHandle;

impl MonitorHandle {
pub fn scale_factor(&self) -> f64 {
1.0
unreachable!()
}

pub fn position(&self) -> PhysicalPosition<i32> {
PhysicalPosition { x: 0, y: 0 }
unreachable!()
}

pub fn name(&self) -> Option<String> {
None
unreachable!()
}

pub fn refresh_rate_millihertz(&self) -> Option<u32> {
None
unreachable!()
}

pub fn size(&self) -> PhysicalSize<u32> {
PhysicalSize {
width: 0,
height: 0,
}
unreachable!()
}

pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
std::iter::empty()
pub fn video_modes(&self) -> Empty<VideoMode> {
unreachable!()
}
}

Expand All @@ -37,18 +36,18 @@ pub struct VideoMode;

impl VideoMode {
pub fn size(&self) -> PhysicalSize<u32> {
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!();
}
}
6 changes: 3 additions & 3 deletions src/platform_impl/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl Inner {
#[inline]
pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
if self.canvas.borrow().is_fullscreen() {
Some(Fullscreen::Borderless(Some(MonitorHandle)))
Some(Fullscreen::Borderless(None))
} else {
None
}
Expand Down Expand Up @@ -335,7 +335,7 @@ impl Inner {

#[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
None
}

#[inline]
Expand All @@ -345,7 +345,7 @@ impl Inner {

#[inline]
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle)
None
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fullscreen> {
self.window
Expand Down

0 comments on commit a3cba83

Please sign in to comment.