aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-09-20 08:48:53 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-09-20 08:48:53 +0200
commit82bb047fda3912489d024dbf40613168ded50527 (patch)
tree83953705406ff67e9f2850e53801cc2d559f1954
parentb9a4f5fbe90a94fbca2e6816b92a129dabfe81fd (diff)
downloadglutin-82bb047fda3912489d024dbf40613168ded50527.tar.gz
glutin-82bb047fda3912489d024dbf40613168ded50527.zip
Report the error from x11-rs when failing to open shared libraries
-rw-r--r--src/api/x11/ffi.rs2
-rw-r--r--src/api/x11/xdisplay.rs37
2 files changed, 31 insertions, 8 deletions
diff --git a/src/api/x11/ffi.rs b/src/api/x11/ffi.rs
index 3d4f0ed..465aa95 100644
--- a/src/api/x11/ffi.rs
+++ b/src/api/x11/ffi.rs
@@ -5,6 +5,8 @@ pub use x11_dl::xlib::*;
pub use x11_dl::xinput::*;
pub use x11_dl::xinput2::*;
+pub use x11_dl::error::OpenError;
+
pub use self::glx::types::GLXContext;
/// GLX bindings
diff --git a/src/api/x11/xdisplay.rs b/src/api/x11/xdisplay.rs
index d48d947..2aa5d95 100644
--- a/src/api/x11/xdisplay.rs
+++ b/src/api/x11/xdisplay.rs
@@ -26,10 +26,10 @@ unsafe impl Sync for XConnection {}
impl XConnection {
pub fn new() -> Result<XConnection, XNotSupported> {
// opening the libraries
- let xlib = try!(ffi::Xlib::open().map_err(|_| XNotSupported));
- let xcursor = try!(ffi::Xcursor::open().map_err(|_| XNotSupported));
- let xf86vmode = try!(ffi::Xf86vmode::open().map_err(|_| XNotSupported));
- let xinput2 = try!(ffi::XInput2::open().map_err(|_| XNotSupported));
+ let xlib = try!(ffi::Xlib::open());
+ let xcursor = try!(ffi::Xcursor::open());
+ let xf86vmode = try!(ffi::Xf86vmode::open());
+ let xinput2 = try!(ffi::XInput2::open());
unsafe extern "C" fn x_error_callback(_: *mut ffi::Display, event: *mut ffi::XErrorEvent)
-> libc::c_int
@@ -80,7 +80,7 @@ impl XConnection {
let display = unsafe {
let display = (xlib.XOpenDisplay)(ptr::null());
if display.is_null() {
- return Err(XNotSupported);
+ return Err(XNotSupported::XOpenDisplayFailed);
}
display
};
@@ -104,12 +104,33 @@ impl Drop for XConnection {
}
/// Error returned if this system doesn't have XLib or can't create an X connection.
-#[derive(Copy, Clone, Debug)]
-pub struct XNotSupported;
+#[derive(Clone, Debug)]
+pub enum XNotSupported {
+ /// Failed to load one or several shared libraries.
+ LibraryOpenError(ffi::OpenError),
+ /// Connecting to the X server with `XOpenDisplay` failed.
+ XOpenDisplayFailed, // TODO: add better message
+}
+
+impl From<ffi::OpenError> for XNotSupported {
+ fn from(err: ffi::OpenError) -> XNotSupported {
+ XNotSupported::LibraryOpenError(err)
+ }
+}
impl Error for XNotSupported {
fn description(&self) -> &str {
- "The X windowing system could not be initialized"
+ match *self {
+ XNotSupported::LibraryOpenError(_) => "Failed to load one of xlib's shared libraries",
+ XNotSupported::XOpenDisplayFailed => "Failed to open connection to X server",
+ }
+ }
+
+ fn cause(&self) -> Option<&Error> {
+ match *self {
+ XNotSupported::LibraryOpenError(ref err) => Some(err),
+ _ => None
+ }
}
}