Change Monitor dimensions functions to size functions (#911)

This commit is contained in:
Osspial 2019-06-13 02:33:44 -04:00 committed by Hal Gentz
parent 47b5dfa034
commit ea5c21950c
12 changed files with 34 additions and 34 deletions

View file

@ -52,15 +52,15 @@ impl Iterator for AvailableMonitorsIter {
/// [monitor_get]: ../monitor/struct.MonitorHandle.html#method.video_modes /// [monitor_get]: ../monitor/struct.MonitorHandle.html#method.video_modes
#[derive(Debug, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct VideoMode { pub struct VideoMode {
pub(crate) dimensions: (u32, u32), pub(crate) size: (u32, u32),
pub(crate) bit_depth: u16, pub(crate) bit_depth: u16,
pub(crate) refresh_rate: u16, pub(crate) refresh_rate: u16,
} }
impl VideoMode { impl VideoMode {
/// Returns the resolution of this video mode. /// Returns the resolution of this video mode.
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
self.dimensions.into() self.size.into()
} }
/// Returns the bit depth of this video mode, as in how many bits you have /// Returns the bit depth of this video mode, as in how many bits you have
@ -104,8 +104,8 @@ impl MonitorHandle {
/// Returns the monitor's resolution. /// Returns the monitor's resolution.
#[inline] #[inline]
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
self.inner.dimensions() self.inner.size()
} }
/// Returns the top-left corner position of the monitor relative to the larger full /// Returns the top-left corner position of the monitor relative to the larger full

View file

@ -107,7 +107,7 @@ impl EventLoop {
None None
} else { } else {
let dpi_factor = MonitorHandle.hidpi_factor(); let dpi_factor = MonitorHandle.hidpi_factor();
let physical_size = MonitorHandle.dimensions(); let physical_size = MonitorHandle.size();
let size = LogicalSize::from_physical(physical_size, dpi_factor); let size = LogicalSize::from_physical(physical_size, dpi_factor);
Some(Event::WindowEvent { Some(Event::WindowEvent {
window_id: RootWindowId(WindowId), window_id: RootWindowId(WindowId),
@ -207,7 +207,7 @@ impl fmt::Debug for MonitorHandle {
let monitor_id_proxy = MonitorHandle { let monitor_id_proxy = MonitorHandle {
name: self.name(), name: self.name(),
dimensions: self.dimensions(), dimensions: self.size(),
position: self.outer_position(), position: self.outer_position(),
hidpi_factor: self.hidpi_factor(), hidpi_factor: self.hidpi_factor(),
}; };
@ -223,7 +223,7 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
unsafe { unsafe {
let window = android_glue::native_window(); let window = android_glue::native_window();
( (
@ -325,7 +325,7 @@ impl Window {
None None
} else { } else {
let dpi_factor = self.hidpi_factor(); let dpi_factor = self.hidpi_factor();
let physical_size = self.current_monitor().dimensions(); let physical_size = self.current_monitor().size();
Some(LogicalSize::from_physical(physical_size, dpi_factor)) Some(LogicalSize::from_physical(physical_size, dpi_factor))
} }
} }

View file

@ -54,7 +54,7 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
(0, 0).into() (0, 0).into()
} }

View file

@ -67,14 +67,14 @@ impl fmt::Debug for MonitorHandle {
#[derive(Debug)] #[derive(Debug)]
struct MonitorHandle { struct MonitorHandle {
name: Option<String>, name: Option<String>,
dimensions: PhysicalSize, size: PhysicalSize,
position: PhysicalPosition, position: PhysicalPosition,
hidpi_factor: f64, hidpi_factor: f64,
} }
let monitor_id_proxy = MonitorHandle { let monitor_id_proxy = MonitorHandle {
name: self.name(), name: self.name(),
dimensions: self.dimensions(), size: self.size(),
position: self.position(), position: self.position(),
hidpi_factor: self.hidpi_factor(), hidpi_factor: self.hidpi_factor(),
}; };
@ -109,7 +109,7 @@ impl Inner {
} }
} }
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
unsafe { unsafe {
let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds]; let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds];
(bounds.size.width as f64, bounds.size.height as f64).into() (bounds.size.width as f64, bounds.size.height as f64).into()
@ -142,7 +142,7 @@ impl Inner {
let mode: id = unsafe { msg_send![available_modes, objectAtIndex: i] }; let mode: id = unsafe { msg_send![available_modes, objectAtIndex: i] };
let size: CGSize = unsafe { msg_send![mode, size] }; let size: CGSize = unsafe { msg_send![mode, size] };
modes.insert(VideoMode { modes.insert(VideoMode {
dimensions: (size.width as u32, size.height as u32), size: (size.width as u32, size.height as u32),
bit_depth: 32, bit_depth: 32,
refresh_rate: refresh_rate as u16, refresh_rate: refresh_rate as u16,
}); });

View file

@ -120,10 +120,10 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
match self { match self {
&MonitorHandle::X(ref m) => m.dimensions(), &MonitorHandle::X(ref m) => m.size(),
&MonitorHandle::Wayland(ref m) => m.dimensions(), &MonitorHandle::Wayland(ref m) => m.size(),
} }
} }

View file

@ -531,7 +531,7 @@ impl fmt::Debug for MonitorHandle {
struct MonitorHandle { struct MonitorHandle {
name: Option<String>, name: Option<String>,
native_identifier: u32, native_identifier: u32,
dimensions: PhysicalSize, size: PhysicalSize,
position: PhysicalPosition, position: PhysicalPosition,
hidpi_factor: i32, hidpi_factor: i32,
} }
@ -539,7 +539,7 @@ impl fmt::Debug for MonitorHandle {
let monitor_id_proxy = MonitorHandle { let monitor_id_proxy = MonitorHandle {
name: self.name(), name: self.name(),
native_identifier: self.native_identifier(), native_identifier: self.native_identifier(),
dimensions: self.dimensions(), size: self.size(),
position: self.position(), position: self.position(),
hidpi_factor: self.hidpi_factor(), hidpi_factor: self.hidpi_factor(),
}; };
@ -560,7 +560,7 @@ impl MonitorHandle {
self.mgr.with_info(&self.proxy, |id, _| id).unwrap_or(0) self.mgr.with_info(&self.proxy, |id, _| id).unwrap_or(0)
} }
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
match self.mgr.with_info(&self.proxy, |_, info| { match self.mgr.with_info(&self.proxy, |_, info| {
info.modes info.modes
.iter() .iter()
@ -594,7 +594,7 @@ impl MonitorHandle {
.unwrap_or(vec![]) .unwrap_or(vec![])
.into_iter() .into_iter()
.map(|x| VideoMode { .map(|x| VideoMode {
dimensions: (x.dimensions.0 as u32, x.dimensions.1 as u32), size: (x.dimensions.0 as u32, x.dimensions.1 as u32),
refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16, refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16,
bit_depth: 32 bit_depth: 32
}) })

View file

@ -70,7 +70,7 @@ impl MonitorHandle {
primary: bool, primary: bool,
) -> Option<Self> { ) -> Option<Self> {
let (name, hidpi_factor, video_modes) = unsafe { xconn.get_output_info(resources, &repr)? }; let (name, hidpi_factor, video_modes) = unsafe { xconn.get_output_info(resources, &repr)? };
let (dimensions, position) = unsafe { (repr.dimensions(), repr.position()) }; let (dimensions, position) = unsafe { (repr.size(), repr.position()) };
let rect = util::AaRect::new(position, dimensions); let rect = util::AaRect::new(position, dimensions);
Some(MonitorHandle { Some(MonitorHandle {
id, id,
@ -93,7 +93,7 @@ impl MonitorHandle {
self.id as u32 self.id as u32
} }
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
self.dimensions.into() self.dimensions.into()
} }

View file

@ -52,7 +52,7 @@ impl MonitorRepr {
} }
} }
pub unsafe fn dimensions(&self) -> (u32, u32) { pub unsafe fn size(&self) -> (u32, u32) {
match *self { match *self {
MonitorRepr::Monitor(monitor) => ((*monitor).width as u32, (*monitor).height as u32), MonitorRepr::Monitor(monitor) => ((*monitor).width as u32, (*monitor).height as u32),
MonitorRepr::Crtc(crtc) => ((*crtc).width as u32, (*crtc).height as u32), MonitorRepr::Crtc(crtc) => ((*crtc).width as u32, (*crtc).height as u32),
@ -136,7 +136,7 @@ impl XConnection {
}; };
VideoMode { VideoMode {
dimensions: (x.width, x.height), size: (x.width, x.height),
refresh_rate: (refresh_rate as f32 / 1000.0).round() as u16, refresh_rate: (refresh_rate as f32 / 1000.0).round() as u16,
bit_depth: bit_depth as u16, bit_depth: bit_depth as u16,
} }
@ -151,7 +151,7 @@ impl XConnection {
dpi / 96. dpi / 96.
} else { } else {
calc_dpi_factor( calc_dpi_factor(
repr.dimensions(), repr.size(),
((*output_info).mm_width as u64, (*output_info).mm_height as u64), ((*output_info).mm_width as u64, (*output_info).mm_height as u64),
) )
}; };

View file

@ -41,7 +41,7 @@ impl fmt::Debug for MonitorHandle {
struct MonitorHandle { struct MonitorHandle {
name: Option<String>, name: Option<String>,
native_identifier: u32, native_identifier: u32,
dimensions: PhysicalSize, size: PhysicalSize,
position: PhysicalPosition, position: PhysicalPosition,
hidpi_factor: f64, hidpi_factor: f64,
} }
@ -49,7 +49,7 @@ impl fmt::Debug for MonitorHandle {
let monitor_id_proxy = MonitorHandle { let monitor_id_proxy = MonitorHandle {
name: self.name(), name: self.name(),
native_identifier: self.native_identifier(), native_identifier: self.native_identifier(),
dimensions: self.dimensions(), size: self.size(),
position: self.position(), position: self.position(),
hidpi_factor: self.hidpi_factor(), hidpi_factor: self.hidpi_factor(),
}; };
@ -74,7 +74,7 @@ impl MonitorHandle {
self.0 self.0
} }
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
let MonitorHandle(display_id) = *self; let MonitorHandle(display_id) = *self;
let display = CGDisplay::new(display_id); let display = CGDisplay::new(display_id);
let height = display.pixels_high(); let height = display.pixels_high();
@ -133,7 +133,7 @@ impl MonitorHandle {
}; };
VideoMode { VideoMode {
dimensions: (mode.width() as u32, mode.height() as u32), size: (mode.width() as u32, mode.height() as u32),
refresh_rate: refresh_rate as u16, refresh_rate: refresh_rate as u16,
bit_depth: mode.bit_depth() as u16, bit_depth: mode.bit_depth() as u16,
} }

View file

@ -162,7 +162,7 @@ impl MonitorHandle {
} }
#[inline] #[inline]
pub fn dimensions(&self) -> PhysicalSize { pub fn size(&self) -> PhysicalSize {
self.dimensions.into() self.dimensions.into()
} }
@ -201,7 +201,7 @@ impl MonitorHandle {
assert!(mode.dmFields & REQUIRED_FIELDS == REQUIRED_FIELDS); assert!(mode.dmFields & REQUIRED_FIELDS == REQUIRED_FIELDS);
modes.insert(VideoMode { modes.insert(VideoMode {
dimensions: (mode.dmPelsWidth, mode.dmPelsHeight), size: (mode.dmPelsWidth, mode.dmPelsHeight),
bit_depth: mode.dmBitsPerPel as u16, bit_depth: mode.dmBitsPerPel as u16,
refresh_rate: mode.dmDisplayFrequency as u16, refresh_rate: mode.dmDisplayFrequency as u16,
}); });

View file

@ -403,7 +403,7 @@ impl Window {
match &monitor { match &monitor {
&Some(RootMonitorHandle { ref inner }) => { &Some(RootMonitorHandle { ref inner }) => {
let (x, y): (i32, i32) = inner.position().into(); let (x, y): (i32, i32) = inner.position().into();
let (width, height): (u32, u32) = inner.dimensions().into(); let (width, height): (u32, u32) = inner.size().into();
let mut monitor = monitor.clone(); let mut monitor = monitor.clone();
self.thread_executor.execute_in_thread(move || { self.thread_executor.execute_in_thread(move || {

View file

@ -287,7 +287,7 @@ impl WindowBuilder {
self.window.inner_size = Some(self.window.inner_size.unwrap_or_else(|| { self.window.inner_size = Some(self.window.inner_size.unwrap_or_else(|| {
if let Some(ref monitor) = self.window.fullscreen { if let Some(ref monitor) = self.window.fullscreen {
// resizing the window to the dimensions of the monitor when fullscreen // resizing the window to the dimensions of the monitor when fullscreen
LogicalSize::from_physical(monitor.dimensions(), 1.0) LogicalSize::from_physical(monitor.size(), 1.0)
} else { } else {
// default dimensions // default dimensions
(1024, 768).into() (1024, 768).into()