Rename VideoMode to VideoModeHandle (#3328)

This commit is contained in:
daxpedda 2023-12-26 22:12:33 +01:00 committed by GitHub
parent 34e42ff94d
commit 658f49b014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 111 additions and 104 deletions

View file

@ -254,38 +254,38 @@ impl MonitorHandle {
}
#[inline]
pub fn video_modes(&self) -> Box<dyn Iterator<Item = VideoMode>> {
pub fn video_modes(&self) -> Box<dyn Iterator<Item = VideoModeHandle>> {
x11_or_wayland!(match self; MonitorHandle(m) => Box::new(m.video_modes()))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum VideoMode {
pub enum VideoModeHandle {
#[cfg(x11_platform)]
X(x11::VideoMode),
X(x11::VideoModeHandle),
#[cfg(wayland_platform)]
Wayland(wayland::VideoMode),
Wayland(wayland::VideoModeHandle),
}
impl VideoMode {
impl VideoModeHandle {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
x11_or_wayland!(match self; VideoMode(m) => m.size())
x11_or_wayland!(match self; VideoModeHandle(m) => m.size())
}
#[inline]
pub fn bit_depth(&self) -> u16 {
x11_or_wayland!(match self; VideoMode(m) => m.bit_depth())
x11_or_wayland!(match self; VideoModeHandle(m) => m.bit_depth())
}
#[inline]
pub fn refresh_rate_millihertz(&self) -> u32 {
x11_or_wayland!(match self; VideoMode(m) => m.refresh_rate_millihertz())
x11_or_wayland!(match self; VideoModeHandle(m) => m.refresh_rate_millihertz())
}
#[inline]
pub fn monitor(&self) -> MonitorHandle {
x11_or_wayland!(match self; VideoMode(m) => m.monitor(); as MonitorHandle)
x11_or_wayland!(match self; VideoModeHandle(m) => m.monitor(); as MonitorHandle)
}
}

View file

@ -11,7 +11,7 @@ use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy};
pub use crate::platform_impl::platform::{OsError, WindowId};
pub use event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
pub use output::{MonitorHandle, VideoMode};
pub use output::{MonitorHandle, VideoModeHandle};
pub use window::Window;
mod event_loop;

View file

@ -4,7 +4,7 @@ use sctk::reexports::client::Proxy;
use sctk::output::OutputData;
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::platform_impl::platform::VideoMode as PlatformVideoMode;
use crate::platform_impl::platform::VideoModeHandle as PlatformVideoModeHandle;
use super::event_loop::EventLoopWindowTarget;
@ -98,14 +98,14 @@ impl MonitorHandle {
}
#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> {
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoModeHandle> {
let output_data = self.proxy.data::<OutputData>().unwrap();
let modes = output_data.with_output_info(|info| info.modes.clone());
let monitor = self.clone();
modes.into_iter().map(move |mode| {
PlatformVideoMode::Wayland(VideoMode {
PlatformVideoModeHandle::Wayland(VideoModeHandle {
size: (mode.dimensions.0 as u32, mode.dimensions.1 as u32).into(),
refresh_rate_millihertz: mode.refresh_rate as u32,
bit_depth: 32,
@ -142,14 +142,14 @@ impl std::hash::Hash for MonitorHandle {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VideoMode {
pub struct VideoModeHandle {
pub(crate) size: PhysicalSize<u32>,
pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32,
pub(crate) monitor: MonitorHandle,
}
impl VideoMode {
impl VideoModeHandle {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.size

View file

@ -12,7 +12,7 @@ mod window;
mod xdisplay;
pub(crate) use self::{
monitor::{MonitorHandle, VideoMode},
monitor::{MonitorHandle, VideoModeHandle},
window::UnownedWindow,
xdisplay::XConnection,
};

View file

@ -1,7 +1,7 @@
use super::{util, X11Error, XConnection};
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
platform_impl::VideoMode as PlatformVideoMode,
platform_impl::VideoModeHandle as PlatformVideoModeHandle,
};
use x11rb::{
connection::RequestConnection,
@ -22,7 +22,7 @@ impl XConnection {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VideoMode {
pub struct VideoModeHandle {
pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16,
pub(crate) refresh_rate_millihertz: u32,
@ -30,7 +30,7 @@ pub struct VideoMode {
pub(crate) monitor: Option<MonitorHandle>,
}
impl VideoMode {
impl VideoModeHandle {
#[inline]
pub fn size(&self) -> PhysicalSize<u32> {
self.size.into()
@ -71,7 +71,7 @@ pub struct MonitorHandle {
/// Used to determine which windows are on this monitor
pub(crate) rect: util::AaRect,
/// Supported video modes on this monitor
video_modes: Vec<VideoMode>,
video_modes: Vec<VideoModeHandle>,
}
impl PartialEq for MonitorHandle {
@ -191,11 +191,11 @@ impl MonitorHandle {
}
#[inline]
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoMode> {
pub fn video_modes(&self) -> impl Iterator<Item = PlatformVideoModeHandle> {
let monitor = self.clone();
self.video_modes.clone().into_iter().map(move |mut x| {
x.monitor = Some(monitor.clone());
PlatformVideoMode::X(x)
PlatformVideoModeHandle::X(x)
})
}
}

View file

@ -2,7 +2,7 @@ use std::{env, str, str::FromStr};
use super::*;
use crate::platform_impl::platform::x11::monitor;
use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoMode};
use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoModeHandle};
use log::warn;
use x11rb::protocol::randr::{self, ConnectionExt as _};
@ -46,7 +46,7 @@ impl XConnection {
&self,
resources: &monitor::ScreenResources,
crtc: &randr::GetCrtcInfoReply,
) -> Option<(String, f64, Vec<VideoMode>)> {
) -> Option<(String, f64, Vec<VideoModeHandle>)> {
let output_info = match self
.xcb_connection()
.randr_get_output_info(crtc.outputs[0], x11rb::CURRENT_TIME)
@ -70,7 +70,7 @@ impl XConnection {
// modes in the array in XRRScreenResources
.filter(|x| output_modes.iter().any(|id| x.id == *id))
.map(|mode| {
VideoMode {
VideoModeHandle {
size: (mode.width.into(), mode.height.into()),
refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode)
.unwrap_or(0),

View file

@ -32,7 +32,7 @@ use crate::{
X11Error,
},
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformIcon,
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
PlatformSpecificWindowBuilderAttributes, VideoModeHandle as PlatformVideoModeHandle,
},
window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
@ -754,10 +754,10 @@ impl UnownedWindow {
// fullscreen, so we can restore it upon exit, as XRandR does not
// provide a mechanism to set this per app-session or restore this
// to the desktop video mode as macOS and Windows do
(&None, &Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))))
(&None, &Some(Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode))))
| (
&Some(Fullscreen::Borderless(_)),
&Some(Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode))),
&Some(Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode))),
) => {
let monitor = video_mode.monitor.as_ref().unwrap();
shared_state_lock.desktop_video_mode = Some((
@ -793,7 +793,7 @@ impl UnownedWindow {
}
Some(fullscreen) => {
let (video_mode, monitor) = match fullscreen {
Fullscreen::Exclusive(PlatformVideoMode::X(ref video_mode)) => {
Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode)) => {
(Some(video_mode), video_mode.monitor.clone().unwrap())
}
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {