diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2016-01-22 08:01:27 +0100 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2016-01-22 08:01:27 +0100 |
commit | 1ab6677f1e0966fc63eed99d64388da79d5c466e (patch) | |
tree | f7f958ce26a9b39ebc88eff1ee768102b375aa4d | |
parent | 1113fa1c138e8aa06213d7e74e9ed4a971bd10b7 (diff) | |
parent | 0a43f8f733412f7ec7542866b8177ea1215345a5 (diff) | |
download | glutin-1ab6677f1e0966fc63eed99d64388da79d5c466e.tar.gz glutin-1ab6677f1e0966fc63eed99d64388da79d5c466e.zip |
Merge pull request #710 from notriddle/master
Allow it to work under Xvfb.
-rw-r--r-- | src/api/x11/window.rs | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index de9cfb6..4b78c4a 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -57,7 +57,7 @@ pub struct XWindow { pub context: Context, is_fullscreen: bool, screen_id: libc::c_int, - xf86_desk_mode: ffi::XF86VidModeModeInfo, + xf86_desk_mode: Option<ffi::XF86VidModeModeInfo>, ic: ffi::XIC, im: ffi::XIM, colormap: ffi::Colormap, @@ -90,7 +90,9 @@ impl Drop for XWindow { let _lock = GLOBAL_XOPENIM_LOCK.lock().unwrap(); if self.is_fullscreen { - (self.display.xf86vmode.XF86VidModeSwitchToMode)(self.display.display, self.screen_id, &mut self.xf86_desk_mode); + if let Some(mut xf86_desk_mode) = self.xf86_desk_mode { + (self.display.xf86vmode.XF86VidModeSwitchToMode)(self.display.display, self.screen_id, &mut xf86_desk_mode); + } (self.display.xf86vmode.XF86VidModeSetViewPort)(self.display.display, self.screen_id, 0, 0); } @@ -324,36 +326,31 @@ impl Window { let mut mode_num: libc::c_int = mem::uninitialized(); let mut modes: *mut *mut ffi::XF86VidModeModeInfo = mem::uninitialized(); if (display.xf86vmode.XF86VidModeGetAllModeLines)(display.display, screen_id, &mut mode_num, &mut modes) == 0 { - return Err(OsError(format!("Could not query the video modes"))); - } - - let xf86_desk_mode: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(0)); - - let mode_to_switch_to = if window_attrs.monitor.is_some() { - let matching_mode = (0 .. mode_num).map(|i| { - let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m - }).find(|m| m.hdisplay == dimensions.0 as u16 && m.vdisplay == dimensions.1 as u16); - - if let Some(matching_mode) = matching_mode { - Some(matching_mode) - - } else { - let m = (0 .. mode_num).map(|i| { + (None, None) + } else { + let xf86_desk_mode: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(0)); + let mode_to_switch_to = if window_attrs.monitor.is_some() { + let matching_mode = (0 .. mode_num).map(|i| { let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m - }).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16); - - match m { - Some(m) => Some(m), - None => return Err(OsError(format!("Could not find a suitable graphics mode"))) + }).find(|m| m.hdisplay == dimensions.0 as u16 && m.vdisplay == dimensions.1 as u16); + if let Some(matching_mode) = matching_mode { + Some(matching_mode) + } else { + let m = (0 .. mode_num).map(|i| { + let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m + }).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16); + + match m { + Some(m) => Some(m), + None => return Err(OsError(format!("Could not find a suitable graphics mode"))) + } } - } - } else { - None - }; - - (display.xlib.XFree)(modes as *mut _); - - (mode_to_switch_to, xf86_desk_mode) + } else { + None + }; + (display.xlib.XFree)(modes as *mut _); + (mode_to_switch_to, Some(xf86_desk_mode)) + } }; // start the context building process |