Rename MonitorId to MonitorHandle

This commit is contained in:
Osspial
2018-08-23 20:19:56 -04:00
parent 8d8d9b7cd1
commit deb7d379b7
26 changed files with 224 additions and 220 deletions

View File

@@ -33,7 +33,7 @@
//! windows. This event is sent any time the DPI factor changes, either because the window moved to another monitor, //! windows. This event is sent any time the DPI factor changes, either because the window moved to another monitor,
//! or because the user changed the configuration of their screen. //! or because the user changed the configuration of their screen.
//! - You can also retrieve the DPI factor of a monitor by calling //! - You can also retrieve the DPI factor of a monitor by calling
//! [`MonitorId::get_hidpi_factor`](../monitor/struct.MonitorId.html#method.get_hidpi_factor), or the //! [`MonitorHandle::get_hidpi_factor`](../monitor/struct.MonitorHandle.html#method.get_hidpi_factor), or the
//! current DPI factor applied to a window by calling //! current DPI factor applied to a window by calling
//! [`Window::get_hidpi_factor`](../window/struct.Window.html#method.get_hidpi_factor), which is roughly equivalent //! [`Window::get_hidpi_factor`](../window/struct.Window.html#method.get_hidpi_factor), which is roughly equivalent
//! to `window.get_current_monitor().get_hidpi_factor()`. //! to `window.get_current_monitor().get_hidpi_factor()`.

View File

@@ -14,7 +14,7 @@ use std::time::Instant;
use platform_impl; use platform_impl;
use event::Event; use event::Event;
use monitor::{AvailableMonitorsIter, MonitorId}; use monitor::{AvailableMonitorsIter, MonitorHandle};
/// Provides a way to retrieve events from the system and from the windows that were registered to /// Provides a way to retrieve events from the system and from the windows that were registered to
/// the events loop. /// the events loop.
@@ -101,8 +101,8 @@ impl<T> EventLoop<T> {
/// Returns the primary monitor of the system. /// Returns the primary monitor of the system.
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId { inner: self.event_loop.get_primary_monitor() } MonitorHandle { inner: self.event_loop.get_primary_monitor() }
} }
/// Hijacks the calling thread and initializes the `winit` event loop with the provided /// Hijacks the calling thread and initializes the `winit` event loop with the provided

View File

@@ -1,12 +1,12 @@
//! Types useful for interacting with a user's monitors. //! Types useful for interacting with a user's monitors.
//! //!
//! If you want to get basic information about a monitor, you can use the [`MonitorId`][monitor_id] //! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_id]
//! type. This is retreived from an [`AvailableMonitorsIter`][monitor_iter], which can be acquired //! type. This is retreived from an [`AvailableMonitorsIter`][monitor_iter], which can be acquired
//! with: //! with:
//! - [`EventLoop::get_available_monitors`][loop_get] //! - [`EventLoop::get_available_monitors`][loop_get]
//! - [`Window::get_available_monitors`][window_get]. //! - [`Window::get_available_monitors`][window_get].
//! //!
//! [monitor_id]: ./struct.MonitorId.html //! [monitor_id]: ./struct.MonitorHandle.html
//! [monitor_iter]: ./struct.AvailableMonitorsIter.html //! [monitor_iter]: ./struct.AvailableMonitorsIter.html
//! [loop_get]: ../event_loop/struct.EventLoop.html#method.get_available_monitors //! [loop_get]: ../event_loop/struct.EventLoop.html#method.get_available_monitors
//! [window_get]: ../window/struct.Window.html#method.get_available_monitors //! [window_get]: ../window/struct.Window.html#method.get_available_monitors
@@ -27,15 +27,15 @@ use dpi::{PhysicalPosition, PhysicalSize};
// This may change in the future. // This may change in the future.
#[derive(Debug)] #[derive(Debug)]
pub struct AvailableMonitorsIter { pub struct AvailableMonitorsIter {
pub(crate) data: VecDequeIter<platform_impl::MonitorId>, pub(crate) data: VecDequeIter<platform_impl::MonitorHandle>,
} }
impl Iterator for AvailableMonitorsIter { impl Iterator for AvailableMonitorsIter {
type Item = MonitorId; type Item = MonitorHandle;
#[inline] #[inline]
fn next(&mut self) -> Option<MonitorId> { fn next(&mut self) -> Option<MonitorHandle> {
self.data.next().map(|id| MonitorId { inner: id }) self.data.next().map(|id| MonitorHandle { inner: id })
} }
#[inline] #[inline]
@@ -44,13 +44,17 @@ impl Iterator for AvailableMonitorsIter {
} }
} }
/// Identifier for a monitor. /// Handle to a monitor.
///
/// Allows you to retrieve information about a given monitor and can be used in [`Window`] creation.
///
/// [`Window`]: ../window/struct.Window.html
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MonitorId { pub struct MonitorHandle {
pub(crate) inner: platform_impl::MonitorId pub(crate) inner: platform_impl::MonitorHandle
} }
impl MonitorId { impl MonitorHandle {
/// Returns a human-readable name of the monitor. /// Returns a human-readable name of the monitor.
/// ///
/// Returns `None` if the monitor doesn't exist anymore. /// Returns `None` if the monitor doesn't exist anymore.

View File

@@ -2,7 +2,7 @@
use std::os::raw::c_void; use std::os::raw::c_void;
use {MonitorId, Window, WindowBuilder}; use {MonitorHandle, Window, WindowBuilder};
/// Additional methods on `Window` that are specific to iOS. /// Additional methods on `Window` that are specific to iOS.
pub trait WindowExtIOS { pub trait WindowExtIOS {
@@ -45,13 +45,13 @@ impl WindowBuilderExtIOS for WindowBuilder {
} }
} }
/// Additional methods on `MonitorId` that are specific to iOS. /// Additional methods on `MonitorHandle` that are specific to iOS.
pub trait MonitorIdExtIOS { pub trait MonitorHandleExtIOS {
/// Returns a pointer to the `UIScreen` that is used by this monitor. /// Returns a pointer to the `UIScreen` that is used by this monitor.
fn get_uiscreen(&self) -> *mut c_void; fn get_uiscreen(&self) -> *mut c_void;
} }
impl MonitorIdExtIOS for MonitorId { impl MonitorHandleExtIOS for MonitorHandle {
#[inline] #[inline]
fn get_uiscreen(&self) -> *mut c_void { fn get_uiscreen(&self) -> *mut c_void {
self.inner.get_uiscreen() as _ self.inner.get_uiscreen() as _

View File

@@ -1,7 +1,7 @@
#![cfg(target_os = "macos")] #![cfg(target_os = "macos")]
use std::os::raw::c_void; use std::os::raw::c_void;
use {LogicalSize, MonitorId, Window, WindowBuilder}; use {LogicalSize, MonitorHandle, Window, WindowBuilder};
/// Additional methods on `Window` that are specific to MacOS. /// Additional methods on `Window` that are specific to MacOS.
pub trait WindowExtMacOS { pub trait WindowExtMacOS {
@@ -137,15 +137,15 @@ impl WindowBuilderExtMacOS for WindowBuilder {
} }
} }
/// Additional methods on `MonitorId` that are specific to MacOS. /// Additional methods on `MonitorHandle` that are specific to MacOS.
pub trait MonitorIdExtMacOS { pub trait MonitorHandleExtMacOS {
/// Returns the identifier of the monitor for Cocoa. /// Returns the identifier of the monitor for Cocoa.
fn native_id(&self) -> u32; fn native_id(&self) -> u32;
/// Returns a pointer to the NSScreen representing this monitor. /// Returns a pointer to the NSScreen representing this monitor.
fn get_nsscreen(&self) -> Option<*mut c_void>; fn get_nsscreen(&self) -> Option<*mut c_void>;
} }
impl MonitorIdExtMacOS for MonitorId { impl MonitorHandleExtMacOS for MonitorHandle {
#[inline] #[inline]
fn native_id(&self) -> u32 { fn native_id(&self) -> u32 {
self.inner.get_native_identifier() self.inner.get_native_identifier()

View File

@@ -7,7 +7,7 @@ use std::sync::Arc;
use { use {
EventLoop, EventLoop,
LogicalSize, LogicalSize,
MonitorId, MonitorHandle,
Window, Window,
WindowBuilder, WindowBuilder,
}; };
@@ -279,13 +279,13 @@ impl WindowBuilderExtUnix for WindowBuilder {
} }
} }
/// Additional methods on `MonitorId` that are specific to Linux. /// Additional methods on `MonitorHandle` that are specific to Linux.
pub trait MonitorIdExtUnix { pub trait MonitorHandleExtUnix {
/// Returns the inner identifier of the monitor. /// Returns the inner identifier of the monitor.
fn native_id(&self) -> u32; fn native_id(&self) -> u32;
} }
impl MonitorIdExtUnix for MonitorId { impl MonitorHandleExtUnix for MonitorHandle {
#[inline] #[inline]
fn native_id(&self) -> u32 { fn native_id(&self) -> u32 {
self.inner.get_native_identifier() self.inner.get_native_identifier()

View File

@@ -6,7 +6,7 @@ use libc;
use winapi::shared::windef::HWND; use winapi::shared::windef::HWND;
use event::DeviceId; use event::DeviceId;
use monitor::MonitorId; use monitor::MonitorHandle;
use event_loop::EventLoop; use event_loop::EventLoop;
use window::{Icon, Window, WindowBuilder}; use window::{Icon, Window, WindowBuilder};
use platform_impl::EventLoop as WindowsEventLoop; use platform_impl::EventLoop as WindowsEventLoop;
@@ -83,8 +83,8 @@ impl WindowBuilderExtWindows for WindowBuilder {
} }
} }
/// Additional methods on `MonitorId` that are specific to Windows. /// Additional methods on `MonitorHandle` that are specific to Windows.
pub trait MonitorIdExtWindows { pub trait MonitorHandleExtWindows {
/// Returns the name of the monitor adapter specific to the Win32 API. /// Returns the name of the monitor adapter specific to the Win32 API.
fn native_id(&self) -> String; fn native_id(&self) -> String;
@@ -92,7 +92,7 @@ pub trait MonitorIdExtWindows {
fn hmonitor(&self) -> *mut c_void; fn hmonitor(&self) -> *mut c_void;
} }
impl MonitorIdExtWindows for MonitorId { impl MonitorHandleExtWindows for MonitorHandle {
#[inline] #[inline]
fn native_id(&self) -> String { fn native_id(&self) -> String {
self.inner.get_native_identifier() self.inner.get_native_identifier()

View File

@@ -24,7 +24,7 @@ use {
}; };
use CreationError::OsError; use CreationError::OsError;
use events::{Touch, TouchPhase}; use events::{Touch, TouchPhase};
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
pub struct EventLoop { pub struct EventLoop {
event_rx: Receiver<android_glue::Event>, event_rx: Receiver<android_glue::Event>,
@@ -45,15 +45,15 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut rb = VecDeque::with_capacity(1); let mut rb = VecDeque::with_capacity(1);
rb.push_back(MonitorId); rb.push_back(MonitorHandle);
rb rb
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
pub fn poll_events<F>(&mut self, mut callback: F) pub fn poll_events<F>(&mut self, mut callback: F)
@@ -62,7 +62,7 @@ impl EventLoop {
while let Ok(event) = self.event_rx.try_recv() { while let Ok(event) = self.event_rx.try_recv() {
let e = match event{ let e = match event{
android_glue::Event::EventMotion(motion) => { android_glue::Event::EventMotion(motion) => {
let dpi_factor = MonitorId.get_hidpi_factor(); let dpi_factor = MonitorHandle.get_hidpi_factor();
let location = LogicalPosition::from_physical( let location = LogicalPosition::from_physical(
(motion.x as f64, motion.y as f64), (motion.x as f64, motion.y as f64),
dpi_factor, dpi_factor,
@@ -103,8 +103,8 @@ impl EventLoop {
if native_window.is_null() { if native_window.is_null() {
None None
} else { } else {
let dpi_factor = MonitorId.get_hidpi_factor(); let dpi_factor = MonitorHandle.get_hidpi_factor();
let physical_size = MonitorId.get_dimensions(); let physical_size = MonitorHandle.get_dimensions();
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),
@@ -178,19 +178,19 @@ pub struct Window {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct MonitorId; pub struct MonitorHandle;
impl fmt::Debug for MonitorId { impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Debug)] #[derive(Debug)]
struct MonitorId { struct MonitorHandle {
name: Option<String>, name: Option<String>,
dimensions: PhysicalSize, dimensions: PhysicalSize,
position: PhysicalPosition, position: PhysicalPosition,
hidpi_factor: f64, hidpi_factor: f64,
} }
let monitor_id_proxy = MonitorId { let monitor_id_proxy = MonitorHandle {
name: self.get_name(), name: self.get_name(),
dimensions: self.get_dimensions(), dimensions: self.get_dimensions(),
position: self.get_position(), position: self.get_position(),
@@ -201,7 +201,7 @@ impl fmt::Debug for MonitorId {
} }
} }
impl MonitorId { impl MonitorHandle {
#[inline] #[inline]
pub fn get_name(&self) -> Option<String> { pub fn get_name(&self) -> Option<String> {
Some("Primary".to_string()) Some("Primary".to_string())
@@ -357,7 +357,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, _monitor: Option<RootMonitorHandle>) {
// N/A // N/A
// Android has single screen maximized apps so nothing to do // Android has single screen maximized apps so nothing to do
} }
@@ -383,20 +383,20 @@ impl Window {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
RootMonitorId { inner: MonitorId } RootMonitorHandle { inner: MonitorHandle }
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut rb = VecDeque::with_capacity(1); let mut rb = VecDeque::with_capacity(1);
rb.push_back(MonitorId); rb.push_back(MonitorHandle);
rb rb
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
#[inline] #[inline]

View File

@@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Mutex, Arc}; use std::sync::{Mutex, Arc};
use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
const DOCUMENT_NAME: &'static str = "#document\0"; const DOCUMENT_NAME: &'static str = "#document\0";
@@ -31,9 +31,9 @@ pub struct DeviceId;
pub struct PlatformSpecificHeadlessBuilderAttributes; pub struct PlatformSpecificHeadlessBuilderAttributes;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MonitorId; pub struct MonitorHandle;
impl MonitorId { impl MonitorHandle {
#[inline] #[inline]
pub fn get_name(&self) -> Option<String> { pub fn get_name(&self) -> Option<String> {
Some("Canvas".to_owned()) Some("Canvas".to_owned())
@@ -107,15 +107,15 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut list = VecDeque::with_capacity(1); let mut list = VecDeque::with_capacity(1);
list.push_back(MonitorId); list.push_back(MonitorHandle);
list list
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
pub fn poll_events<F>(&self, mut callback: F) pub fn poll_events<F>(&self, mut callback: F)
@@ -569,7 +569,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, _monitor: Option<::MonitorId>) { pub fn set_fullscreen(&self, _monitor: Option<::MonitorHandle>) {
// iOS has single screen maximized apps so nothing to do // iOS has single screen maximized apps so nothing to do
} }
@@ -594,20 +594,20 @@ impl Window {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
RootMonitorId { inner: MonitorId } RootMonitorHandle { inner: MonitorHandle }
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut list = VecDeque::with_capacity(1); let mut list = VecDeque::with_capacity(1);
list.push_back(MonitorId); list.push_back(MonitorHandle);
list list
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
} }

View File

@@ -82,7 +82,7 @@ use {
WindowId as RootEventId, WindowId as RootEventId,
}; };
use events::{Touch, TouchPhase}; use events::{Touch, TouchPhase};
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
mod ffi; mod ffi;
use self::ffi::{ use self::ffi::{
@@ -145,19 +145,19 @@ impl Drop for DelegateState {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct MonitorId; pub struct MonitorHandle;
impl fmt::Debug for MonitorId { impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Debug)] #[derive(Debug)]
struct MonitorId { struct MonitorHandle {
name: Option<String>, name: Option<String>,
dimensions: PhysicalSize, dimensions: PhysicalSize,
position: PhysicalPosition, position: PhysicalPosition,
hidpi_factor: f64, hidpi_factor: f64,
} }
let monitor_id_proxy = MonitorId { let monitor_id_proxy = MonitorHandle {
name: self.get_name(), name: self.get_name(),
dimensions: self.get_dimensions(), dimensions: self.get_dimensions(),
position: self.get_position(), position: self.get_position(),
@@ -168,7 +168,7 @@ impl fmt::Debug for MonitorId {
} }
} }
impl MonitorId { impl MonitorHandle {
#[inline] #[inline]
pub fn get_uiscreen(&self) -> id { pub fn get_uiscreen(&self) -> id {
let class = class!(UIScreen); let class = class!(UIScreen);
@@ -217,15 +217,15 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut rb = VecDeque::with_capacity(1); let mut rb = VecDeque::with_capacity(1);
rb.push_back(MonitorId); rb.push_back(MonitorHandle);
rb rb
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
pub fn poll_events<F>(&mut self, mut callback: F) pub fn poll_events<F>(&mut self, mut callback: F)
@@ -330,7 +330,7 @@ impl Window {
(&mut *delegate).set_ivar("eventsQueue", mem::transmute::<_, *mut c_void>(events_queue)); (&mut *delegate).set_ivar("eventsQueue", mem::transmute::<_, *mut c_void>(events_queue));
// easiest? way to get access to PlatformSpecificWindowBuilderAttributes to configure the view // easiest? way to get access to PlatformSpecificWindowBuilderAttributes to configure the view
let rect: CGRect = msg_send![MonitorId.get_uiscreen(), bounds]; let rect: CGRect = msg_send![MonitorHandle.get_uiscreen(), bounds];
let uiview_class = class!(UIView); let uiview_class = class!(UIView);
let root_view_class = pl_attributes.root_view_class; let root_view_class = pl_attributes.root_view_class;
@@ -462,7 +462,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, _monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, _monitor: Option<RootMonitorHandle>) {
// N/A // N/A
// iOS has single screen maximized apps so nothing to do // iOS has single screen maximized apps so nothing to do
} }
@@ -488,20 +488,20 @@ impl Window {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
RootMonitorId { inner: MonitorId } RootMonitorHandle { inner: MonitorHandle }
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut rb = VecDeque::with_capacity(1); let mut rb = VecDeque::with_capacity(1);
rb.push_back(MonitorId); rb.push_back(MonitorHandle);
rb rb
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId MonitorHandle
} }
#[inline] #[inline]

View File

@@ -18,7 +18,7 @@ use {
WindowAttributes, WindowAttributes,
}; };
use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
use self::x11::{XConnection, XError}; use self::x11::{XConnection, XError};
use self::x11::ffi::XVisualInfo; use self::x11::ffi::XVisualInfo;
pub use self::x11::XNotSupported; pub use self::x11::XNotSupported;
@@ -72,49 +72,49 @@ pub enum DeviceId {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum MonitorId { pub enum MonitorHandle {
X(x11::MonitorId), X(x11::MonitorHandle),
Wayland(wayland::MonitorId), Wayland(wayland::MonitorHandle),
} }
impl MonitorId { impl MonitorHandle {
#[inline] #[inline]
pub fn get_name(&self) -> Option<String> { pub fn get_name(&self) -> Option<String> {
match self { match self {
&MonitorId::X(ref m) => m.get_name(), &MonitorHandle::X(ref m) => m.get_name(),
&MonitorId::Wayland(ref m) => m.get_name(), &MonitorHandle::Wayland(ref m) => m.get_name(),
} }
} }
#[inline] #[inline]
pub fn get_native_identifier(&self) -> u32 { pub fn get_native_identifier(&self) -> u32 {
match self { match self {
&MonitorId::X(ref m) => m.get_native_identifier(), &MonitorHandle::X(ref m) => m.get_native_identifier(),
&MonitorId::Wayland(ref m) => m.get_native_identifier(), &MonitorHandle::Wayland(ref m) => m.get_native_identifier(),
} }
} }
#[inline] #[inline]
pub fn get_dimensions(&self) -> PhysicalSize { pub fn get_dimensions(&self) -> PhysicalSize {
match self { match self {
&MonitorId::X(ref m) => m.get_dimensions(), &MonitorHandle::X(ref m) => m.get_dimensions(),
&MonitorId::Wayland(ref m) => m.get_dimensions(), &MonitorHandle::Wayland(ref m) => m.get_dimensions(),
} }
} }
#[inline] #[inline]
pub fn get_position(&self) -> PhysicalPosition { pub fn get_position(&self) -> PhysicalPosition {
match self { match self {
&MonitorId::X(ref m) => m.get_position(), &MonitorHandle::X(ref m) => m.get_position(),
&MonitorId::Wayland(ref m) => m.get_position(), &MonitorHandle::Wayland(ref m) => m.get_position(),
} }
} }
#[inline] #[inline]
pub fn get_hidpi_factor(&self) -> f64 { pub fn get_hidpi_factor(&self) -> f64 {
match self { match self {
&MonitorId::X(ref m) => m.get_hidpi_factor(), &MonitorHandle::X(ref m) => m.get_hidpi_factor(),
&MonitorId::Wayland(ref m) => m.get_hidpi_factor() as f64, &MonitorHandle::Wayland(ref m) => m.get_hidpi_factor() as f64,
} }
} }
} }
@@ -289,7 +289,7 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
match self { match self {
&Window::X(ref w) => w.set_fullscreen(monitor), &Window::X(ref w) => w.set_fullscreen(monitor),
&Window::Wayland(ref w) => w.set_fullscreen(monitor) &Window::Wayland(ref w) => w.set_fullscreen(monitor)
@@ -329,32 +329,32 @@ impl Window {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
match self { match self {
&Window::X(ref window) => RootMonitorId { inner: MonitorId::X(window.get_current_monitor()) }, &Window::X(ref window) => RootMonitorHandle { inner: MonitorHandle::X(window.get_current_monitor()) },
&Window::Wayland(ref window) => RootMonitorId { inner: MonitorId::Wayland(window.get_current_monitor()) }, &Window::Wayland(ref window) => RootMonitorHandle { inner: MonitorHandle::Wayland(window.get_current_monitor()) },
} }
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
match self { match self {
&Window::X(ref window) => window.get_available_monitors() &Window::X(ref window) => window.get_available_monitors()
.into_iter() .into_iter()
.map(MonitorId::X) .map(MonitorHandle::X)
.collect(), .collect(),
&Window::Wayland(ref window) => window.get_available_monitors() &Window::Wayland(ref window) => window.get_available_monitors()
.into_iter() .into_iter()
.map(MonitorId::Wayland) .map(MonitorHandle::Wayland)
.collect(), .collect(),
} }
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
match self { match self {
&Window::X(ref window) => MonitorId::X(window.get_primary_monitor()), &Window::X(ref window) => MonitorHandle::X(window.get_primary_monitor()),
&Window::Wayland(ref window) => MonitorId::Wayland(window.get_primary_monitor()), &Window::Wayland(ref window) => MonitorHandle::Wayland(window.get_primary_monitor()),
} }
} }
} }
@@ -453,27 +453,27 @@ impl EventLoop {
} }
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
match *self { match *self {
EventLoop::Wayland(ref evlp) => evlp EventLoop::Wayland(ref evlp) => evlp
.get_available_monitors() .get_available_monitors()
.into_iter() .into_iter()
.map(MonitorId::Wayland) .map(MonitorHandle::Wayland)
.collect(), .collect(),
EventLoop::X(ref evlp) => evlp EventLoop::X(ref evlp) => evlp
.x_connection() .x_connection()
.get_available_monitors() .get_available_monitors()
.into_iter() .into_iter()
.map(MonitorId::X) .map(MonitorHandle::X)
.collect(), .collect(),
} }
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
match *self { match *self {
EventLoop::Wayland(ref evlp) => MonitorId::Wayland(evlp.get_primary_monitor()), EventLoop::Wayland(ref evlp) => MonitorHandle::Wayland(evlp.get_primary_monitor()),
EventLoop::X(ref evlp) => MonitorId::X(evlp.x_connection().get_primary_monitor()), EventLoop::X(ref evlp) => MonitorHandle::X(evlp.x_connection().get_primary_monitor()),
} }
} }

View File

@@ -211,11 +211,11 @@ impl EventLoop {
} }
} }
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor(&self.env.outputs) get_primary_monitor(&self.env.outputs)
} }
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors(&self.env.outputs) get_available_monitors(&self.env.outputs)
} }
} }
@@ -452,24 +452,24 @@ impl Drop for SeatData {
* Monitor stuff * Monitor stuff
*/ */
pub struct MonitorId { pub struct MonitorHandle {
pub(crate) proxy: Proxy<wl_output::WlOutput>, pub(crate) proxy: Proxy<wl_output::WlOutput>,
pub(crate) mgr: OutputMgr, pub(crate) mgr: OutputMgr,
} }
impl Clone for MonitorId { impl Clone for MonitorHandle {
fn clone(&self) -> MonitorId { fn clone(&self) -> MonitorHandle {
MonitorId { MonitorHandle {
proxy: self.proxy.clone(), proxy: self.proxy.clone(),
mgr: self.mgr.clone(), mgr: self.mgr.clone(),
} }
} }
} }
impl fmt::Debug for MonitorId { impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Debug)] #[derive(Debug)]
struct MonitorId { struct MonitorHandle {
name: Option<String>, name: Option<String>,
native_identifier: u32, native_identifier: u32,
dimensions: PhysicalSize, dimensions: PhysicalSize,
@@ -477,7 +477,7 @@ impl fmt::Debug for MonitorId {
hidpi_factor: i32, hidpi_factor: i32,
} }
let monitor_id_proxy = MonitorId { let monitor_id_proxy = MonitorHandle {
name: self.get_name(), name: self.get_name(),
native_identifier: self.get_native_identifier(), native_identifier: self.get_native_identifier(),
dimensions: self.get_dimensions(), dimensions: self.get_dimensions(),
@@ -489,7 +489,7 @@ impl fmt::Debug for MonitorId {
} }
} }
impl MonitorId { impl MonitorHandle {
pub fn get_name(&self) -> Option<String> { pub fn get_name(&self) -> Option<String> {
self.mgr.with_info(&self.proxy, |_, info| { self.mgr.with_info(&self.proxy, |_, info| {
format!("{} ({})", info.model, info.make) format!("{} ({})", info.model, info.make)
@@ -528,10 +528,10 @@ impl MonitorId {
} }
} }
pub fn get_primary_monitor(outputs: &OutputMgr) -> MonitorId { pub fn get_primary_monitor(outputs: &OutputMgr) -> MonitorHandle {
outputs.with_all(|list| { outputs.with_all(|list| {
if let Some(&(_, ref proxy, _)) = list.first() { if let Some(&(_, ref proxy, _)) = list.first() {
MonitorId { MonitorHandle {
proxy: proxy.clone(), proxy: proxy.clone(),
mgr: outputs.clone(), mgr: outputs.clone(),
} }
@@ -541,10 +541,10 @@ pub fn get_primary_monitor(outputs: &OutputMgr) -> MonitorId {
}) })
} }
pub fn get_available_monitors(outputs: &OutputMgr) -> VecDeque<MonitorId> { pub fn get_available_monitors(outputs: &OutputMgr) -> VecDeque<MonitorHandle> {
outputs.with_all(|list| { outputs.with_all(|list| {
list.iter() list.iter()
.map(|&(_, ref proxy, _)| MonitorId { .map(|&(_, ref proxy, _)| MonitorHandle {
proxy: proxy.clone(), proxy: proxy.clone(),
mgr: outputs.clone(), mgr: outputs.clone(),
}) })

View File

@@ -2,7 +2,7 @@
target_os = "netbsd", target_os = "openbsd"))] target_os = "netbsd", target_os = "openbsd"))]
pub use self::window::Window; pub use self::window::Window;
pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopSink, MonitorId}; pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopSink, MonitorHandle};
use sctk::reexports::client::protocol::wl_surface; use sctk::reexports::client::protocol::wl_surface;
use sctk::reexports::client::Proxy; use sctk::reexports::client::Proxy;

View File

@@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex, Weak};
use {CreationError, MouseCursor, WindowAttributes}; use {CreationError, MouseCursor, WindowAttributes};
use dpi::{LogicalPosition, LogicalSize}; use dpi::{LogicalPosition, LogicalSize};
use platform_impl::MonitorId as PlatformMonitorId; use platform_impl::MonitorHandle as PlatformMonitorHandle;
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow}; use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow};
use sctk::reexports::client::{Display, Proxy}; use sctk::reexports::client::{Display, Proxy};
@@ -13,7 +13,7 @@ use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as Composito
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests; use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
use sctk::output::OutputMgr; use sctk::output::OutputMgr;
use super::{make_wid, EventLoop, MonitorId, WindowId}; use super::{make_wid, EventLoop, MonitorHandle, WindowId};
use platform_impl::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor}; use platform_impl::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor};
pub struct Window { pub struct Window {
@@ -42,7 +42,7 @@ impl Window {
let window_store = evlp.store.clone(); let window_store = evlp.store.clone();
surface.implement(move |event, surface| match event { surface.implement(move |event, surface| match event {
wl_surface::Event::Enter { output } => { wl_surface::Event::Enter { output } => {
let dpi_change = list.lock().unwrap().add_output(MonitorId { let dpi_change = list.lock().unwrap().add_output(MonitorHandle {
proxy: output, proxy: output,
mgr: omgr.clone(), mgr: omgr.clone(),
}); });
@@ -111,8 +111,8 @@ impl Window {
} }
// Check for fullscreen requirements // Check for fullscreen requirements
if let Some(RootMonitorId { if let Some(RootMonitorHandle {
inner: PlatformMonitorId::Wayland(ref monitor_id), inner: PlatformMonitorHandle::Wayland(ref monitor_id),
}) = attributes.fullscreen }) = attributes.fullscreen
{ {
frame.set_fullscreen(Some(&monitor_id.proxy)); frame.set_fullscreen(Some(&monitor_id.proxy));
@@ -247,9 +247,9 @@ impl Window {
} }
} }
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
if let Some(RootMonitorId { if let Some(RootMonitorHandle {
inner: PlatformMonitorId::Wayland(ref monitor_id), inner: PlatformMonitorHandle::Wayland(ref monitor_id),
}) = monitor }) = monitor
{ {
self.frame self.frame
@@ -289,18 +289,18 @@ impl Window {
&self.surface &self.surface
} }
pub fn get_current_monitor(&self) -> MonitorId { pub fn get_current_monitor(&self) -> MonitorHandle {
// we don't know how much each monitor sees us so... // we don't know how much each monitor sees us so...
// just return the most recent one ? // just return the most recent one ?
let guard = self.monitors.lock().unwrap(); let guard = self.monitors.lock().unwrap();
guard.monitors.last().unwrap().clone() guard.monitors.last().unwrap().clone()
} }
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors(&self.outputs) get_available_monitors(&self.outputs)
} }
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor(&self.outputs) get_primary_monitor(&self.outputs)
} }
} }
@@ -412,7 +412,7 @@ impl WindowStore {
*/ */
struct MonitorList { struct MonitorList {
monitors: Vec<MonitorId> monitors: Vec<MonitorHandle>
} }
impl MonitorList { impl MonitorList {
@@ -431,7 +431,7 @@ impl MonitorList {
factor factor
} }
fn add_output(&mut self, monitor: MonitorId) -> Option<i32> { fn add_output(&mut self, monitor: MonitorHandle) -> Option<i32> {
let old_dpi = self.compute_hidpi_factor(); let old_dpi = self.compute_hidpi_factor();
let monitor_dpi = monitor.get_hidpi_factor(); let monitor_dpi = monitor.get_hidpi_factor();
self.monitors.push(monitor); self.monitors.push(monitor);

View File

@@ -9,7 +9,7 @@ mod dnd;
mod ime; mod ime;
pub mod util; pub mod util;
pub use self::monitor::MonitorId; pub use self::monitor::MonitorHandle;
pub use self::window::UnownedWindow; pub use self::window::UnownedWindow;
pub use self::xdisplay::{XConnection, XNotSupported, XError}; pub use self::xdisplay::{XConnection, XNotSupported, XError};

View File

@@ -20,7 +20,7 @@ const DISABLE_MONITOR_LIST_CACHING: bool = false;
lazy_static! { lazy_static! {
static ref XRANDR_VERSION: Mutex<Option<(c_int, c_int)>> = Mutex::default(); static ref XRANDR_VERSION: Mutex<Option<(c_int, c_int)>> = Mutex::default();
static ref MONITORS: Mutex<Option<Vec<MonitorId>>> = Mutex::default(); static ref MONITORS: Mutex<Option<Vec<MonitorHandle>>> = Mutex::default();
} }
fn version_is_at_least(major: c_int, minor: c_int) -> bool { fn version_is_at_least(major: c_int, minor: c_int) -> bool {
@@ -35,13 +35,13 @@ fn version_is_at_least(major: c_int, minor: c_int) -> bool {
} }
} }
pub fn invalidate_cached_monitor_list() -> Option<Vec<MonitorId>> { pub fn invalidate_cached_monitor_list() -> Option<Vec<MonitorHandle>> {
// We update this lazily. // We update this lazily.
(*MONITORS.lock()).take() (*MONITORS.lock()).take()
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MonitorId { pub struct MonitorHandle {
/// The actual id /// The actual id
id: u32, id: u32,
/// The name of the monitor /// The name of the monitor
@@ -58,7 +58,7 @@ pub struct MonitorId {
pub(crate) rect: util::AaRect, pub(crate) rect: util::AaRect,
} }
impl MonitorId { impl MonitorHandle {
fn from_repr( fn from_repr(
xconn: &XConnection, xconn: &XConnection,
resources: *mut XRRScreenResources, resources: *mut XRRScreenResources,
@@ -69,7 +69,7 @@ impl MonitorId {
let (name, hidpi_factor) = unsafe { xconn.get_output_info(resources, &repr) }; let (name, hidpi_factor) = unsafe { xconn.get_output_info(resources, &repr) };
let (dimensions, position) = unsafe { (repr.get_dimensions(), repr.get_position()) }; let (dimensions, position) = unsafe { (repr.get_dimensions(), repr.get_position()) };
let rect = util::AaRect::new(position, dimensions); let rect = util::AaRect::new(position, dimensions);
MonitorId { MonitorHandle {
id, id,
name, name,
hidpi_factor, hidpi_factor,
@@ -104,7 +104,7 @@ impl MonitorId {
} }
impl XConnection { impl XConnection {
pub fn get_monitor_for_window(&self, window_rect: Option<util::AaRect>) -> MonitorId { pub fn get_monitor_for_window(&self, window_rect: Option<util::AaRect>) -> MonitorHandle {
let monitors = self.get_available_monitors(); let monitors = self.get_available_monitors();
let default = monitors let default = monitors
.get(0) .get(0)
@@ -128,7 +128,7 @@ impl XConnection {
matched_monitor.to_owned() matched_monitor.to_owned()
} }
fn query_monitor_list(&self) -> Vec<MonitorId> { fn query_monitor_list(&self) -> Vec<MonitorHandle> {
unsafe { unsafe {
let root = (self.xlib.XDefaultRootWindow)(self.display); let root = (self.xlib.XDefaultRootWindow)(self.display);
// WARNING: this function is supposedly very slow, on the order of hundreds of ms. // WARNING: this function is supposedly very slow, on the order of hundreds of ms.
@@ -153,7 +153,7 @@ impl XConnection {
let monitor = monitors.offset(monitor_index as isize); let monitor = monitors.offset(monitor_index as isize);
let is_primary = (*monitor).primary != 0; let is_primary = (*monitor).primary != 0;
has_primary |= is_primary; has_primary |= is_primary;
available.push(MonitorId::from_repr( available.push(MonitorHandle::from_repr(
self, self,
resources, resources,
monitor_index as u32, monitor_index as u32,
@@ -176,7 +176,7 @@ impl XConnection {
let crtc = util::MonitorRepr::from(crtc); let crtc = util::MonitorRepr::from(crtc);
let is_primary = crtc.get_output() == primary; let is_primary = crtc.get_output() == primary;
has_primary |= is_primary; has_primary |= is_primary;
available.push(MonitorId::from_repr( available.push(MonitorHandle::from_repr(
self, self,
resources, resources,
crtc_id as u32, crtc_id as u32,
@@ -201,7 +201,7 @@ impl XConnection {
} }
} }
pub fn get_available_monitors(&self) -> Vec<MonitorId> { pub fn get_available_monitors(&self) -> Vec<MonitorHandle> {
let mut monitors_lock = MONITORS.lock(); let mut monitors_lock = MONITORS.lock();
(*monitors_lock) (*monitors_lock)
.as_ref() .as_ref()
@@ -217,7 +217,7 @@ impl XConnection {
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
self.get_available_monitors() self.get_available_monitors()
.into_iter() .into_iter()
.find(|monitor| monitor.primary) .find(|monitor| monitor.primary)

View File

@@ -10,10 +10,10 @@ use parking_lot::Mutex;
use {Icon, MouseCursor, WindowAttributes}; use {Icon, MouseCursor, WindowAttributes};
use CreationError::{self, OsError}; use CreationError::{self, OsError};
use dpi::{LogicalPosition, LogicalSize}; use dpi::{LogicalPosition, LogicalSize};
use platform_impl::MonitorId as PlatformMonitorId; use platform_impl::MonitorHandle as PlatformMonitorHandle;
use platform_impl::PlatformSpecificWindowBuilderAttributes; use platform_impl::PlatformSpecificWindowBuilderAttributes;
use platform_impl::x11::MonitorId as X11MonitorId; use platform_impl::x11::MonitorHandle as X11MonitorHandle;
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
use super::{ffi, util, ImeSender, XConnection, XError, WindowId, EventLoop}; use super::{ffi, util, ImeSender, XConnection, XError, WindowId, EventLoop};
@@ -35,7 +35,7 @@ pub struct SharedState {
pub inner_position: Option<(i32, i32)>, pub inner_position: Option<(i32, i32)>,
pub inner_position_rel_parent: Option<(i32, i32)>, pub inner_position_rel_parent: Option<(i32, i32)>,
pub guessed_dpi: Option<f64>, pub guessed_dpi: Option<f64>,
pub last_monitor: Option<X11MonitorId>, pub last_monitor: Option<X11MonitorHandle>,
pub dpi_adjusted: Option<(f64, f64)>, pub dpi_adjusted: Option<(f64, f64)>,
// Used to restore position after exiting fullscreen. // Used to restore position after exiting fullscreen.
pub restore_position: Option<(i32, i32)>, pub restore_position: Option<(i32, i32)>,
@@ -511,7 +511,7 @@ impl UnownedWindow {
self.set_netwm(fullscreen.into(), (fullscreen_atom as c_long, 0, 0, 0)) self.set_netwm(fullscreen.into(), (fullscreen_atom as c_long, 0, 0, 0))
} }
fn set_fullscreen_inner(&self, monitor: Option<RootMonitorId>) -> util::Flusher { fn set_fullscreen_inner(&self, monitor: Option<RootMonitorHandle>) -> util::Flusher {
match monitor { match monitor {
None => { None => {
let flusher = self.set_fullscreen_hint(false); let flusher = self.set_fullscreen_hint(false);
@@ -520,7 +520,7 @@ impl UnownedWindow {
} }
flusher flusher
}, },
Some(RootMonitorId { inner: PlatformMonitorId::X(monitor) }) => { Some(RootMonitorHandle { inner: PlatformMonitorHandle::X(monitor) }) => {
let window_position = self.get_position_physical(); let window_position = self.get_position_physical();
self.shared_state.lock().restore_position = window_position; self.shared_state.lock().restore_position = window_position;
let monitor_origin: (i32, i32) = monitor.get_position().into(); let monitor_origin: (i32, i32) = monitor.get_position().into();
@@ -532,7 +532,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
self.set_fullscreen_inner(monitor) self.set_fullscreen_inner(monitor)
.flush() .flush()
.expect("Failed to change window fullscreen state"); .expect("Failed to change window fullscreen state");
@@ -549,7 +549,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> X11MonitorId { pub fn get_current_monitor(&self) -> X11MonitorHandle {
let monitor = self.shared_state let monitor = self.shared_state
.lock() .lock()
.last_monitor .last_monitor
@@ -563,11 +563,11 @@ impl UnownedWindow {
}) })
} }
pub fn get_available_monitors(&self) -> Vec<X11MonitorId> { pub fn get_available_monitors(&self) -> Vec<X11MonitorHandle> {
self.xconn.get_available_monitors() self.xconn.get_available_monitors()
} }
pub fn get_primary_monitor(&self) -> X11MonitorId { pub fn get_primary_monitor(&self) -> X11MonitorHandle {
self.xconn.get_primary_monitor() self.xconn.get_primary_monitor()
} }

View File

@@ -1,7 +1,7 @@
#![cfg(target_os = "macos")] #![cfg(target_os = "macos")]
pub use self::event_loop::{EventLoop, Proxy as EventLoopProxy}; pub use self::event_loop::{EventLoop, Proxy as EventLoopProxy};
pub use self::monitor::MonitorId; pub use self::monitor::MonitorHandle;
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2}; pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
use std::sync::Arc; use std::sync::Arc;

View File

@@ -11,13 +11,13 @@ use super::EventLoop;
use super::window::{IdRef, Window2}; use super::window::{IdRef, Window2};
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct MonitorId(CGDirectDisplayID); pub struct MonitorHandle(CGDirectDisplayID);
fn get_available_monitors() -> VecDeque<MonitorId> { fn get_available_monitors() -> VecDeque<MonitorHandle> {
if let Ok(displays) = CGDisplay::active_displays() { if let Ok(displays) = CGDisplay::active_displays() {
let mut monitors = VecDeque::with_capacity(displays.len()); let mut monitors = VecDeque::with_capacity(displays.len());
for d in displays { for d in displays {
monitors.push_back(MonitorId(d)); monitors.push_back(MonitorHandle(d));
} }
monitors monitors
} else { } else {
@@ -25,44 +25,44 @@ fn get_available_monitors() -> VecDeque<MonitorId> {
} }
} }
pub fn get_primary_monitor() -> MonitorId { pub fn get_primary_monitor() -> MonitorHandle {
let id = MonitorId(CGDisplay::main().id); let id = MonitorHandle(CGDisplay::main().id);
id id
} }
impl EventLoop { impl EventLoop {
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors() get_available_monitors()
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor() get_primary_monitor()
} }
pub fn make_monitor_from_display(id: CGDirectDisplayID) -> MonitorId { pub fn make_monitor_from_display(id: CGDirectDisplayID) -> MonitorHandle {
let id = MonitorId(id); let id = MonitorHandle(id);
id id
} }
} }
impl Window2 { impl Window2 {
#[inline] #[inline]
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors() get_available_monitors()
} }
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor() get_primary_monitor()
} }
} }
impl fmt::Debug for MonitorId { impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Debug)] #[derive(Debug)]
struct MonitorId { struct MonitorHandle {
name: Option<String>, name: Option<String>,
native_identifier: u32, native_identifier: u32,
dimensions: PhysicalSize, dimensions: PhysicalSize,
@@ -70,7 +70,7 @@ impl fmt::Debug for MonitorId {
hidpi_factor: f64, hidpi_factor: f64,
} }
let monitor_id_proxy = MonitorId { let monitor_id_proxy = MonitorHandle {
name: self.get_name(), name: self.get_name(),
native_identifier: self.get_native_identifier(), native_identifier: self.get_native_identifier(),
dimensions: self.get_dimensions(), dimensions: self.get_dimensions(),
@@ -82,9 +82,9 @@ impl fmt::Debug for MonitorId {
} }
} }
impl MonitorId { impl MonitorHandle {
pub fn get_name(&self) -> Option<String> { pub fn get_name(&self) -> Option<String> {
let MonitorId(display_id) = *self; let MonitorHandle(display_id) = *self;
let screen_num = CGDisplay::new(display_id).model_number(); let screen_num = CGDisplay::new(display_id).model_number();
Some(format!("Monitor #{}", screen_num)) Some(format!("Monitor #{}", screen_num))
} }
@@ -95,7 +95,7 @@ impl MonitorId {
} }
pub fn get_dimensions(&self) -> PhysicalSize { pub fn get_dimensions(&self) -> PhysicalSize {
let MonitorId(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();
let width = display.pixels_wide(); let width = display.pixels_wide();

View File

@@ -44,7 +44,7 @@ use os::macos::{ActivationPolicy, WindowExt};
use platform_impl::platform::{ffi, util}; use platform_impl::platform::{ffi, util};
use platform_impl::platform::event_loop::{EventLoop, Shared}; use platform_impl::platform::event_loop::{EventLoop, Shared};
use platform_impl::platform::view::{new_view, set_ime_spot}; use platform_impl::platform::view::{new_view, set_ime_spot};
use window::MonitorId as RootMonitorId; use window::MonitorHandle as RootMonitorHandle;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Id(pub usize); pub struct Id(pub usize);
@@ -537,13 +537,13 @@ pub struct Window2 {
unsafe impl Send for Window2 {} unsafe impl Send for Window2 {}
unsafe impl Sync for Window2 {} unsafe impl Sync for Window2 {}
unsafe fn get_current_monitor(window: id) -> RootMonitorId { unsafe fn get_current_monitor(window: id) -> RootMonitorHandle {
let screen: id = msg_send![window, screen]; let screen: id = msg_send![window, screen];
let desc = NSScreen::deviceDescription(screen); let desc = NSScreen::deviceDescription(screen);
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber")); let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
let value = NSDictionary::valueForKey_(desc, *key); let value = NSDictionary::valueForKey_(desc, *key);
let display_id = msg_send![value, unsignedIntegerValue]; let display_id = msg_send![value, unsignedIntegerValue];
RootMonitorId { inner: EventLoop::make_monitor_from_display(display_id) } RootMonitorHandle { inner: EventLoop::make_monitor_from_display(display_id) }
} }
impl Drop for Window2 { impl Drop for Window2 {
@@ -1084,7 +1084,7 @@ impl Window2 {
#[inline] #[inline]
/// TODO: Right now set_fullscreen do not work on switching monitors /// TODO: Right now set_fullscreen do not work on switching monitors
/// in fullscreen mode /// in fullscreen mode
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
let state = &self.delegate.state; let state = &self.delegate.state;
let current = { let current = {
let win_attribs = state.win_attribs.borrow_mut(); let win_attribs = state.win_attribs.borrow_mut();
@@ -1186,7 +1186,7 @@ impl Window2 {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
unsafe { unsafe {
self::get_current_monitor(*self.window) self::get_current_monitor(*self.window)
} }

View File

@@ -41,7 +41,7 @@ use winapi::um::{winuser, winbase, ole2, processthreadsapi, commctrl, libloadera
use winapi::um::winnt::{LONG, LPCSTR, SHORT}; use winapi::um::winnt::{LONG, LPCSTR, SHORT};
use window::WindowId as RootWindowId; use window::WindowId as RootWindowId;
use monitor::MonitorId; use monitor::MonitorHandle;
use event_loop::{ControlFlow, EventLoop as RootEventLoop, EventLoopClosed}; use event_loop::{ControlFlow, EventLoop as RootEventLoop, EventLoopClosed};
use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use event::{DeviceEvent, Touch, TouchPhase, StartCause, KeyboardInput, Event, WindowEvent}; use event::{DeviceEvent, Touch, TouchPhase, StartCause, KeyboardInput, Event, WindowEvent};
@@ -91,7 +91,7 @@ pub struct WindowState {
// This is different from the value in `SavedWindowInfo`! That one represents the DPI saved upon entering // This is different from the value in `SavedWindowInfo`! That one represents the DPI saved upon entering
// fullscreen. This will always be the most recent DPI for the window. // fullscreen. This will always be the most recent DPI for the window.
pub dpi_factor: f64, pub dpi_factor: f64,
pub fullscreen: Option<MonitorId>, pub fullscreen: Option<MonitorHandle>,
pub window_icon: Option<WinIcon>, pub window_icon: Option<WinIcon>,
pub taskbar_icon: Option<WinIcon>, pub taskbar_icon: Option<WinIcon>,
pub decorations: bool, pub decorations: bool,

View File

@@ -4,7 +4,7 @@ use winapi;
use winapi::shared::windef::HWND; use winapi::shared::windef::HWND;
pub use self::event_loop::{EventLoop, EventLoopProxy}; pub use self::event_loop::{EventLoop, EventLoopProxy};
pub use self::monitor::MonitorId; pub use self::monitor::MonitorHandle;
pub use self::window::Window; pub use self::window::Window;
use window::Icon; use window::Icon;

View File

@@ -11,9 +11,9 @@ use dpi::{PhysicalPosition, PhysicalSize};
use platform_impl::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi}; use platform_impl::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi};
use platform_impl::platform::window::Window; use platform_impl::platform::window::Window;
/// Win32 implementation of the main `MonitorId` object. /// Win32 implementation of the main `MonitorHandle` object.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MonitorId { pub struct MonitorHandle {
/// Monitor handle. /// Monitor handle.
hmonitor: HMonitor, hmonitor: HMonitor,
/// The system name of the monitor. /// The system name of the monitor.
@@ -45,13 +45,13 @@ unsafe extern "system" fn monitor_enum_proc(
_place: LPRECT, _place: LPRECT,
data: LPARAM, data: LPARAM,
) -> BOOL { ) -> BOOL {
let monitors = data as *mut VecDeque<MonitorId>; let monitors = data as *mut VecDeque<MonitorHandle>;
(*monitors).push_back(MonitorId::from_hmonitor(hmonitor)); (*monitors).push_back(MonitorHandle::from_hmonitor(hmonitor));
TRUE // continue enumeration TRUE // continue enumeration
} }
pub fn get_available_monitors() -> VecDeque<MonitorId> { pub fn get_available_monitors() -> VecDeque<MonitorHandle> {
let mut monitors: VecDeque<MonitorId> = VecDeque::new(); let mut monitors: VecDeque<MonitorHandle> = VecDeque::new();
unsafe { unsafe {
winuser::EnumDisplayMonitors( winuser::EnumDisplayMonitors(
ptr::null_mut(), ptr::null_mut(),
@@ -63,38 +63,38 @@ pub fn get_available_monitors() -> VecDeque<MonitorId> {
monitors monitors
} }
pub fn get_primary_monitor() -> MonitorId { pub fn get_primary_monitor() -> MonitorHandle {
const ORIGIN: POINT = POINT { x: 0, y: 0 }; const ORIGIN: POINT = POINT { x: 0, y: 0 };
let hmonitor = unsafe { let hmonitor = unsafe {
winuser::MonitorFromPoint(ORIGIN, winuser::MONITOR_DEFAULTTOPRIMARY) winuser::MonitorFromPoint(ORIGIN, winuser::MONITOR_DEFAULTTOPRIMARY)
}; };
MonitorId::from_hmonitor(hmonitor) MonitorHandle::from_hmonitor(hmonitor)
} }
pub fn get_current_monitor(hwnd: HWND) -> MonitorId { pub fn get_current_monitor(hwnd: HWND) -> MonitorHandle {
let hmonitor = unsafe { let hmonitor = unsafe {
winuser::MonitorFromWindow(hwnd, winuser::MONITOR_DEFAULTTONEAREST) winuser::MonitorFromWindow(hwnd, winuser::MONITOR_DEFAULTTONEAREST)
}; };
MonitorId::from_hmonitor(hmonitor) MonitorHandle::from_hmonitor(hmonitor)
} }
impl<T> EventLoop<T> { impl<T> EventLoop<T> {
// TODO: Investigate opportunities for caching // TODO: Investigate opportunities for caching
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors() get_available_monitors()
} }
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor() get_primary_monitor()
} }
} }
impl Window { impl Window {
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> { pub fn get_available_monitors(&self) -> VecDeque<MonitorHandle> {
get_available_monitors() get_available_monitors()
} }
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
get_primary_monitor() get_primary_monitor()
} }
} }
@@ -115,7 +115,7 @@ fn get_monitor_info(hmonitor: HMONITOR) -> Result<winuser::MONITORINFOEXW, util:
} }
} }
impl MonitorId { impl MonitorHandle {
pub(crate) fn from_hmonitor(hmonitor: HMONITOR) -> Self { pub(crate) fn from_hmonitor(hmonitor: HMONITOR) -> Self {
let monitor_info = get_monitor_info(hmonitor).expect("`GetMonitorInfoW` failed"); let monitor_info = get_monitor_info(hmonitor).expect("`GetMonitorInfoW` failed");
let place = monitor_info.rcMonitor; let place = monitor_info.rcMonitor;
@@ -123,7 +123,7 @@ impl MonitorId {
(place.right - place.left) as u32, (place.right - place.left) as u32,
(place.bottom - place.top) as u32, (place.bottom - place.top) as u32,
); );
MonitorId { MonitorHandle {
hmonitor: HMonitor(hmonitor), hmonitor: HMonitor(hmonitor),
monitor_name: util::wchar_ptr_to_string(monitor_info.szDevice.as_ptr()), monitor_name: util::wchar_ptr_to_string(monitor_info.szDevice.as_ptr()),
primary: util::has_flag(monitor_info.dwFlags, winuser::MONITORINFOF_PRIMARY), primary: util::has_flag(monitor_info.dwFlags, winuser::MONITORINFOF_PRIMARY),

View File

@@ -20,7 +20,7 @@ use winapi::um::winnt::{LONG, LPCWSTR};
use window::{CreationError, Icon, WindowAttributes, MouseCursor}; use window::{CreationError, Icon, WindowAttributes, MouseCursor};
use dpi::{LogicalPosition, LogicalSize, PhysicalSize}; use dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use monitor::MonitorId as RootMonitorId; use monitor::MonitorHandle as RootMonitorHandle;
use platform_impl::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId}; use platform_impl::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId};
use platform_impl::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi}; use platform_impl::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi};
use platform_impl::platform::event_loop::{self, EventLoop, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID, REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID}; use platform_impl::platform::event_loop::{self, EventLoop, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID, REQUEST_REDRAW_NO_NEWEVENTS_MSG_ID};
@@ -606,11 +606,11 @@ impl Window {
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorHandle>) {
let mut window_state_lock = self.window_state.lock(); let mut window_state_lock = self.window_state.lock();
unsafe { unsafe {
let monitor_rect = monitor.as_ref() let monitor_rect = monitor.as_ref()
.map(|RootMonitorId{ ref inner }| { .map(|RootMonitorHandle{ ref inner }| {
let (x, y): (i32, i32) = inner.get_position().into(); let (x, y): (i32, i32) = inner.get_position().into();
let (width, height): (u32, u32) = inner.get_dimensions().into(); let (width, height): (u32, u32) = inner.get_dimensions().into();
(x, y, width, height) (x, y, width, height)
@@ -772,8 +772,8 @@ impl Window {
} }
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorHandle {
RootMonitorId { RootMonitorHandle {
inner: monitor::get_current_monitor(self.window.0), inner: monitor::get_current_monitor(self.window.0),
} }
} }

View File

@@ -3,7 +3,7 @@ use std::{fmt, error};
use platform_impl; use platform_impl;
use event_loop::EventLoop; use event_loop::EventLoop;
use monitor::{AvailableMonitorsIter, MonitorId}; use monitor::{AvailableMonitorsIter, MonitorHandle};
use dpi::{LogicalPosition, LogicalSize}; use dpi::{LogicalPosition, LogicalSize};
pub use icon::*; pub use icon::*;
@@ -93,7 +93,7 @@ pub struct WindowAttributes {
/// Whether the window should be set as fullscreen upon creation. /// Whether the window should be set as fullscreen upon creation.
/// ///
/// The default is `None`. /// The default is `None`.
pub fullscreen: Option<MonitorId>, pub fullscreen: Option<MonitorHandle>,
/// The title of the window in the title bar. /// The title of the window in the title bar.
/// ///
@@ -210,10 +210,10 @@ impl WindowBuilder {
self self
} }
/// Sets the window fullscreen state. None means a normal window, Some(MonitorId) /// Sets the window fullscreen state. None means a normal window, Some(MonitorHandle)
/// means a fullscreen window on that specific monitor /// means a fullscreen window on that specific monitor
#[inline] #[inline]
pub fn with_fullscreen(mut self, monitor: Option<MonitorId>) -> WindowBuilder { pub fn with_fullscreen(mut self, monitor: Option<MonitorHandle>) -> WindowBuilder {
self.window.fullscreen = monitor; self.window.fullscreen = monitor;
self self
} }
@@ -521,7 +521,7 @@ impl Window {
/// Sets the window to fullscreen or back /// Sets the window to fullscreen or back
#[inline] #[inline]
pub fn set_fullscreen(&self, monitor: Option<MonitorId>) { pub fn set_fullscreen(&self, monitor: Option<MonitorHandle>) {
self.window.set_fullscreen(monitor) self.window.set_fullscreen(monitor)
} }
@@ -558,7 +558,7 @@ impl Window {
/// Returns the monitor on which the window currently resides /// Returns the monitor on which the window currently resides
#[inline] #[inline]
pub fn get_current_monitor(&self) -> MonitorId { pub fn get_current_monitor(&self) -> MonitorHandle {
self.window.get_current_monitor() self.window.get_current_monitor()
} }
@@ -575,8 +575,8 @@ impl Window {
/// ///
/// This is the same as `EventLoop::get_primary_monitor`, and is provided for convenience. /// This is the same as `EventLoop::get_primary_monitor`, and is provided for convenience.
#[inline] #[inline]
pub fn get_primary_monitor(&self) -> MonitorId { pub fn get_primary_monitor(&self) -> MonitorHandle {
MonitorId { inner: self.window.get_primary_monitor() } MonitorHandle { inner: self.window.get_primary_monitor() }
} }
/// Returns an identifier unique to the window. /// Returns an identifier unique to the window.

View File

@@ -19,5 +19,5 @@ fn ids_send() {
// ensures that the various `..Id` types implement `Send` // ensures that the various `..Id` types implement `Send`
needs_send::<winit::window::WindowId>(); needs_send::<winit::window::WindowId>();
needs_send::<winit::event::DeviceId>(); needs_send::<winit::event::DeviceId>();
needs_send::<winit::monitor::MonitorId>(); needs_send::<winit::monitor::MonitorHandle>();
} }