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:
parent
6d60a49956
commit
4000ec04d8
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 = []
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue