expose platform-native monitor identifier

This commit is contained in:
Ryan Stewart 2015-03-16 13:52:58 -07:00
parent 0fa5e541e8
commit 9914d826b8
6 changed files with 43 additions and 1 deletions

View file

@ -14,6 +14,7 @@ use std::collections::VecDeque;
use Api;
use BuilderAttribs;
use GlRequest;
use NativeMonitorID;
pub struct Window {
display: ffi::egl::types::EGLDisplay,
@ -41,6 +42,10 @@ impl MonitorID {
Some("Primary".to_string())
}
pub fn get_native_identifier(&self) -> NativeMonitorID {
NativeMonitorID::Unavailable
}
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()
}

View file

@ -1,5 +1,6 @@
use core_graphics::display;
use std::collections::VecDeque;
use window::NativeMonitorID;
pub struct MonitorID(u32);
@ -35,6 +36,11 @@ impl MonitorID {
Some(format!("Monitor #{}", screen_num))
}
pub fn get_native_identifier(&self) -> NativeMonitorID {
let MonitorID(display_id) = *self;
NativeMonitorID::Numeric(display_id)
}
pub fn get_dimensions(&self) -> (u32, u32) {
let MonitorID(display_id) = *self;
let dimension = unsafe {

View file

@ -50,7 +50,7 @@ pub use headless::{HeadlessRendererBuilder, HeadlessContext};
#[cfg(feature = "window")]
pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator};
#[cfg(feature = "window")]
pub use window::{AvailableMonitorsIter, MonitorID, get_available_monitors, get_primary_monitor};
pub use window::{AvailableMonitorsIter, NativeMonitorID, MonitorID, get_available_monitors, get_primary_monitor};
#[cfg(all(not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android")))]
use this_platform_is_not_supported;

View file

@ -3,6 +3,8 @@ use user32;
use std::collections::VecDeque;
use NativeMonitorID;
/// Win32 implementation of the main `MonitorID` object.
pub struct MonitorID {
/// The system name of the monitor.
@ -113,6 +115,11 @@ impl MonitorID {
Some(self.readable_name.clone())
}
/// See the docs of the crate root file.
pub fn get_native_identifier(&self) -> NativeMonitorID {
NativeMonitorID::Name(self.readable_name.clone())
}
/// See the docs if the crate root file.
pub fn get_dimensions(&self) -> (u32, u32) {
// TODO: retreive the dimensions every time this is called

View file

@ -500,6 +500,19 @@ pub fn get_primary_monitor() -> MonitorID {
MonitorID(winimpl::get_primary_monitor())
}
/// Native platform identifier for a monitor. Different platforms use fundamentally different types
/// to represent a monitor ID.
pub enum NativeMonitorID {
/// Cocoa and X11 use a numeric identifier to represent a monitor.
Numeric(u32),
/// Win32 uses a Unicode string to represent a monitor.
Name(String),
/// Other platforms (Android) don't support monitor identification.
Unavailable
}
/// Identifier for a monitor.
pub struct MonitorID(winimpl::MonitorID);
@ -510,6 +523,12 @@ impl MonitorID {
id.get_name()
}
/// Returns the native platform identifier for this monitor.
pub fn get_native_identifier(&self) -> NativeMonitorID {
let &MonitorID(ref id) = self;
id.get_native_identifier()
}
/// Returns the number of pixels currently displayed on the monitor.
pub fn get_dimensions(&self) -> (u32, u32) {
let &MonitorID(ref id) = self;

View file

@ -43,6 +43,11 @@ impl MonitorID {
Some(format!("Monitor #{}", screen_num))
}
pub fn get_native_identifier(&self) -> NativeMonitorID {
let MonitorID(screen_num) = *self;
NativeMonitorID::Numeric(screen_num)
}
pub fn get_dimensions(&self) -> (u32, u32) {
let dimensions = unsafe {
let display = ffi::XOpenDisplay(ptr::null());