1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

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.
This commit is contained in:
Kirill Chibisov 2020-03-13 03:33:12 +03:00 committed by GitHub
parent 6d60a49956
commit 4000ec04d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 17 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Packaging ### Packaging
- Minimum Rust version has been bumped to 1.37.0 - 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 ### Changed

View file

@ -9,7 +9,7 @@ homepage = "https://github.com/alacritty/alacritty"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
alacritty_terminal = { path = "../alacritty_terminal" } alacritty_terminal = { path = "../alacritty_terminal", default-features = false }
clap = "2" clap = "2"
log = "0.4" log = "0.4"
time = "0.1.40" time = "0.1.40"
@ -49,7 +49,9 @@ winapi = { version = "0.3.7", features = ["impl-default", "wincon"]}
embed-resource = "1.3" embed-resource = "1.3"
[features] [features]
default = [] default = ["wayland", "x11"]
x11 = ["alacritty_terminal/x11"]
wayland = ["alacritty_terminal/wayland"]
# Enabling this feature makes shaders automatically reload when changed # Enabling this feature makes shaders automatically reload when changed
live-shader-reload = [] live-shader-reload = []
nightly = [] nightly = []

View file

@ -22,6 +22,10 @@ use std::path::Path;
use embed_resource; use embed_resource;
fn main() { 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(); let hash = rustc_tools_util::get_commit_hash().unwrap_or_default();
println!("cargo:rustc-env=GIT_HASH={}", hash); println!("cargo:rustc-env=GIT_HASH={}", hash);

View file

@ -24,7 +24,7 @@ unicode-width = "0.1"
base64 = "0.11.0" base64 = "0.11.0"
terminfo = "0.7.1" terminfo = "0.7.1"
url = "2" url = "2"
copypasta = "0.6.1" copypasta = { version = "0.6.3", default-features = false }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = "0.16.1" nix = "0.16.1"
@ -44,7 +44,9 @@ mio-anonymous-pipes = "0.1"
objc = "0.2.2" objc = "0.2.2"
[features] [features]
default = [] default = ["x11", "wayland"]
x11 = ["copypasta/x11"]
wayland = ["copypasta/wayland"]
nightly = [] nightly = []
bench = [] bench = []

View file

@ -18,11 +18,13 @@ use std::ffi::c_void;
use log::{debug, warn}; use log::{debug, warn};
use copypasta::nop_clipboard::NopClipboardContext; 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; 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::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 { pub struct Clipboard {
clipboard: Box<dyn ClipboardProvider>, clipboard: Box<dyn ClipboardProvider>,
@ -30,23 +32,33 @@ pub struct Clipboard {
} }
impl Clipboard { impl Clipboard {
#[cfg(any(target_os = "macos", target_os = "windows"))] #[cfg(any(target_os = "macos", windows))]
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()
} }
#[cfg(not(any(target_os = "macos", target_os = "windows")))] #[cfg(not(any(target_os = "macos", windows)))]
pub fn new(display: Option<*mut c_void>) -> Self { pub fn new(_display: Option<*mut c_void>) -> Self {
if let Some(display) = display { #[cfg(feature = "wayland")]
{
if let Some(display) = _display {
let (selection, clipboard) = let (selection, clipboard) =
unsafe { wayland_clipboard::create_clipboards_from_external(display) }; unsafe { wayland_clipboard::create_clipboards_from_external(display) };
return Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) }; return Self {
clipboard: Box::new(clipboard),
selection: Some(Box::new(selection)),
};
}
} }
Self { #[cfg(feature = "x11")]
return Self {
clipboard: Box::new(ClipboardContext::new().unwrap()), clipboard: Box::new(ClipboardContext::new().unwrap()),
selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())),
} };
#[cfg(not(feature = "x11"))]
return Self::new_nop();
} }
// Use for tests and ref-tests // Use for tests and ref-tests
@ -57,7 +69,10 @@ impl Clipboard {
impl Default for Clipboard { impl Default for Clipboard {
fn default() -> Self { 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();
} }
} }