1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 11:17:15 +03:00

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).
This commit is contained in:
Wez Furlong 2021-06-26 17:05:22 -07:00
parent e78bcfce2a
commit 8ab025b7fc
5 changed files with 40 additions and 3 deletions

View File

@ -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"

View File

@ -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"

View File

@ -462,6 +462,7 @@ impl GlState {
}
#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(feature = "wayland")]
pub fn create_wayland(
display: Option<ffi::EGLNativeDisplayType>,
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<GlConnection>,
wegl_surface: &wayland_egl::WlEglSurface,

View File

@ -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;

View File

@ -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<XConnection>),
#[cfg(feature = "wayland")]
Wayland(Rc<WaylandConnection>),
}
#[derive(Clone)]
pub enum Window {
X11(XWindow),
#[cfg(feature = "wayland")]
Wayland(WaylandWindow),
}
impl Connection {
pub(crate) fn create_new() -> anyhow::Result<Connection> {
#[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<XConnection> {
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<WaylandConnection> {
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<Rc<glium::backend::Context>> {
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<MouseCursor>) -> 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<Dimensions> {
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<String> {
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),
}
}