aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-09-20 17:52:53 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-09-20 17:52:53 +0200
commitf51ace4c7885fa25c146c24181c4d87f5632de3e (patch)
treefa22f137deaabbc99c2f7bbeb1958b07ab7c2949 /src/platform
parent907d7621bc9822c2688d1783a5805f8532a92b42 (diff)
parent82bb047fda3912489d024dbf40613168ded50527 (diff)
downloadglutin-f51ace4c7885fa25c146c24181c4d87f5632de3e.tar.gz
glutin-f51ace4c7885fa25c146c24181c4d87f5632de3e.zip
Merge pull request #602 from tomaka/api-dispatch-error
[Breaking change] Better error handling in Linux's api dispatch
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/linux/api_dispatch.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs
index e580ab1..f25bda9 100644
--- a/src/platform/linux/api_dispatch.rs
+++ b/src/platform/linux/api_dispatch.rs
@@ -19,10 +19,12 @@ use libc;
use api::wayland;
use api::x11;
use api::x11::XConnection;
+use api::x11::XNotSupported;
enum Backend {
X(Arc<XConnection>),
- Wayland
+ Wayland,
+ Error(XNotSupported),
}
lazy_static!(
@@ -31,7 +33,10 @@ lazy_static!(
if false && wayland::is_available() {
Backend::Wayland
} else {
- Backend::X(Arc::new(XConnection::new().unwrap()))
+ match XConnection::new() {
+ Ok(x) => Backend::X(Arc::new(x)),
+ Err(e) => Backend::Error(e),
+ }
}
};
);
@@ -65,7 +70,9 @@ pub enum MonitorID {
#[doc(hidden)]
X(x11::MonitorID),
#[doc(hidden)]
- Wayland(wayland::MonitorID)
+ Wayland(wayland::MonitorID),
+ #[doc(hidden)]
+ None,
}
pub fn get_available_monitors() -> VecDeque<MonitorID> {
@@ -78,6 +85,7 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> {
.into_iter()
.map(MonitorID::X)
.collect(),
+ Backend::Error(_) => { let mut d = VecDeque::new(); d.push_back(MonitorID::None); d},
}
}
@@ -85,6 +93,7 @@ pub fn get_primary_monitor() -> MonitorID {
match *BACKEND {
Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()),
Backend::X(ref connec) => MonitorID::X(x11::get_primary_monitor(connec)),
+ Backend::Error(_) => MonitorID::None,
}
}
@@ -92,21 +101,24 @@ impl MonitorID {
pub fn get_name(&self) -> Option<String> {
match self {
&MonitorID::X(ref m) => m.get_name(),
- &MonitorID::Wayland(ref m) => m.get_name()
+ &MonitorID::Wayland(ref m) => m.get_name(),
+ &MonitorID::None => None,
}
}
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
match self {
&MonitorID::X(ref m) => m.get_native_identifier(),
- &MonitorID::Wayland(ref m) => m.get_native_identifier()
+ &MonitorID::Wayland(ref m) => m.get_native_identifier(),
+ &MonitorID::None => unimplemented!() // FIXME:
}
}
pub fn get_dimensions(&self) -> (u32, u32) {
match self {
&MonitorID::X(ref m) => m.get_dimensions(),
- &MonitorID::Wayland(ref m) => m.get_dimensions()
+ &MonitorID::Wayland(ref m) => m.get_dimensions(),
+ &MonitorID::None => (800, 600), // FIXME:
}
}
}
@@ -153,6 +165,7 @@ impl Window {
match *BACKEND {
Backend::Wayland => wayland::Window::new(builder).map(Window::Wayland),
Backend::X(ref connec) => x11::Window::new(connec, builder).map(Window::X),
+ Backend::Error(ref error) => Err(CreationError::NoBackendAvailable(Box::new(error.clone())))
}
}