mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 23:23:14 -04:00
Err when a X connection cannot be created instead of panicking
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
|
||||
pub use self::window::{Window, XWindow, PollEventsIterator, WaitEventsIterator, Context, WindowProxy};
|
||||
pub use self::xdisplay::XConnection;
|
||||
pub use self::xdisplay::{XConnection, XNotSupported};
|
||||
|
||||
pub mod ffi;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::ptr;
|
||||
use std::fmt;
|
||||
use std::error::Error;
|
||||
use std::ffi::CString;
|
||||
|
||||
use libc;
|
||||
@@ -21,10 +23,6 @@ pub struct XConnection {
|
||||
unsafe impl Send for XConnection {}
|
||||
unsafe impl Sync 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;
|
||||
|
||||
impl XConnection {
|
||||
pub fn new() -> Result<XConnection, XNotSupported> {
|
||||
// opening the libraries
|
||||
@@ -104,3 +102,19 @@ impl Drop for XConnection {
|
||||
unsafe { (self.xlib.XCloseDisplay)(self.display) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Error returned if this system doesn't have XLib or can't create an X connection.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct XNotSupported;
|
||||
|
||||
impl Error for XNotSupported {
|
||||
fn description(&self) -> &str {
|
||||
"The X windowing system could not be initialized"
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for XNotSupported {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
formatter.write_str(self.description())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user