mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Report the error from x11-rs when failing to open shared libraries
This commit is contained in:
parent
b9a4f5fbe9
commit
82bb047fda
|
@ -5,6 +5,8 @@ pub use x11_dl::xlib::*;
|
||||||
pub use x11_dl::xinput::*;
|
pub use x11_dl::xinput::*;
|
||||||
pub use x11_dl::xinput2::*;
|
pub use x11_dl::xinput2::*;
|
||||||
|
|
||||||
|
pub use x11_dl::error::OpenError;
|
||||||
|
|
||||||
pub use self::glx::types::GLXContext;
|
pub use self::glx::types::GLXContext;
|
||||||
|
|
||||||
/// GLX bindings
|
/// GLX bindings
|
||||||
|
|
|
@ -26,10 +26,10 @@ unsafe impl Sync for XConnection {}
|
||||||
impl XConnection {
|
impl XConnection {
|
||||||
pub fn new() -> Result<XConnection, XNotSupported> {
|
pub fn new() -> Result<XConnection, XNotSupported> {
|
||||||
// opening the libraries
|
// opening the libraries
|
||||||
let xlib = try!(ffi::Xlib::open().map_err(|_| XNotSupported));
|
let xlib = try!(ffi::Xlib::open());
|
||||||
let xcursor = try!(ffi::Xcursor::open().map_err(|_| XNotSupported));
|
let xcursor = try!(ffi::Xcursor::open());
|
||||||
let xf86vmode = try!(ffi::Xf86vmode::open().map_err(|_| XNotSupported));
|
let xf86vmode = try!(ffi::Xf86vmode::open());
|
||||||
let xinput2 = try!(ffi::XInput2::open().map_err(|_| XNotSupported));
|
let xinput2 = try!(ffi::XInput2::open());
|
||||||
|
|
||||||
unsafe extern "C" fn x_error_callback(_: *mut ffi::Display, event: *mut ffi::XErrorEvent)
|
unsafe extern "C" fn x_error_callback(_: *mut ffi::Display, event: *mut ffi::XErrorEvent)
|
||||||
-> libc::c_int
|
-> libc::c_int
|
||||||
|
@ -80,7 +80,7 @@ impl XConnection {
|
||||||
let display = unsafe {
|
let display = unsafe {
|
||||||
let display = (xlib.XOpenDisplay)(ptr::null());
|
let display = (xlib.XOpenDisplay)(ptr::null());
|
||||||
if display.is_null() {
|
if display.is_null() {
|
||||||
return Err(XNotSupported);
|
return Err(XNotSupported::XOpenDisplayFailed);
|
||||||
}
|
}
|
||||||
display
|
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.
|
/// Error returned if this system doesn't have XLib or can't create an X connection.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct XNotSupported;
|
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 {
|
impl Error for XNotSupported {
|
||||||
fn description(&self) -> &str {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue