From 8ab025b7fc5e4361c9e5f952a6977d35518cb802 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 26 Jun 2021 17:05:22 -0700 Subject: [PATCH] Allow building without wayland support You can run `cargo build --release --no-default-features` to build without wayland support. This is useful for systems that do not have wayland (eg: the `slint` distro). --- wezterm-gui/Cargo.toml | 4 ++++ window/Cargo.toml | 9 ++++++--- window/src/egl.rs | 2 ++ window/src/os/mod.rs | 1 + window/src/os/x_and_wayland.rs | 27 +++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index 429a7bcb1..994906fca 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -8,6 +8,10 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["wayland"] +wayland = ["window/wayland"] + [build-dependencies] anyhow = "1.0" diff --git a/window/Cargo.toml b/window/Cargo.toml index bf6b4f6ff..c26eeda56 100644 --- a/window/Cargo.toml +++ b/window/Cargo.toml @@ -15,6 +15,9 @@ wgpu = "0.8" [build-dependencies] gl_generator = "0.14" +[features] +wayland = ["wayland-client", "smithay-client-toolkit", "wayland-egl"] + [dependencies] async-channel = "1.6" async-task = "4.0" @@ -61,9 +64,9 @@ xkbcommon = { version = "0.5", features = ["x11", "wayland"], git="https://githu mio = "0.6" libc = "0.2" #smithay-client-toolkit = {version = "0.9", optional = true, features=["calloop"], git="https://github.com/wez/client-toolkit.git", branch="title_trunc"} -smithay-client-toolkit = {version = "0.12", features=["calloop"]} -wayland-client = "0.28" -wayland-egl = "0.28" +smithay-client-toolkit = {version = "0.12", features=["calloop"], optional=true} +wayland-client = {version="0.28", optional=true} +wayland-egl = {version="0.28", optional=true} [target.'cfg(target_os="macos")'.dependencies] cocoa = "0.20" diff --git a/window/src/egl.rs b/window/src/egl.rs index 997b17ce7..b38ed398f 100644 --- a/window/src/egl.rs +++ b/window/src/egl.rs @@ -462,6 +462,7 @@ impl GlState { } #[cfg(all(unix, not(target_os = "macos")))] + #[cfg(feature = "wayland")] pub fn create_wayland( display: Option, wegl_surface: &wayland_egl::WlEglSurface, @@ -489,6 +490,7 @@ impl GlState { } #[cfg(all(unix, not(target_os = "macos")))] + #[cfg(feature = "wayland")] pub fn create_wayland_with_existing_connection( connection: &Rc, wegl_surface: &wayland_egl::WlEglSurface, diff --git a/window/src/os/mod.rs b/window/src/os/mod.rs index 997db0386..9119be3cd 100644 --- a/window/src/os/mod.rs +++ b/window/src/os/mod.rs @@ -3,6 +3,7 @@ pub mod windows; #[cfg(windows)] pub use windows::*; +#[cfg(feature = "wayland")] pub mod wayland; pub mod x11; pub mod x_and_wayland; diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rs index c42099c6e..6cdaf8c44 100644 --- a/window/src/os/x_and_wayland.rs +++ b/window/src/os/x_and_wayland.rs @@ -1,7 +1,9 @@ #![cfg(all(unix, not(target_os = "macos")))] use crate::connection::ConnectionOps; +#[cfg(feature = "wayland")] use crate::os::wayland::connection::WaylandConnection; +#[cfg(feature = "wayland")] use crate::os::wayland::window::WaylandWindow; use crate::os::x11::connection::XConnection; use crate::os::x11::window::XWindow; @@ -15,17 +17,20 @@ use std::rc::Rc; pub enum Connection { X11(Rc), + #[cfg(feature = "wayland")] Wayland(Rc), } #[derive(Clone)] pub enum Window { X11(XWindow), + #[cfg(feature = "wayland")] Wayland(WaylandWindow), } impl Connection { pub(crate) fn create_new() -> anyhow::Result { + #[cfg(feature = "wayland")] if config::configuration().enable_wayland { match WaylandConnection::create_new() { Ok(w) => { @@ -50,6 +55,7 @@ impl Connection { ) -> anyhow::Result<(Window, WindowEventReceiver)> { match self { Self::X11(_) => XWindow::new_window(class_name, name, width, height, config).await, + #[cfg(feature = "wayland")] Self::Wayland(_) => { WaylandWindow::new_window(class_name, name, width, height, config).await } @@ -59,10 +65,12 @@ impl Connection { pub(crate) fn x11(&self) -> Rc { match self { Self::X11(x) => Rc::clone(x), + #[cfg(feature = "wayland")] _ => panic!("attempted to get x11 reference on non-x11 connection"), } } + #[cfg(feature = "wayland")] pub(crate) fn wayland(&self) -> Rc { match self { Self::Wayland(w) => Rc::clone(w), @@ -75,6 +83,7 @@ impl ConnectionOps for Connection { fn terminate_message_loop(&self) { match self { Self::X11(x) => x.terminate_message_loop(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.terminate_message_loop(), } } @@ -82,6 +91,7 @@ impl ConnectionOps for Connection { fn run_message_loop(&self) -> anyhow::Result<()> { match self { Self::X11(x) => x.run_message_loop(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.run_message_loop(), } } @@ -106,6 +116,7 @@ unsafe impl HasRawWindowHandle for Window { fn raw_window_handle(&self) -> RawWindowHandle { match self { Self::X11(x) => x.raw_window_handle(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.raw_window_handle(), } } @@ -116,6 +127,7 @@ impl WindowOps for Window { async fn enable_opengl(&self) -> anyhow::Result> { match self { Self::X11(x) => x.enable_opengl().await, + #[cfg(feature = "wayland")] Self::Wayland(w) => w.enable_opengl().await, } } @@ -123,6 +135,7 @@ impl WindowOps for Window { fn finish_frame(&self, frame: glium::Frame) -> anyhow::Result<()> { match self { Self::X11(x) => x.finish_frame(frame), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.finish_frame(frame), } } @@ -130,6 +143,7 @@ impl WindowOps for Window { fn close(&self) -> Future<()> { match self { Self::X11(x) => x.close(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.close(), } } @@ -139,6 +153,7 @@ impl WindowOps for Window { { match self { Self::X11(x) => x.notify(t), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.notify(t), } } @@ -146,6 +161,7 @@ impl WindowOps for Window { fn hide(&self) -> Future<()> { match self { Self::X11(x) => x.hide(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.hide(), } } @@ -153,6 +169,7 @@ impl WindowOps for Window { fn toggle_fullscreen(&self) -> Future<()> { match self { Self::X11(x) => x.toggle_fullscreen(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.toggle_fullscreen(), } } @@ -160,6 +177,7 @@ impl WindowOps for Window { fn config_did_change(&self, config: &ConfigHandle) -> Future<()> { match self { Self::X11(x) => x.config_did_change(config), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.config_did_change(config), } } @@ -167,6 +185,7 @@ impl WindowOps for Window { fn show(&self) -> Future<()> { match self { Self::X11(x) => x.show(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.show(), } } @@ -174,6 +193,7 @@ impl WindowOps for Window { fn set_cursor(&self, cursor: Option) -> Future<()> { match self { Self::X11(x) => x.set_cursor(cursor), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_cursor(cursor), } } @@ -181,6 +201,7 @@ impl WindowOps for Window { fn invalidate(&self) -> Future<()> { match self { Self::X11(x) => x.invalidate(), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.invalidate(), } } @@ -188,6 +209,7 @@ impl WindowOps for Window { fn set_title(&self, title: &str) -> Future<()> { match self { Self::X11(x) => x.set_title(title), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_title(title), } } @@ -195,6 +217,7 @@ impl WindowOps for Window { fn set_icon(&self, image: crate::bitmaps::Image) -> Future<()> { match self { Self::X11(x) => x.set_icon(image), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_icon(image), } } @@ -202,6 +225,7 @@ impl WindowOps for Window { fn set_inner_size(&self, width: usize, height: usize) -> Future { match self { Self::X11(x) => x.set_inner_size(width, height), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_inner_size(width, height), } } @@ -209,6 +233,7 @@ impl WindowOps for Window { fn set_window_position(&self, coords: ScreenPoint) -> Future<()> { match self { Self::X11(x) => x.set_window_position(coords), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_window_position(coords), } } @@ -216,12 +241,14 @@ impl WindowOps for Window { fn get_clipboard(&self, clipboard: Clipboard) -> Future { match self { Self::X11(x) => x.get_clipboard(clipboard), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.get_clipboard(clipboard), } } fn set_clipboard(&self, clipboard: Clipboard, text: String) -> Future<()> { match self { Self::X11(x) => x.set_clipboard(clipboard, text), + #[cfg(feature = "wayland")] Self::Wayland(w) => w.set_clipboard(clipboard, text), } }