2014-11-05 04:03:38 +11:00
|
|
|
use core_graphics::display;
|
2015-02-21 23:59:37 +11:00
|
|
|
use std::collections::VecDeque;
|
2015-03-19 08:16:35 +11:00
|
|
|
use native_monitor::NativeMonitorId;
|
2014-11-05 04:03:38 +11:00
|
|
|
|
|
|
|
pub struct MonitorID(u32);
|
|
|
|
|
2015-02-21 23:59:37 +11:00
|
|
|
pub fn get_available_monitors() -> VecDeque<MonitorID> {
|
|
|
|
let mut monitors = VecDeque::new();
|
2014-11-05 04:03:38 +11:00
|
|
|
unsafe {
|
|
|
|
let max_displays = 10u32;
|
2015-01-10 20:56:47 +11:00
|
|
|
let mut active_displays = [0u32; 10];
|
2014-11-05 04:03:38 +11:00
|
|
|
let mut display_count = 0;
|
|
|
|
display::CGGetActiveDisplayList(max_displays,
|
|
|
|
&mut active_displays[0],
|
|
|
|
&mut display_count);
|
2015-03-23 23:03:07 +11:00
|
|
|
for i in 0..display_count as usize {
|
2015-01-02 18:09:16 +11:00
|
|
|
monitors.push_back(MonitorID(active_displays[i]));
|
2014-11-05 04:03:38 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2015-03-19 08:16:35 +11:00
|
|
|
pub fn get_native_identifier(&self) -> NativeMonitorId {
|
2015-03-17 07:52:58 +11:00
|
|
|
let MonitorID(display_id) = *self;
|
2015-03-19 08:16:35 +11:00
|
|
|
NativeMonitorId::Numeric(display_id)
|
2015-03-17 07:52:58 +11:00
|
|
|
}
|
|
|
|
|
2015-01-16 06:20:52 +11:00
|
|
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
2014-11-05 04:03:38 +11:00
|
|
|
let MonitorID(display_id) = *self;
|
|
|
|
let dimension = unsafe {
|
|
|
|
let height = display::CGDisplayPixelsHigh(display_id);
|
|
|
|
let width = display::CGDisplayPixelsWide(display_id);
|
2015-01-16 06:20:52 +11:00
|
|
|
(width as u32, height as u32)
|
2014-11-05 04:03:38 +11:00
|
|
|
};
|
|
|
|
dimension
|
|
|
|
}
|
|
|
|
}
|