From 3376332a851e16801a4f27347c8d6170c9008e73 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 17 May 2015 11:19:06 +0200 Subject: Rework the X implementation to use only one X connection --- src/platform/linux/api_dispatch.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/platform/linux') diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs index e04cff5..d04a1fb 100644 --- a/src/platform/linux/api_dispatch.rs +++ b/src/platform/linux/api_dispatch.rs @@ -4,6 +4,7 @@ pub use api::x11::{Window, WindowProxy, MonitorID, get_available_monitors, get_p pub use api::x11::{WaitEventsIterator, PollEventsIterator};*/ use std::collections::VecDeque; +use std::sync::Arc; use BuilderAttribs; use CreationError; @@ -16,9 +17,10 @@ use libc; use api::wayland; use api::x11; +use api::x11::XConnection; enum Backend { - X, + X(Arc), Wayland } @@ -28,7 +30,7 @@ lazy_static!( if false && wayland::is_available() { Backend::Wayland } else { - Backend::X + Backend::X(Arc::new(XConnection::new().unwrap())) } }; ); @@ -70,16 +72,17 @@ pub fn get_available_monitors() -> VecDeque { .into_iter() .map(MonitorID::Wayland) .collect(), - Backend::X => x11::get_available_monitors() - .into_iter() - .map(MonitorID::X) - .collect(), + Backend::X(ref connec) => x11::get_available_monitors(connec) + .into_iter() + .map(MonitorID::X) + .collect(), } } + pub fn get_primary_monitor() -> MonitorID { match *BACKEND { Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()), - Backend::X => MonitorID::X(x11::get_primary_monitor()), + Backend::X(ref connec) => MonitorID::X(x11::get_primary_monitor(connec)), } } @@ -147,7 +150,7 @@ impl Window { pub fn new(builder: BuilderAttribs) -> Result { match *BACKEND { Backend::Wayland => wayland::Window::new(builder).map(Window::Wayland), - Backend::X => x11::Window::new(builder).map(Window::X), + Backend::X(ref connec) => x11::Window::new(connec, builder).map(Window::X), } } @@ -286,7 +289,6 @@ impl Window { } impl GlContext for Window { - unsafe fn make_current(&self) { match self { &Window::X(ref w) => w.make_current(), @@ -328,4 +330,4 @@ impl GlContext for Window { &Window::Wayland(ref w) => w.get_pixel_format() } } -} \ No newline at end of file +} -- cgit v1.2.3