Add better X error handling

This commit is contained in:
Pierre Krieger 2015-12-24 10:57:08 +01:00
parent 8236564a52
commit 82f5cd8272
5 changed files with 94 additions and 7 deletions

View file

@ -9,6 +9,7 @@ pub struct MonitorId(pub Arc<XConnection>, pub u32);
pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorId> {
let nb_monitors = unsafe { (x.xlib.XScreenCount)(x.display) };
x.check_errors().expect("Failed to call XScreenCount");
let mut monitors = VecDeque::new();
monitors.extend((0 .. nb_monitors).map(|i| MonitorId(x.clone(), i as u32)));
@ -18,6 +19,7 @@ pub fn get_available_monitors(x: &Arc<XConnection>) -> VecDeque<MonitorId> {
#[inline]
pub fn get_primary_monitor(x: &Arc<XConnection>) -> MonitorId {
let primary_monitor = unsafe { (x.xlib.XDefaultScreen)(x.display) };
x.check_errors().expect("Failed to call XDefaultScreen");
MonitorId(x.clone(), primary_monitor as u32)
}
@ -36,6 +38,7 @@ impl MonitorId {
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) };
self.0.check_errors().expect("Failed to get monitor dimensions");
(width as u32, height as u32)
}
}