2014-11-04 18:03:38 +01:00
|
|
|
use core_graphics::display;
|
2015-02-21 23:59:37 +11:00
|
|
|
use std::collections::VecDeque;
|
2017-09-01 11:04:57 +02:00
|
|
|
use super::EventsLoop;
|
2014-11-04 18:03:38 +01:00
|
|
|
|
2015-07-19 13:53:40 +02:00
|
|
|
#[derive(Clone)]
|
2015-09-24 09:11:59 +02:00
|
|
|
pub struct MonitorId(u32);
|
2014-11-04 18:03:38 +01:00
|
|
|
|
2017-09-01 11:04:57 +02:00
|
|
|
impl EventsLoop {
|
|
|
|
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
|
|
|
|
let mut monitors = VecDeque::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 0..display_count as usize {
|
|
|
|
|
monitors.push_back(MonitorId(active_displays[i]));
|
|
|
|
|
}
|
2014-11-04 18:03:38 +01:00
|
|
|
}
|
2017-09-01 11:04:57 +02:00
|
|
|
monitors
|
2014-11-04 18:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-01 11:04:57 +02:00
|
|
|
#[inline]
|
|
|
|
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
|
|
|
|
let id = unsafe { MonitorId(display::CGMainDisplayID()) };
|
|
|
|
|
id
|
|
|
|
|
}
|
2014-11-04 18:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-24 09:11:59 +02:00
|
|
|
impl MonitorId {
|
2014-11-04 18:03:38 +01:00
|
|
|
pub fn get_name(&self) -> Option<String> {
|
2015-09-24 09:11:59 +02:00
|
|
|
let MonitorId(display_id) = *self;
|
2016-12-13 07:28:30 -06:00
|
|
|
let screen_num = unsafe { display::CGDisplayModelNumber(display_id) };
|
2014-11-04 18:03:38 +01:00
|
|
|
Some(format!("Monitor #{}", screen_num))
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 14:42:05 +02:00
|
|
|
#[inline]
|
2017-08-30 08:49:18 +02:00
|
|
|
pub fn get_native_identifier(&self) -> u32 {
|
|
|
|
|
self.0
|
2015-03-16 13:52:58 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-15 20:20:52 +01:00
|
|
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
2015-09-24 09:11:59 +02:00
|
|
|
let MonitorId(display_id) = *self;
|
2014-11-04 18:03:38 +01:00
|
|
|
let dimension = unsafe {
|
|
|
|
|
let height = display::CGDisplayPixelsHigh(display_id);
|
|
|
|
|
let width = display::CGDisplayPixelsWide(display_id);
|
2015-01-15 20:20:52 +01:00
|
|
|
(width as u32, height as u32)
|
2014-11-04 18:03:38 +01:00
|
|
|
};
|
|
|
|
|
dimension
|
|
|
|
|
}
|
2017-09-07 09:33:46 +01:00
|
|
|
|
|
|
|
|
#[inline]
|
2017-10-19 20:08:05 +03:00
|
|
|
pub fn get_position(&self) -> (i32, i32) {
|
2017-09-07 09:33:46 +01:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
2017-10-17 14:56:38 +03:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn get_hidpi_factor(&self) -> f32 {
|
|
|
|
|
1.0
|
|
|
|
|
}
|
2014-11-04 18:03:38 +01:00
|
|
|
}
|