From 4000ec04d89b9bd77995960d2a9da8fcad55e003 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Fri, 13 Mar 2020 03:33:12 +0300 Subject: [PATCH] Add option to pick Linux/BSD backends This commit adds two cargo features `x11` and `wayland` to pick Linux/BSD backends, with both enabled by default. Fixes #3340. --- CHANGELOG.md | 1 + alacritty/Cargo.toml | 6 +++-- alacritty/build.rs | 4 +++ alacritty_terminal/Cargo.toml | 6 +++-- alacritty_terminal/src/clipboard.rs | 41 ++++++++++++++++++++--------- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a21b580..9e24158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Packaging - Minimum Rust version has been bumped to 1.37.0 +- Added Rust features `x11` and `wayland` to pick backends, with both enabled by default ### Changed diff --git a/alacritty/Cargo.toml b/alacritty/Cargo.toml index b68d10e..0557436 100644 --- a/alacritty/Cargo.toml +++ b/alacritty/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://github.com/alacritty/alacritty" edition = "2018" [dependencies] -alacritty_terminal = { path = "../alacritty_terminal" } +alacritty_terminal = { path = "../alacritty_terminal", default-features = false } clap = "2" log = "0.4" time = "0.1.40" @@ -49,7 +49,9 @@ winapi = { version = "0.3.7", features = ["impl-default", "wincon"]} embed-resource = "1.3" [features] -default = [] +default = ["wayland", "x11"] +x11 = ["alacritty_terminal/x11"] +wayland = ["alacritty_terminal/wayland"] # Enabling this feature makes shaders automatically reload when changed live-shader-reload = [] nightly = [] diff --git a/alacritty/build.rs b/alacritty/build.rs index 16f3a2b..b2ee8b6 100644 --- a/alacritty/build.rs +++ b/alacritty/build.rs @@ -22,6 +22,10 @@ use std::path::Path; use embed_resource; fn main() { + if cfg!(not(any(feature = "x11", feature = "wayland", target_os = "macos", windows))) { + panic!("at least one of the \"x11\"/\"wayland\" features must be enabled"); + } + let hash = rustc_tools_util::get_commit_hash().unwrap_or_default(); println!("cargo:rustc-env=GIT_HASH={}", hash); diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml index f86f945..2fe46d0 100644 --- a/alacritty_terminal/Cargo.toml +++ b/alacritty_terminal/Cargo.toml @@ -24,7 +24,7 @@ unicode-width = "0.1" base64 = "0.11.0" terminfo = "0.7.1" url = "2" -copypasta = "0.6.1" +copypasta = { version = "0.6.3", default-features = false } [target.'cfg(unix)'.dependencies] nix = "0.16.1" @@ -44,7 +44,9 @@ mio-anonymous-pipes = "0.1" objc = "0.2.2" [features] -default = [] +default = ["x11", "wayland"] +x11 = ["copypasta/x11"] +wayland = ["copypasta/wayland"] nightly = [] bench = [] diff --git a/alacritty_terminal/src/clipboard.rs b/alacritty_terminal/src/clipboard.rs index 6f6a41b..1169cdc 100644 --- a/alacritty_terminal/src/clipboard.rs +++ b/alacritty_terminal/src/clipboard.rs @@ -18,11 +18,13 @@ use std::ffi::c_void; use log::{debug, warn}; use copypasta::nop_clipboard::NopClipboardContext; -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(all(not(any(target_os = "macos", windows)), feature = "wayland"))] use copypasta::wayland_clipboard; -#[cfg(not(any(target_os = "macos", target_os = "windows")))] +#[cfg(all(not(any(target_os = "macos", windows)), feature = "x11"))] use copypasta::x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}; -use copypasta::{ClipboardContext, ClipboardProvider}; +#[cfg(any(feature = "x11", target_os = "macos", windows))] +use copypasta::ClipboardContext; +use copypasta::ClipboardProvider; pub struct Clipboard { clipboard: Box, @@ -30,23 +32,33 @@ pub struct Clipboard { } impl Clipboard { - #[cfg(any(target_os = "macos", target_os = "windows"))] + #[cfg(any(target_os = "macos", windows))] pub fn new() -> Self { Self::default() } - #[cfg(not(any(target_os = "macos", target_os = "windows")))] - pub fn new(display: Option<*mut c_void>) -> Self { - if let Some(display) = display { - let (selection, clipboard) = - unsafe { wayland_clipboard::create_clipboards_from_external(display) }; - return Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) }; + #[cfg(not(any(target_os = "macos", windows)))] + pub fn new(_display: Option<*mut c_void>) -> Self { + #[cfg(feature = "wayland")] + { + if let Some(display) = _display { + let (selection, clipboard) = + unsafe { wayland_clipboard::create_clipboards_from_external(display) }; + return Self { + clipboard: Box::new(clipboard), + selection: Some(Box::new(selection)), + }; + } } - Self { + #[cfg(feature = "x11")] + return Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: Some(Box::new(X11ClipboardContext::::new().unwrap())), - } + }; + + #[cfg(not(feature = "x11"))] + return Self::new_nop(); } // Use for tests and ref-tests @@ -57,7 +69,10 @@ impl Clipboard { impl Default for Clipboard { fn default() -> Self { - Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None } + #[cfg(any(feature = "x11", target_os = "macos", windows))] + return Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None }; + #[cfg(not(any(feature = "x11", target_os = "macos", windows)))] + return Self::new_nop(); } }