winit/src/osx/monitor.rs
Ty Overby a698146943 Change the way that events are represented.
The bulk of this commit is changing instances of Vec to RingBuf which is
optimized for the push_back() / pop_front() strategy that is used
internaly in the event system.

The glutin custom iterators are now just wrappers around the RingBuf
iterator type.  This will bring the running time of iterator traversal from
O(n^2) to O(n) because shifting-on-delete won't be performed.
2015-01-01 23:44:02 -08:00

47 lines
1.4 KiB
Rust

use core_graphics::display;
use std::collections::RingBuf;
pub struct MonitorID(u32);
pub fn get_available_monitors() -> Vec<MonitorID> {
let mut monitors = RingBuf::new();
unsafe {
let max_displays = 10u32;
let mut active_displays = [0u32, ..10];
let mut display_count = 0;
display::CGGetActiveDisplayList(max_displays,
&mut active_displays[0],
&mut display_count);
for i in range(0u, display_count as uint) {
monitors.push_back(MonitorID(active_displays[i]));
}
}
monitors
}
pub fn get_primary_monitor() -> MonitorID {
let id = unsafe {
MonitorID(display::CGMainDisplayID())
};
id
}
impl MonitorID {
pub fn get_name(&self) -> Option<String> {
let MonitorID(display_id) = *self;
let screen_num = unsafe {
display::CGDisplayModelNumber(display_id)
};
Some(format!("Monitor #{}", screen_num))
}
pub fn get_dimensions(&self) -> (uint, uint) {
let MonitorID(display_id) = *self;
let dimension = unsafe {
let height = display::CGDisplayPixelsHigh(display_id);
let width = display::CGDisplayPixelsWide(display_id);
(width as uint, height as uint)
};
dimension
}
}