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:
Kirill Chibisov 2024-09-21 20:27:12 +03:00
parent be1baf164c
commit f1c5afd84e
43 changed files with 726 additions and 826 deletions

View file

@ -2,7 +2,7 @@ use std::cell::Cell;
use std::collections::VecDeque;
use std::sync::{mpsc, Arc, Mutex};
use std::time::Instant;
use std::{mem, slice};
use std::{iter, mem, slice};
use bitflags::bitflags;
use orbclient::{
@ -11,9 +11,7 @@ use orbclient::{
};
use smol_str::SmolStr;
use super::{
MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, WindowProperties,
};
use super::{PlatformSpecificEventLoopAttributes, RedoxSocket, TimeSocket, WindowProperties};
use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, NotSupportedError, RequestError};
use crate::event::{self, Ime, Modifiers, StartCause};
@ -711,9 +709,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
}
fn available_monitors(&self) -> Box<dyn Iterator<Item = crate::monitor::MonitorHandle>> {
let mut v = VecDeque::with_capacity(1);
v.push_back(crate::monitor::MonitorHandle { inner: MonitorHandle });
Box::new(v.into_iter())
Box::new(iter::empty())
}
fn system_theme(&self) -> Option<Theme> {
@ -721,7 +717,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
}
fn primary_monitor(&self) -> Option<crate::monitor::MonitorHandle> {
Some(crate::monitor::MonitorHandle { inner: MonitorHandle })
None
}
fn listen_device_events(&self, _allowed: DeviceEvents) {}

View file

@ -4,8 +4,6 @@ use std::{fmt, str};
pub(crate) use self::event_loop::{ActiveEventLoop, EventLoop};
pub use self::window::Window;
use crate::dpi::PhysicalPosition;
use crate::monitor::VideoMode;
mod event_loop;
mod window;
@ -133,29 +131,3 @@ impl fmt::Display for WindowProperties<'_> {
)
}
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct MonitorHandle;
impl MonitorHandle {
pub fn name(&self) -> Option<String> {
None
}
pub fn position(&self) -> Option<PhysicalPosition<i32>> {
None
}
pub fn scale_factor(&self) -> f64 {
1.0 // TODO
}
pub fn current_video_mode(&self) -> Option<VideoMode> {
// (it is guaranteed to support 32 bit color though)
None
}
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
std::iter::empty()
}
}

View file

@ -1,13 +1,14 @@
use std::collections::VecDeque;
use std::iter;
use std::sync::{Arc, Mutex};
use super::event_loop::EventLoopProxy;
use super::{ActiveEventLoop, MonitorHandle, RedoxSocket, WindowProperties};
use super::{ActiveEventLoop, RedoxSocket, WindowProperties};
use crate::cursor::Cursor;
use crate::dpi::{PhysicalInsets, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{NotSupportedError, RequestError};
use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId};
use crate::monitor::{Fullscreen, MonitorHandle as CoreMonitorHandle};
use crate::window::{self, ImePurpose, Window as CoreWindow, WindowId};
// These values match the values uses in the `window_new` function in orbital:
// https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs
@ -33,7 +34,7 @@ impl Window {
el: &ActiveEventLoop,
attrs: window::WindowAttributes,
) -> Result<Self, RequestError> {
let scale = MonitorHandle.scale_factor();
let scale = 1.;
let (x, y) = if let Some(pos) = attrs.position {
pos.to_physical::<i32>(scale).into()
@ -161,22 +162,22 @@ impl CoreWindow for Window {
#[inline]
fn primary_monitor(&self) -> Option<CoreMonitorHandle> {
Some(CoreMonitorHandle { inner: MonitorHandle })
None
}
#[inline]
fn available_monitors(&self) -> Box<dyn Iterator<Item = CoreMonitorHandle>> {
Box::new(vec![CoreMonitorHandle { inner: MonitorHandle }].into_iter())
Box::new(iter::empty())
}
#[inline]
fn current_monitor(&self) -> Option<CoreMonitorHandle> {
Some(CoreMonitorHandle { inner: MonitorHandle })
None
}
#[inline]
fn scale_factor(&self) -> f64 {
MonitorHandle.scale_factor()
1.
}
#[inline]