aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/window/monitor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/x11/window/monitor.rs')
-rw-r--r--src/x11/window/monitor.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/x11/window/monitor.rs b/src/x11/window/monitor.rs
index b72ed15..f62a8ef 100644
--- a/src/x11/window/monitor.rs
+++ b/src/x11/window/monitor.rs
@@ -1,13 +1,15 @@
use std::{ptr};
use super::super::ffi;
+use super::ensure_thread_init;
pub struct MonitorID(pub uint);
pub fn get_available_monitors() -> Vec<MonitorID> {
+ ensure_thread_init();
let nb_monitors = unsafe {
let display = ffi::XOpenDisplay(ptr::null());
if display.is_null() {
- fail!("get_available_monitors failed");
+ panic!("get_available_monitors failed");
}
let nb_monitors = ffi::XScreenCount(display);
ffi::XCloseDisplay(display);
@@ -20,10 +22,11 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
}
pub fn get_primary_monitor() -> MonitorID {
+ ensure_thread_init();
let primary_monitor = unsafe {
let display = ffi::XOpenDisplay(ptr::null());
if display.is_null() {
- fail!("get_available_monitors failed");
+ panic!("get_available_monitors failed");
}
let primary_monitor = ffi::XDefaultScreen(display);
ffi::XCloseDisplay(display);
@@ -46,6 +49,7 @@ impl MonitorID {
let screen = ffi::XScreenOfDisplay(display, screen_num as i32);
let width = ffi::XWidthOfScreen(screen);
let height = ffi::XHeightOfScreen(screen);
+ ffi::XCloseDisplay(display);
(width as uint, height as uint)
};