winit-core: move monitor handle
This commit is contained in:
parent
3493a20173
commit
3142355417
10 changed files with 43 additions and 32 deletions
|
|
@ -77,6 +77,7 @@ changelog entry.
|
||||||
- Add `CustomCursorSource::Url`, `CustomCursorSource::from_animation`.
|
- Add `CustomCursorSource::Url`, `CustomCursorSource::from_animation`.
|
||||||
- Implement `CustomIconProvider` for `RgbaIcon`.
|
- Implement `CustomIconProvider` for `RgbaIcon`.
|
||||||
- Add `icon` module that exposes winit's icon API.
|
- Add `icon` module that exposes winit's icon API.
|
||||||
|
- `VideoMode::new` to create a `VideoMode`.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ pub mod event;
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod monitor;
|
pub use winit_core::monitor;
|
||||||
mod platform_impl;
|
mod platform_impl;
|
||||||
use winit_core::as_any as utils;
|
use winit_core::as_any as utils;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
|
||||||
|
|
@ -79,14 +79,14 @@ impl VideoModeHandle {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mode = VideoMode {
|
let mode = VideoMode::new(
|
||||||
size: PhysicalSize::new(
|
PhysicalSize::new(
|
||||||
CGDisplayMode::pixel_width(Some(&native_mode.0)) as u32,
|
CGDisplayMode::pixel_width(Some(&native_mode.0)) as u32,
|
||||||
CGDisplayMode::pixel_height(Some(&native_mode.0)) as u32,
|
CGDisplayMode::pixel_height(Some(&native_mode.0)) as u32,
|
||||||
),
|
),
|
||||||
|
NonZeroU16::new(bit_depth),
|
||||||
refresh_rate_millihertz,
|
refresh_rate_millihertz,
|
||||||
bit_depth: NonZeroU16::new(bit_depth),
|
);
|
||||||
};
|
|
||||||
|
|
||||||
VideoModeHandle { mode, monitor: monitor.clone(), native_mode }
|
VideoModeHandle { mode, monitor: monitor.clone(), native_mode }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,11 @@ impl VideoModeHandle {
|
||||||
) -> VideoModeHandle {
|
) -> VideoModeHandle {
|
||||||
let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen);
|
let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen);
|
||||||
let size = screen_mode.size();
|
let size = screen_mode.size();
|
||||||
let mode = VideoMode {
|
let mode = VideoMode::new(
|
||||||
size: (size.width as u32, size.height as u32).into(),
|
(size.width as u32, size.height as u32).into(),
|
||||||
bit_depth: None,
|
None,
|
||||||
refresh_rate_millihertz,
|
refresh_rate_millihertz,
|
||||||
};
|
);
|
||||||
|
|
||||||
VideoModeHandle {
|
VideoModeHandle {
|
||||||
mode,
|
mode,
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,9 @@ impl Eq for MonitorHandle {}
|
||||||
|
|
||||||
/// Convert the wayland's [`Mode`] to winit's [`VideoMode`].
|
/// Convert the wayland's [`Mode`] to winit's [`VideoMode`].
|
||||||
fn wayland_mode_to_core_mode(mode: Mode) -> VideoMode {
|
fn wayland_mode_to_core_mode(mode: Mode) -> VideoMode {
|
||||||
VideoMode {
|
VideoMode::new(
|
||||||
size: (mode.dimensions.0, mode.dimensions.1).into(),
|
(mode.dimensions.0, mode.dimensions.1).into(),
|
||||||
bit_depth: None,
|
None,
|
||||||
refresh_rate_millihertz: NonZeroU32::new(mode.refresh_rate as u32),
|
NonZeroU32::new(mode.refresh_rate as u32),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,11 @@ impl XConnection {
|
||||||
.filter(|x| output_modes.iter().any(|id| x.id == *id))
|
.filter(|x| output_modes.iter().any(|id| x.id == *id))
|
||||||
.map(|mode| VideoModeHandle {
|
.map(|mode| VideoModeHandle {
|
||||||
current: mode.id == current_mode,
|
current: mode.id == current_mode,
|
||||||
mode: VideoMode {
|
mode: VideoMode::new(
|
||||||
size: (mode.width as u32, mode.height as u32).into(),
|
(mode.width as u32, mode.height as u32).into(),
|
||||||
refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode),
|
NonZeroU16::new(bit_depth as u16),
|
||||||
bit_depth: NonZeroU16::new(bit_depth as u16),
|
monitor::mode_refresh_rate_millihertz(mode),
|
||||||
},
|
),
|
||||||
native_mode: mode.id,
|
native_mode: mode.id,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
||||||
|
|
@ -141,11 +141,11 @@ impl MonitorHandleProvider for MonitorHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_video_mode(&self) -> Option<VideoMode> {
|
fn current_video_mode(&self) -> Option<VideoMode> {
|
||||||
Some(VideoMode {
|
Some(VideoMode::new(
|
||||||
size: self.inner.queue(|inner| inner.size()),
|
self.inner.queue(|inner| inner.size()),
|
||||||
bit_depth: self.inner.queue(|inner| inner.bit_depth()),
|
self.inner.queue(|inner| inner.bit_depth()),
|
||||||
refresh_rate_millihertz: None,
|
None,
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> {
|
fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> {
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ impl VideoModeHandle {
|
||||||
DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
|
DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
|
||||||
assert!(has_flag(native_video_mode.dmFields, REQUIRED_FIELDS));
|
assert!(has_flag(native_video_mode.dmFields, REQUIRED_FIELDS));
|
||||||
|
|
||||||
let mode = VideoMode {
|
let mode = VideoMode::new(
|
||||||
size: (native_video_mode.dmPelsWidth, native_video_mode.dmPelsHeight).into(),
|
(native_video_mode.dmPelsWidth, native_video_mode.dmPelsHeight).into(),
|
||||||
bit_depth: NonZeroU16::new(native_video_mode.dmBitsPerPel as u16),
|
NonZeroU16::new(native_video_mode.dmBitsPerPel as u16),
|
||||||
refresh_rate_millihertz: NonZeroU32::new(native_video_mode.dmDisplayFrequency * 1000),
|
NonZeroU32::new(native_video_mode.dmDisplayFrequency * 1000),
|
||||||
};
|
);
|
||||||
|
|
||||||
VideoModeHandle { mode, native_video_mode: Box::new(native_video_mode) }
|
VideoModeHandle { mode, native_video_mode: Box::new(native_video_mode) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod as_any;
|
pub mod as_any;
|
||||||
|
pub mod monitor;
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ use std::num::{NonZeroU16, NonZeroU32};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
use dpi::{PhysicalPosition, PhysicalSize};
|
||||||
use crate::utils::{impl_dyn_casting, AsAny};
|
|
||||||
|
use crate::as_any::{impl_dyn_casting, AsAny};
|
||||||
|
|
||||||
/// Handle to a monitor.
|
/// Handle to a monitor.
|
||||||
///
|
///
|
||||||
|
|
@ -45,7 +46,7 @@ use crate::utils::{impl_dyn_casting, AsAny};
|
||||||
///
|
///
|
||||||
/// [`Window`]: crate::window::Window
|
/// [`Window`]: crate::window::Window
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MonitorHandle(pub(crate) Arc<dyn MonitorHandleProvider>);
|
pub struct MonitorHandle(pub Arc<dyn MonitorHandleProvider>);
|
||||||
|
|
||||||
impl Deref for MonitorHandle {
|
impl Deref for MonitorHandle {
|
||||||
type Target = dyn MonitorHandleProvider;
|
type Target = dyn MonitorHandleProvider;
|
||||||
|
|
@ -161,6 +162,14 @@ pub struct VideoMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VideoMode {
|
impl VideoMode {
|
||||||
|
pub fn new(
|
||||||
|
size: PhysicalSize<u32>,
|
||||||
|
bit_depth: Option<NonZeroU16>,
|
||||||
|
refresh_rate_millihertz: Option<NonZeroU32>,
|
||||||
|
) -> Self {
|
||||||
|
Self { size, bit_depth, refresh_rate_millihertz }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the resolution of this video mode. This **must not** be used to create your
|
/// Returns the resolution of this video mode. This **must not** be used to create your
|
||||||
/// rendering surface. Use [`Window::surface_size()`] instead.
|
/// rendering surface. Use [`Window::surface_size()`] instead.
|
||||||
///
|
///
|
||||||
Loading…
Add table
Add a link
Reference in a new issue