diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-05-18 09:42:28 +0200 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-05-18 09:42:28 +0200 |
commit | ff829f7d9d8441569d91936bef5cf3bbc646ef43 (patch) | |
tree | 6d5c67882424ce84aeb5338b555c86f1f760d155 /src/api/x11/monitor.rs | |
parent | 7fe85cbc4931c8d81b0e363eeb90686d8afc8ed8 (diff) | |
parent | 3376332a851e16801a4f27347c8d6170c9008e73 (diff) | |
download | glutin-ff829f7d9d8441569d91936bef5cf3bbc646ef43.tar.gz glutin-ff829f7d9d8441569d91936bef5cf3bbc646ef43.zip |
Merge pull request #455 from tomaka/x-rework
Rework the X implementation to use only one X connection
Diffstat (limited to 'src/api/x11/monitor.rs')
-rw-r--r-- | src/api/x11/monitor.rs | 66 |
1 files changed, 16 insertions, 50 deletions
diff --git a/src/api/x11/monitor.rs b/src/api/x11/monitor.rs index a563d2e..d556930 100644 --- a/src/api/x11/monitor.rs +++ b/src/api/x11/monitor.rs @@ -1,72 +1,38 @@ -use std::ptr; use std::collections::VecDeque; -use super::ffi; -use super::ensure_thread_init; -use native_monitor::NativeMonitorId; +use std::sync::Arc; -pub struct MonitorID(pub u32); +use super::XConnection; +use native_monitor::NativeMonitorId; -pub fn get_available_monitors() -> VecDeque<MonitorID> { - let xlib = ffi::Xlib::open().unwrap(); // FIXME: gracious handling +pub struct MonitorID(pub Arc<XConnection>, pub u32); - ensure_thread_init(&xlib); - let nb_monitors = unsafe { - let display = (xlib.XOpenDisplay)(ptr::null()); - if display.is_null() { - panic!("get_available_monitors failed"); - } - let nb_monitors = (xlib.XScreenCount)(display); - (xlib.XCloseDisplay)(display); - nb_monitors - }; +pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorID> { + let nb_monitors = unsafe { (x.xlib.XScreenCount)(x.display) }; let mut monitors = VecDeque::new(); - monitors.extend((0..nb_monitors).map(|i| MonitorID(i as u32))); + monitors.extend((0 .. nb_monitors).map(|i| MonitorID(x.clone(), i as u32))); monitors } -pub fn get_primary_monitor() -> MonitorID { - let xlib = ffi::Xlib::open().unwrap(); // FIXME: gracious handling - - ensure_thread_init(&xlib); - let primary_monitor = unsafe { - let display = (xlib.XOpenDisplay)(ptr::null()); - if display.is_null() { - panic!("get_available_monitors failed"); - } - let primary_monitor = (xlib.XDefaultScreen)(display); - (xlib.XCloseDisplay)(display); - primary_monitor - }; - - MonitorID(primary_monitor as u32) +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) } impl MonitorID { pub fn get_name(&self) -> Option<String> { - let MonitorID(screen_num) = *self; + let MonitorID(_, screen_num) = *self; Some(format!("Monitor #{}", screen_num)) } pub fn get_native_identifier(&self) -> NativeMonitorId { - let MonitorID(screen_num) = *self; - NativeMonitorId::Numeric(screen_num) + NativeMonitorId::Numeric(self.1) } pub fn get_dimensions(&self) -> (u32, u32) { - let xlib = ffi::Xlib::open().unwrap(); // FIXME: gracious handling - - let dimensions = unsafe { - let display = (xlib.XOpenDisplay)(ptr::null()); - let MonitorID(screen_num) = *self; - let screen = (xlib.XScreenOfDisplay)(display, screen_num as i32); - let width = (xlib.XWidthOfScreen)(screen); - let height = (xlib.XHeightOfScreen)(screen); - (xlib.XCloseDisplay)(display); - (width as u32, height as u32) - }; - - dimensions + 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) } } - |