Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'use-x-over-wayland' feature #182

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ wayland-client = { version = "0.8.6", features = ["dlopen"] }
wayland-kbd = "0.8.0"
wayland-window = "0.5.0"
x11-dl = "2.8"

[features]
# Under linux/bsd use X preferentially over Wayland, if running a Wayland session this means the window will render
# using XWayland. This feature will not affect other operating systems.
use-x-over-wayland = []
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate winit;
fn main() {
let events_loop = winit::EventsLoop::new();

let window = winit::WindowBuilder::new()
let _window = winit::WindowBuilder::new()
.with_title("A fantastic window!")
.build(&events_loop)
.unwrap();
Expand Down
17 changes: 13 additions & 4 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@ pub enum UnixBackend {
X(Arc<XConnection>),
Wayland(Arc<wayland::WaylandContext>),
Error(XNotSupported),
}
}

lazy_static!(
pub static ref UNIX_BACKEND: UnixBackend = {
if let Some(ctxt) = wayland::WaylandContext::init() {
UnixBackend::Wayland(Arc::new(ctxt))
} else {
#[inline]
fn x_backend() -> UnixBackend {
match XConnection::new(Some(x_error_callback)) {
Ok(x) => UnixBackend::X(Arc::new(x)),
Err(e) => UnixBackend::Error(e),
}
}

if cfg!(feature = "use-x-over-wayland") {
x_backend()
}
else if let Some(ctxt) = wayland::WaylandContext::init() {
UnixBackend::Wayland(Arc::new(ctxt))
}
else {
x_backend()
}
};
);

Expand Down