2015-02-22 00:40:23 +11:00
|
|
|
use std::collections::VecDeque;
|
2015-05-17 19:19:06 +10:00
|
|
|
use std::sync::Arc;
|
2014-09-19 23:42:47 +10:00
|
|
|
|
2015-05-17 19:19:06 +10:00
|
|
|
use super::XConnection;
|
|
|
|
use native_monitor::NativeMonitorId;
|
2014-09-19 23:42:47 +10:00
|
|
|
|
2015-05-17 19:19:06 +10:00
|
|
|
pub struct MonitorID(pub Arc<XConnection>, pub u32);
|
2015-05-07 21:14:09 +10:00
|
|
|
|
2015-05-17 19:19:06 +10:00
|
|
|
pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorID> {
|
|
|
|
let nb_monitors = unsafe { (x.xlib.XScreenCount)(x.display) };
|
2014-09-19 23:42:47 +10:00
|
|
|
|
2015-02-22 00:40:23 +11:00
|
|
|
let mut monitors = VecDeque::new();
|
2015-05-17 19:19:06 +10:00
|
|
|
monitors.extend((0 .. nb_monitors).map(|i| MonitorID(x.clone(), i as u32)));
|
2015-01-02 18:09:16 +11:00
|
|
|
monitors
|
2014-09-19 23:42:47 +10:00
|
|
|
}
|
|
|
|
|
2015-05-17 19:19:06 +10:00
|
|
|
pub fn get_primary_monitor(x: &Arc<XConnection>) -> MonitorID {
|
|
|
|
let primary_monitor = unsafe { (x.xlib.XDefaultScreen)(x.display) };
|
|
|
|
MonitorID(x.clone(), primary_monitor as u32)
|
2014-09-19 23:42:47 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MonitorID {
|
|
|
|
pub fn get_name(&self) -> Option<String> {
|
2015-05-17 19:19:06 +10:00
|
|
|
let MonitorID(_, screen_num) = *self;
|
2014-09-20 03:57:52 +10:00
|
|
|
Some(format!("Monitor #{}", screen_num))
|
2014-09-19 23:42:47 +10:00
|
|
|
}
|
|
|
|
|
2015-03-19 08:16:35 +11:00
|
|
|
pub fn get_native_identifier(&self) -> NativeMonitorId {
|
2015-05-17 19:19:06 +10:00
|
|
|
NativeMonitorId::Numeric(self.1)
|
2015-03-17 07:52:58 +11:00
|
|
|
}
|
|
|
|
|
2015-01-13 23:21:36 +11:00
|
|
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
2015-05-17 19:19:06 +10:00
|
|
|
let screen = unsafe { (self.0.xlib.XScreenOfDisplay)(self.0.display, self.1 as i32) };
|
|
|
|
let width = unsafe { (self.0.xlib.XWidthOfScreen)(screen) };
|
|
|
|
let height = unsafe { (self.0.xlib.XHeightOfScreen)(screen) };
|
|
|
|
(width as u32, height as u32)
|
2014-09-19 23:42:47 +10:00
|
|
|
}
|
|
|
|
}
|