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,3 +1,5 @@
|
|||
use std::num::{NonZeroU16, NonZeroU32};
|
||||
|
||||
use x11rb::connection::RequestConnection;
|
||||
use x11rb::protocol::randr::{self, ConnectionExt as _};
|
||||
use x11rb::protocol::xproto;
|
||||
|
|
@ -20,8 +22,8 @@ impl XConnection {
|
|||
pub struct VideoModeHandle {
|
||||
pub(crate) current: bool,
|
||||
pub(crate) size: (u32, u32),
|
||||
pub(crate) bit_depth: u16,
|
||||
pub(crate) refresh_rate_millihertz: Option<u32>,
|
||||
pub(crate) bit_depth: Option<NonZeroU16>,
|
||||
pub(crate) refresh_rate_millihertz: Option<NonZeroU32>,
|
||||
pub(crate) native_mode: randr::Mode,
|
||||
pub(crate) monitor: Option<MonitorHandle>,
|
||||
}
|
||||
|
|
@ -33,12 +35,12 @@ impl VideoModeHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bit_depth(&self) -> u16 {
|
||||
pub fn bit_depth(&self) -> Option<NonZeroU16> {
|
||||
self.bit_depth
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<u32> {
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<NonZeroU32> {
|
||||
self.refresh_rate_millihertz
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +57,7 @@ pub struct MonitorHandle {
|
|||
/// The name of the monitor
|
||||
pub(crate) name: String,
|
||||
/// The position of the monitor in the X screen
|
||||
position: (i32, i32),
|
||||
pub(crate) position: (i32, i32),
|
||||
/// If the monitor is the primary one
|
||||
primary: bool,
|
||||
/// The DPI scale factor
|
||||
|
|
@ -93,10 +95,12 @@ impl std::hash::Hash for MonitorHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mode_refresh_rate_millihertz(mode: &randr::ModeInfo) -> Option<u32> {
|
||||
pub fn mode_refresh_rate_millihertz(mode: &randr::ModeInfo) -> Option<NonZeroU32> {
|
||||
if mode.dot_clock > 0 && mode.htotal > 0 && mode.vtotal > 0 {
|
||||
#[allow(clippy::unnecessary_cast)]
|
||||
Some((mode.dot_clock as u64 * 1000 / (mode.htotal as u64 * mode.vtotal as u64)) as u32)
|
||||
NonZeroU32::new(
|
||||
(mode.dot_clock as u64 * 1000 / (mode.htotal as u64 * mode.vtotal as u64)) as u32,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -145,8 +149,8 @@ impl MonitorHandle {
|
|||
self.id as _
|
||||
}
|
||||
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
self.position.into()
|
||||
pub fn position(&self) -> Option<PhysicalPosition<i32>> {
|
||||
Some(self.position.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::num::NonZeroU16;
|
||||
use std::str::FromStr;
|
||||
use std::{env, str};
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ impl XConnection {
|
|||
current: mode.id == current_mode,
|
||||
size: (mode.width.into(), mode.height.into()),
|
||||
refresh_rate_millihertz: monitor::mode_refresh_rate_millihertz(mode),
|
||||
bit_depth: bit_depth as u16,
|
||||
bit_depth: NonZeroU16::new(bit_depth as u16),
|
||||
native_mode: mode.id,
|
||||
// This is populated in `MonitorHandle::video_modes` as the
|
||||
// video mode is returned to the user
|
||||
|
|
|
|||
|
|
@ -822,7 +822,7 @@ impl UnownedWindow {
|
|||
|
||||
let window_position = self.outer_position_physical();
|
||||
self.shared_state_lock().restore_position = Some(window_position);
|
||||
let monitor_origin: (i32, i32) = monitor.position().into();
|
||||
let monitor_origin: (i32, i32) = monitor.position;
|
||||
self.set_position_inner(monitor_origin.0, monitor_origin.1)
|
||||
.expect_then_ignore_error("Failed to set window position");
|
||||
self.set_fullscreen_hint(true).map(Some)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue