aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-05-15 13:13:00 +0200
committertomaka <pierre.krieger1708@gmail.com>2015-05-15 13:13:00 +0200
commit899f9b9880f35b824c571d3bdf2ac20f8a2be46a (patch)
tree20a39a02dc4711ea3b8cbea6eebf1b20902e853d /src
parenta6c33ef958d9c54581c9efb1760d48eeb8137e4b (diff)
parent1dc2cb27cf229402e16e30fb12511cbbab37cd1d (diff)
downloadglutin-899f9b9880f35b824c571d3bdf2ac20f8a2be46a.tar.gz
glutin-899f9b9880f35b824c571d3bdf2ac20f8a2be46a.zip
Merge pull request #450 from vberger/x-wayland-split
Do the linux backend choice only once at startup.
Diffstat (limited to 'src')
-rw-r--r--src/platform/linux/api_dispatch.rs55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs
index 1a5e1ab..e04cff5 100644
--- a/src/platform/linux/api_dispatch.rs
+++ b/src/platform/linux/api_dispatch.rs
@@ -17,6 +17,22 @@ use libc;
use api::wayland;
use api::x11;
+enum Backend {
+ X,
+ Wayland
+}
+
+lazy_static!(
+ static ref BACKEND: Backend = {
+ // Wayland backend is not production-ready yet so we disable it
+ if false && wayland::is_available() {
+ Backend::Wayland
+ } else {
+ Backend::X
+ }
+ };
+);
+
pub enum Window {
#[doc(hidden)]
X(x11::Window),
@@ -49,25 +65,21 @@ pub enum MonitorID {
}
pub fn get_available_monitors() -> VecDeque<MonitorID> {
- if false && wayland::is_available() {
- // We are doing wayland
- wayland::get_available_monitors()
- .into_iter()
- .map(|m| MonitorID::Wayland(m))
- .collect()
- } else {
- // Fallback on X
- x11::get_available_monitors()
- .into_iter()
- .map(|m| MonitorID::X(m))
- .collect()
+ match *BACKEND {
+ Backend::Wayland => wayland::get_available_monitors()
+ .into_iter()
+ .map(MonitorID::Wayland)
+ .collect(),
+ Backend::X => x11::get_available_monitors()
+ .into_iter()
+ .map(MonitorID::X)
+ .collect(),
}
}
pub fn get_primary_monitor() -> MonitorID {
- if false && wayland::is_available() {
- MonitorID::Wayland(wayland::get_primary_monitor())
- } else {
- MonitorID::X(x11::get_primary_monitor())
+ match *BACKEND {
+ Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()),
+ Backend::X => MonitorID::X(x11::get_primary_monitor()),
}
}
@@ -133,14 +145,9 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
impl Window {
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
- if false && wayland::is_available() {
- // we have a wayland connection, go for it
- let window = try!(wayland::Window::new(builder));
- Ok(Window::Wayland(window))
- } else {
- // fallback on X
- let window = try!(x11::Window::new(builder));
- Ok(Window::X(window))
+ match *BACKEND {
+ Backend::Wayland => wayland::Window::new(builder).map(Window::Wayland),
+ Backend::X => x11::Window::new(builder).map(Window::X),
}
}