Skip to content

Commit

Permalink
Merge pull request #18 from rust-windowing/x11-wayland-features
Browse files Browse the repository at this point in the history
Add feature flags for `x11` and `wayland`
  • Loading branch information
ids1024 authored Dec 22, 2022
2 parents 80b45a9 + c73bd4b commit abfb2ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ keywords = ["framebuffer", "windowing"]
categories = ["game-development", "graphics", "gui", "multimedia", "rendering"]
exclude = ["examples"]

[features]
default = ["x11", "wayland"]
wayland = ["wayland-backend", "wayland-client", "nix"]
x11 = ["x11-dl"]

[dependencies]
thiserror = "1.0.30"
raw-window-handle = "0.5.0"

[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
nix = "0.26.1"
wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
wayland-client = {version = "0.30.0-beta.14"}
x11-dl = "2.19.1"
nix = { version = "0.26.1", optional = true }
wayland-backend = { version = "0.1.0-beta.14", features = ["client_system"], optional = true }
wayland-client = { version = "0.30.0-beta.14", optional = true }
x11-dl = { version = "2.19.1", optional = true }

[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.42.0"
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ extern crate core;
mod win32;
#[cfg(target_os = "macos")]
mod cg;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
mod x11;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "freebsd")))]
mod wayland;
#[cfg(target_arch = "wasm32")]
mod web;
Expand Down Expand Up @@ -49,9 +49,9 @@ impl GraphicsContext {
/// lifetime of the GraphicsContext
pub unsafe fn from_raw(raw_window_handle: RawWindowHandle, raw_display_handle: RawDisplayHandle) -> Result<Self, SwBufError> {
let imple: Box<dyn GraphicsContextImpl> = match (raw_window_handle, raw_display_handle) {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
(RawWindowHandle::Xlib(xlib_window_handle), RawDisplayHandle::Xlib(xlib_display_handle)) => Box::new(x11::X11Impl::new(xlib_window_handle, xlib_display_handle)?),
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "freebsd")))]
(RawWindowHandle::Wayland(wayland_window_handle), RawDisplayHandle::Wayland(wayland_display_handle)) => Box::new(wayland::WaylandImpl::new(wayland_window_handle, wayland_display_handle)?),
#[cfg(target_os = "windows")]
(RawWindowHandle::Win32(win32_handle), _) => Box::new(win32::Win32Impl::new(&win32_handle)?),
Expand Down

0 comments on commit abfb2ac

Please sign in to comment.