Various Monitor/VideoModeHandle methods now return an Option
`VideoModeHandle::refresh_rate_millihertz()` and `bit_depth()` now return a `Option<NonZero*>`. `MonitorHandle::position()` now returns an `Option`. On Orbital `MonitorHandle::name()` now returns `None` instead of a dummy name.
This commit is contained in:
parent
0ffcfd8a3a
commit
58142680ce
15 changed files with 259 additions and 195 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::{BTreeSet, VecDeque};
|
||||
use std::hash::Hash;
|
||||
use std::num::{NonZeroU16, NonZeroU32};
|
||||
use std::{io, mem, ptr};
|
||||
|
||||
use windows_sys::Win32::Foundation::{BOOL, HWND, LPARAM, POINT, RECT};
|
||||
|
|
@ -20,8 +21,8 @@ use crate::platform_impl::platform::window::Window;
|
|||
#[derive(Clone)]
|
||||
pub struct VideoModeHandle {
|
||||
pub(crate) size: (u32, u32),
|
||||
pub(crate) bit_depth: u16,
|
||||
pub(crate) refresh_rate_millihertz: u32,
|
||||
pub(crate) bit_depth: Option<NonZeroU16>,
|
||||
pub(crate) refresh_rate_millihertz: Option<NonZeroU32>,
|
||||
pub(crate) monitor: MonitorHandle,
|
||||
// DEVMODEW is huge so we box it to avoid blowing up the size of winit::window::Fullscreen
|
||||
pub(crate) native_video_mode: Box<DEVMODEW>,
|
||||
|
|
@ -66,8 +67,8 @@ impl VideoModeHandle {
|
|||
|
||||
VideoModeHandle {
|
||||
size: (mode.dmPelsWidth, mode.dmPelsHeight),
|
||||
bit_depth: mode.dmBitsPerPel as u16,
|
||||
refresh_rate_millihertz: mode.dmDisplayFrequency * 1000,
|
||||
bit_depth: NonZeroU16::new(mode.dmBitsPerPel as u16),
|
||||
refresh_rate_millihertz: NonZeroU32::new(mode.dmDisplayFrequency * 1000),
|
||||
monitor,
|
||||
native_video_mode: Box::new(mode),
|
||||
}
|
||||
|
|
@ -77,12 +78,12 @@ impl VideoModeHandle {
|
|||
self.size.into()
|
||||
}
|
||||
|
||||
pub fn bit_depth(&self) -> u16 {
|
||||
pub fn bit_depth(&self) -> Option<NonZeroU16> {
|
||||
self.bit_depth
|
||||
}
|
||||
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<u32> {
|
||||
Some(self.refresh_rate_millihertz)
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<NonZeroU32> {
|
||||
self.refresh_rate_millihertz
|
||||
}
|
||||
|
||||
pub fn monitor(&self) -> MonitorHandle {
|
||||
|
|
@ -189,13 +190,13 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
pub fn position(&self) -> Option<PhysicalPosition<i32>> {
|
||||
get_monitor_info(self.0)
|
||||
.map(|info| {
|
||||
let rc_monitor = info.monitorInfo.rcMonitor;
|
||||
PhysicalPosition { x: rc_monitor.left, y: rc_monitor.top }
|
||||
})
|
||||
.unwrap_or(PhysicalPosition { x: 0, y: 0 })
|
||||
.ok()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -786,7 +786,7 @@ impl Window {
|
|||
Fullscreen::Borderless(None) => monitor::current_monitor(window),
|
||||
};
|
||||
|
||||
let position: (i32, i32) = monitor.position().into();
|
||||
let position: (i32, i32) = monitor.position().unwrap_or_default().into();
|
||||
let size: (u32, u32) = monitor.size().into();
|
||||
|
||||
unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue