monitor: refactor MonitorHandle to store dyn object
This also alters `VideoMode` to be a regular object and not reference the `MonitorHandle`, since it's a static data. Given that `VideoMode` set may change during runtime keeping the reference as a some sort of validity may not be idea and propagating errors when changing video mode could be more reliable.
This commit is contained in:
parent
be1baf164c
commit
f1c5afd84e
43 changed files with 726 additions and 826 deletions
|
|
@ -8,7 +8,7 @@ use std::num::NonZeroU16;
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::task::{ready, Context, Poll};
|
||||
|
||||
use dpi::LogicalSize;
|
||||
|
|
@ -28,7 +28,7 @@ use super::main_thread::MainThreadMarker;
|
|||
use super::r#async::{Dispatcher, Notified, Notifier};
|
||||
use super::web_sys::{Engine, EventListenerHandle};
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode};
|
||||
use crate::monitor::{MonitorHandle as CoreMonitorHandle, MonitorHandleProvider, VideoMode};
|
||||
use crate::platform::web::{
|
||||
MonitorPermissionError, Orientation, OrientationData, OrientationLock, OrientationLockError,
|
||||
};
|
||||
|
|
@ -46,30 +46,6 @@ impl MonitorHandle {
|
|||
Self { id, inner: Dispatcher::new(main_thread, inner).0 }
|
||||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f64 {
|
||||
self.inner.queue(|inner| inner.scale_factor())
|
||||
}
|
||||
|
||||
pub fn position(&self) -> Option<PhysicalPosition<i32>> {
|
||||
self.inner.queue(|inner| inner.position())
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.inner.queue(|inner| inner.name())
|
||||
}
|
||||
|
||||
pub fn current_video_mode(&self) -> Option<VideoMode> {
|
||||
Some(VideoMode {
|
||||
size: self.inner.queue(|inner| inner.size()),
|
||||
bit_depth: self.inner.queue(|inner| inner.bit_depth()),
|
||||
refresh_rate_millihertz: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
|
||||
self.current_video_mode().into_iter()
|
||||
}
|
||||
|
||||
pub fn orientation(&self) -> OrientationData {
|
||||
self.inner.queue(|inner| inner.orientation())
|
||||
}
|
||||
|
|
@ -143,6 +119,40 @@ impl MonitorHandle {
|
|||
}
|
||||
}
|
||||
|
||||
impl MonitorHandleProvider for MonitorHandle {
|
||||
fn id(&self) -> u128 {
|
||||
self.native_id() as _
|
||||
}
|
||||
|
||||
fn native_id(&self) -> u64 {
|
||||
self.id.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn scale_factor(&self) -> f64 {
|
||||
self.inner.queue(|inner| inner.scale_factor())
|
||||
}
|
||||
|
||||
fn position(&self) -> Option<PhysicalPosition<i32>> {
|
||||
self.inner.queue(|inner| inner.position())
|
||||
}
|
||||
|
||||
fn name(&self) -> Option<std::borrow::Cow<'_, str>> {
|
||||
self.inner.queue(|inner| inner.name().map(Into::into))
|
||||
}
|
||||
|
||||
fn current_video_mode(&self) -> Option<VideoMode> {
|
||||
Some(VideoMode {
|
||||
size: self.inner.queue(|inner| inner.size()),
|
||||
bit_depth: self.inner.queue(|inner| inner.bit_depth()),
|
||||
refresh_rate_millihertz: None,
|
||||
})
|
||||
}
|
||||
|
||||
fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> {
|
||||
Box::new(self.current_video_mode().into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for MonitorHandle {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
let (name, position, scale_factor, orientation, is_internal, is_detailed) =
|
||||
|
|
@ -192,9 +202,9 @@ impl PartialOrd for MonitorHandle {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<MonitorHandle> for RootMonitorHandle {
|
||||
fn from(inner: MonitorHandle) -> Self {
|
||||
RootMonitorHandle { inner }
|
||||
impl From<MonitorHandle> for CoreMonitorHandle {
|
||||
fn from(monitor: MonitorHandle) -> Self {
|
||||
CoreMonitorHandle(Arc::new(monitor))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue