summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-03-13 03:33:12 +0300
committerGitHub <noreply@github.com>2020-03-13 03:33:12 +0300
commit4000ec04d89b9bd77995960d2a9da8fcad55e003 (patch)
tree0e38be94eb1d75d70d5dcec7e676c699f3de29a2
parent6d60a49956facc63ab5e0ebac8eb15ab7347ea9a (diff)
downloadalacritty-4000ec04d89b9bd77995960d2a9da8fcad55e003.tar.gz
alacritty-4000ec04d89b9bd77995960d2a9da8fcad55e003.zip
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.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/Cargo.toml6
-rw-r--r--alacritty/build.rs4
-rw-r--r--alacritty_terminal/Cargo.toml6
-rw-r--r--alacritty_terminal/src/clipboard.rs41
5 files changed, 41 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a21b5803..9e241586 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 b68d10e0..05574363 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 16f3a2b3..b2ee8b6e 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 f86f9456..2fe46d0d 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 6f6a41be..1169cdc3 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<dyn ClipboardProvider>,
@@ -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::<X11SelectionClipboard>::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();
}
}