diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Cargo.lock | 134 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | INSTALL.md | 17 | ||||
-rw-r--r-- | alacritty/src/main.rs | 9 | ||||
-rw-r--r-- | alacritty_terminal/Cargo.toml | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/clipboard.rs | 90 | ||||
-rw-r--r-- | alacritty_terminal/src/display.rs | 6 | ||||
-rw-r--r-- | alacritty_terminal/src/event.rs | 11 | ||||
-rw-r--r-- | alacritty_terminal/src/input.rs | 26 | ||||
-rw-r--r-- | alacritty_terminal/src/lib.rs | 1 | ||||
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 56 | ||||
-rw-r--r-- | alacritty_terminal/src/url.rs | 4 | ||||
-rw-r--r-- | alacritty_terminal/src/window.rs | 15 | ||||
-rw-r--r-- | alacritty_terminal/tests/ref.rs | 3 | ||||
-rw-r--r-- | copypasta/Cargo.toml | 17 | ||||
-rw-r--r-- | copypasta/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | copypasta/src/lib.rs | 88 | ||||
-rw-r--r-- | copypasta/src/macos.rs | 329 | ||||
-rw-r--r-- | copypasta/src/windows.rs | 64 | ||||
-rw-r--r-- | copypasta/src/x11.rs | 144 | ||||
-rw-r--r-- | extra/linux/snap/snapcraft.yaml | 1 |
22 files changed, 301 insertions, 923 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4efb03ec..8fe27442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Packaging + +- The xclip dependency has been removed + ### Added - Added ToggleFullscreen action @@ -38,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added ScrollLineUp and ScrollLineDown actions for scrolling line by line +- Native clipboard support on X11 and Wayland ### Changed @@ -41,7 +41,7 @@ dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "copypasta 0.0.1", + "clipboard 0.5.0 (git+https://github.com/chrisduerr/rust-clipboard)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -66,7 +66,7 @@ dependencies = [ "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "terminfo 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -316,12 +316,14 @@ dependencies = [ [[package]] name = "clipboard" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/chrisduerr/rust-clipboard#c0c27997a091e217eb2b6e38d4cb6232a3fe593a" dependencies = [ "clipboard-win 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smithay-clipboard 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", "x11-clipboard 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -402,16 +404,6 @@ dependencies = [ ] [[package]] -name = "copypasta" -version = "0.0.1" -dependencies = [ - "clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "core-foundation" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1407,6 +1399,18 @@ dependencies = [ [[package]] name = "nix" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nix" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ @@ -2117,13 +2121,22 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook-registry 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "signal-hook-registry" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2158,6 +2171,30 @@ dependencies = [ ] [[package]] +name = "smithay-client-toolkit" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-protocols 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "smithay-clipboard" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "smithay-client-toolkit 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "socket2" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2593,6 +2630,20 @@ dependencies = [ ] [[package]] +name = "wayland-client" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "wayland-commons" version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2602,6 +2653,15 @@ dependencies = [ ] [[package]] +name = "wayland-commons" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "wayland-protocols" version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2614,6 +2674,18 @@ dependencies = [ ] [[package]] +name = "wayland-protocols" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-commons 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "wayland-scanner" version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2624,6 +2696,16 @@ dependencies = [ ] [[package]] +name = "wayland-scanner" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "wayland-sys" version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2633,6 +2715,15 @@ dependencies = [ ] [[package]] +name = "wayland-sys" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "which" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2845,7 +2936,7 @@ dependencies = [ "checksum cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" "checksum clang-sys 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "939a1a34310b120d26eba35c29475933128b0ec58e24b43327f8dbe6036fc538" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" +"checksum clipboard 0.5.0 (git+https://github.com/chrisduerr/rust-clipboard)" = "<none>" "checksum clipboard-win 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "289da2fc09ab964a4948a63287c94fcb4698fa823c46da84c3792928c9d36110" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8" @@ -2962,6 +3053,7 @@ dependencies = [ "checksum named_pipe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ed10a5ac4f5f7e5d75552b12c1d5d542debca81e573279dd1e4c19fde6efa6d" "checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +"checksum nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "921f61dc817b379d0834e45d5ec45beaacfae97082090a49c2cf30dcbc30206f" "checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b" @@ -3041,11 +3133,14 @@ dependencies = [ "checksum servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a088f8d775a5c5314aae09bd77340bc9c67d72b9a45258be34c83548b4814cd9" "checksum servo-fontconfig-sys 4.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b46d201addcfbd25c1798ad1281d98c40743824e0b0f1e611bd3d5d0d31a7b8d" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" -"checksum signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "97a47ae722318beceb0294e6f3d601205a1e6abaa4437d9d33e3a212233e3021" +"checksum signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "72ab58f1fda436857e6337dcb6a5aaa34f16c5ddc87b3a8b6ef7a212f90b9c5a" +"checksum signal-hook-registry 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "591fe2ee5a2412968f63a008a190d99918c2cda3f616411026f0975715e1cf62" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum smithay-client-toolkit 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aa4899558362a65589b53313935099835acf999740915e134dff20cca7c6a28b" +"checksum smithay-client-toolkit 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c172926680325cc0cbb6b08193a66fd88e1ef4a6e92651fd459ca4f5d94c8bc" +"checksum smithay-clipboard 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7944fcb3ecb86f0e39537c1c7501931d3a0f00d3ef1dfc0d4b8996884ac77197" "checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum spsc-buffer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be6c3f39c37a4283ee4b43d1311c828f2e1fb0541e76ea0cb1a2abd9ef2f5b3b" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -3096,10 +3191,15 @@ dependencies = [ "checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum wayland-client 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e77d1e6887f07ea2e5d79a3d7d03a875e62d3746334a909b5035d779d849a523" +"checksum wayland-client 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a2656a57440ba1db12d4e5f0dce5423eed97bbf91bd321f456f41cde6da6c01e" "checksum wayland-commons 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "dff69a5399ca212efa4966f3ee2a3773f19960d0fa329b9aca046a8508a0e09f" +"checksum wayland-commons 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27b4965c07ee4b63b845e6aef4aa9066668a9ed00ce345afddcc991508ec8025" "checksum wayland-protocols 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ccddf6a4407d982898e0f0a1172217843f3d40fe4272f828060b56a2d40d81" +"checksum wayland-protocols 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)" = "56bfad6aef97b909703605ea1321079a00914aa2eb98912641c54bfa9e3b0570" "checksum wayland-scanner 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "63bc5efa7dcdb8f04d2e5d1571c0d0577fc47076d133d68e056bdb299f1b60e2" +"checksum wayland-scanner 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ada374074230633e2b27c045c6706be02408e1abf76e0e810e0f65cccae43c6e" "checksum wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e76af81a601b84d400744f85f083381daa77ac01f6c8711e57e662dc3a35d69d" +"checksum wayland-sys 0.22.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c0e5e9cbfba8b38c34d7615cfe1e69c5242f0e7c2dab00fd705f6caff32b3c0f" "checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2" "checksum widestring 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effc0e4ff8085673ea7b9b2e3c73f6bd4d118810c9009ed8f1e16bd96c331db6" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" @@ -3,7 +3,6 @@ members = [ "alacritty", "alacritty_terminal", "font", - "copypasta", "winpty" ] @@ -71,7 +71,7 @@ libraries to build Alacritty. Here's an apt command that should install all of them. If something is still found to be missing, please open an issue. ```sh -apt-get install cmake pkg-config libfreetype6-dev libfontconfig1-dev xclip +apt-get install cmake pkg-config libfreetype6-dev libfontconfig1-dev ``` #### Arch Linux @@ -81,7 +81,7 @@ On Arch Linux, you need a few extra libraries to build Alacritty. Here's a to be missing, please open an issue. ```sh -pacman -S cmake freetype2 fontconfig pkg-config make xclip +pacman -S cmake freetype2 fontconfig pkg-config make ``` #### Fedora @@ -91,7 +91,7 @@ command that should install all of them. If something is still found to be missing, please open an issue. ```sh -dnf install cmake freetype-devel fontconfig-devel xclip +dnf install cmake freetype-devel fontconfig-devel ``` #### CentOS/RHEL 7 @@ -101,7 +101,7 @@ command that should install all of them. If something is still found to be missing, please open an issue. ```sh -yum install cmake freetype-devel fontconfig-devel xclip +yum install cmake freetype-devel fontconfig-devel yum group install "Development Tools" ``` @@ -112,15 +112,12 @@ a `zypper` command that should install all of them. If something is still found to be missing, please open an issue. ```sh -zypper install cmake freetype-devel fontconfig-devel xclip +zypper install cmake freetype-devel fontconfig-devel ``` #### Slackware Compiles out of the box for 14.2 -For copy & paste support (middle mouse button) you need to install xclip -https://slackbuilds.org/repository/14.2/misc/xclip/?search=xclip - #### Void Linux @@ -128,7 +125,7 @@ On [Void Linux](https://voidlinux.eu), install following packages before compiling Alacritty: ```sh -xbps-install cmake freetype-devel freetype expat-devel fontconfig-devel fontconfig xclip +xbps-install cmake freetype-devel freetype expat-devel fontconfig-devel fontconfig ``` #### FreeBSD @@ -138,7 +135,7 @@ command that should install all of them. If something is still found to be missing, please open an issue. ```sh -pkg install cmake freetype2 fontconfig xclip pkgconf +pkg install cmake freetype2 fontconfig pkgconf ``` #### OpenBSD diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 7a200a8b..be512bee 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -41,6 +41,7 @@ use std::env; #[cfg(not(windows))] use std::os::unix::io::AsRawFd; +use alacritty_terminal::clipboard::Clipboard; use alacritty_terminal::config::{self, Config, Monitor}; use alacritty_terminal::display::Display; use alacritty_terminal::event_loop::{self, EventLoop, Msg}; @@ -138,12 +139,18 @@ fn run( info!("PTY Dimensions: {:?} x {:?}", display.size().lines(), display.size().cols()); + // Create new native clipboard + #[cfg(not(any(target_os = "macos", target_os = "windows")))] + let clipboard = Clipboard::new(display.get_wayland_display()); + #[cfg(any(target_os = "macos", target_os = "windows"))] + let clipboard = Clipboard::new(); + // Create the terminal // // This object contains all of the state about what's being displayed. It's // wrapped in a clonable mutex since both the I/O loop and display need to // access it. - let terminal = Term::new(&config, display.size().to_owned(), message_buffer); + let terminal = Term::new(&config, display.size().to_owned(), message_buffer, clipboard); let terminal = Arc::new(FairMutex::new(terminal)); // Find the window ID for setting $WINDOWID diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml index 8d9ca639..18164fb9 100644 --- a/alacritty_terminal/Cargo.toml +++ b/alacritty_terminal/Cargo.toml @@ -23,7 +23,6 @@ serde_yaml = "0.8" vte = "0.3" mio = "0.6" mio-extras = "2" -copypasta = { path = "../copypasta" } xdg = "2" log = "0.4" clap = "2" @@ -35,6 +34,7 @@ static_assertions = "0.3.0" terminfo = "0.6.1" url = "1.7.1" crossbeam-channel = "0.3.8" +clipboard = { git = "https://github.com/chrisduerr/rust-clipboard" } [target.'cfg(unix)'.dependencies] nix = "0.13" diff --git a/alacritty_terminal/src/clipboard.rs b/alacritty_terminal/src/clipboard.rs new file mode 100644 index 00000000..ca70c3bf --- /dev/null +++ b/alacritty_terminal/src/clipboard.rs @@ -0,0 +1,90 @@ +// Copyright 2016 Joe Wilm, The Alacritty Project Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[cfg(not(any(target_os = "macos", target_os = "windows")))] +use std::ffi::c_void; + +use clipboard::nop_clipboard::NopClipboardContext; +#[cfg(not(any(target_os = "macos", target_os = "windows")))] +use clipboard::wayland_clipboard::WaylandClipboardContext; +#[cfg(not(any(target_os = "macos", target_os = "windows")))] +use clipboard::x11_clipboard::{Primary as X11SecondaryClipboard, X11ClipboardContext}; +use clipboard::{ClipboardContext, ClipboardProvider}; + +pub struct Clipboard { + primary: Box<ClipboardProvider>, + secondary: Option<Box<ClipboardProvider>>, +} + +impl Clipboard { + #[cfg(any(target_os = "macos", target_os = "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 { + return Self { + primary: unsafe { Box::new(WaylandClipboardContext::new_from_external(display)) }, + secondary: None, + }; + } + + Self { + primary: Box::new(ClipboardContext::new().unwrap()), + secondary: Some(Box::new(X11ClipboardContext::<X11SecondaryClipboard>::new().unwrap())), + } + } + + // Use for tests and ref-tests + pub fn new_nop() -> Self { + Self { primary: Box::new(NopClipboardContext::new().unwrap()), secondary: None } + } +} + +impl Default for Clipboard { + fn default() -> Self { + Self { primary: Box::new(ClipboardContext::new().unwrap()), secondary: None } + } +} + +#[derive(Debug)] +pub enum ClipboardType { + Primary, + Secondary, +} + +impl Clipboard { + pub fn store(&mut self, ty: ClipboardType, text: impl Into<String>) { + let clipboard = match (ty, &mut self.secondary) { + (ClipboardType::Secondary, Some(provider)) => provider, + (ClipboardType::Secondary, None) => return, + _ => &mut self.primary, + }; + + clipboard.set_contents(text.into()).unwrap_or_else(|err| { + warn!("Error storing selection to clipboard. {}", err); + }); + } + + pub fn load(&mut self, ty: ClipboardType) -> Result<String, Box<std::error::Error>> { + let clipboard = match (ty, &mut self.secondary) { + (ClipboardType::Secondary, Some(provider)) => provider, + _ => &mut self.primary, + }; + + clipboard.get_contents() + } +} diff --git a/alacritty_terminal/src/display.rs b/alacritty_terminal/src/display.rs index 1d5799f6..4cb023af 100644 --- a/alacritty_terminal/src/display.rs +++ b/alacritty_terminal/src/display.rs @@ -15,6 +15,7 @@ //! The display subsystem including window management, font rasterization, and //! GPU drawing. use std::f64; +use std::ffi::c_void; use std::sync::mpsc; use glutin::dpi::{PhysicalPosition, PhysicalSize}; @@ -557,4 +558,9 @@ impl Display { self.window().set_ime_spot(PhysicalPosition::from((nspot_x, nspot_y)).to_logical(dpr)); } + + #[cfg(not(any(target_os = "macos", target_os = "windows")))] + pub fn get_wayland_display(&self) -> Option<*mut c_void> { + self.window.get_wayland_display() + } } diff --git a/alacritty_terminal/src/event.rs b/alacritty_terminal/src/event.rs index 1f3e9ca5..f27a6caa 100644 --- a/alacritty_terminal/src/event.rs +++ b/alacritty_terminal/src/event.rs @@ -8,13 +8,13 @@ use std::io::Write; use std::sync::mpsc; use std::time::Instant; -use copypasta::{Buffer as ClipboardBuffer, Clipboard, Load, Store}; use glutin::dpi::PhysicalSize; use glutin::{self, ElementState, Event, ModifiersState, MouseButton}; use parking_lot::MutexGuard; use serde_json as json; use crate::cli::Options; +use crate::clipboard::ClipboardType; use crate::config::{self, Config}; use crate::display::OnResize; use crate::grid::Scroll; @@ -26,7 +26,6 @@ use crate::term::cell::Cell; use crate::term::{SizeInfo, Term}; #[cfg(unix)] use crate::tty; -use crate::util::fmt::Red; use crate::util::{limit, start_daemon}; use crate::window::Window; @@ -70,14 +69,10 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { } } - fn copy_selection(&self, buffer: ClipboardBuffer) { + fn copy_selection(&mut self, ty: ClipboardType) { if let Some(selected) = self.terminal.selection_to_string() { if !selected.is_empty() { - Clipboard::new() - .and_then(|mut clipboard| clipboard.store(selected, buffer)) - .unwrap_or_else(|err| { - warn!("Error storing selection to clipboard. {}", Red(err)); - }); + self.terminal.clipboard().store(ty, selected); } } } diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs index fc79b398..0a5cd42b 100644 --- a/alacritty_terminal/src/input.rs +++ b/alacritty_terminal/src/input.rs @@ -23,7 +23,6 @@ use std::mem; use std::ops::RangeInclusive; use std::time::Instant; -use copypasta::{Buffer as ClipboardBuffer, Clipboard, Load}; use glutin::{ ElementState, KeyboardInput, ModifiersState, MouseButton, MouseCursor, MouseScrollDelta, TouchPhase, @@ -31,6 +30,7 @@ use glutin::{ use unicode_width::UnicodeWidthStr; use crate::ansi::{ClearMode, Handler}; +use crate::clipboard::ClipboardType; use crate::config::{self, Key}; use crate::event::{ClickState, Mouse}; use crate::grid::Scroll; @@ -63,7 +63,7 @@ pub struct Processor<'a, A: 'a> { pub trait ActionContext { fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&mut self, _: B); fn size_info(&self) -> SizeInfo; - fn copy_selection(&self, _: ClipboardBuffer); + fn copy_selection(&mut self, _: ClipboardType); fn clear_selection(&mut self); fn update_selection(&mut self, point: Point, side: Side); fn simple_selection(&mut self, point: Point, side: Side); @@ -279,11 +279,12 @@ impl Action { ctx.write_to_pty(s.clone().into_bytes()) }, Action::Copy => { - ctx.copy_selection(ClipboardBuffer::Primary); + ctx.copy_selection(ClipboardType::Primary); }, Action::Paste => { - Clipboard::new() - .and_then(|clipboard| clipboard.load_primary()) + ctx.terminal_mut() + .clipboard() + .load(ClipboardType::Primary) .map(|contents| self.paste(ctx, &contents)) .unwrap_or_else(|err| { error!("Error loading data from clipboard: {}", Red(err)); @@ -292,8 +293,9 @@ impl Action { Action::PasteSelection => { // Only paste if mouse events are not captured by an application if !mouse_mode { - Clipboard::new() - .and_then(|clipboard| clipboard.load_selection()) + ctx.terminal_mut() + .clipboard() + .load(ClipboardType::Secondary) .map(|contents| self.paste(ctx, &contents)) .unwrap_or_else(|err| { error!("Error loading data from clipboard: {}", Red(err)); @@ -952,9 +954,9 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { /// Copy text selection. fn copy_selection(&mut self) { if self.save_to_clipboard { - self.ctx.copy_selection(ClipboardBuffer::Primary); + self.ctx.copy_selection(ClipboardType::Primary); } - self.ctx.copy_selection(ClipboardBuffer::Selection); + self.ctx.copy_selection(ClipboardType::Secondary); } } @@ -965,6 +967,7 @@ mod tests { use glutin::{ElementState, Event, ModifiersState, MouseButton, VirtualKeyCode, WindowEvent}; + use crate::clipboard::{Clipboard, ClipboardType}; use crate::config::{self, ClickHandler, Config}; use crate::event::{ClickState, Mouse, WindowChanges}; use crate::grid::Scroll; @@ -974,7 +977,6 @@ mod tests { use crate::term::{SizeInfo, Term, TermMode}; use super::{Action, Binding, Processor}; - use copypasta::Buffer as ClipboardBuffer; const KEY: VirtualKeyCode = VirtualKeyCode::Key0; @@ -1004,7 +1006,7 @@ mod tests { fn simple_selection(&mut self, _point: Point, _side: Side) {} - fn copy_selection(&self, _buffer: ClipboardBuffer) {} + fn copy_selection(&mut self, _: ClipboardType) {} fn clear_selection(&mut self) {} @@ -1095,7 +1097,7 @@ mod tests { dpr: 1.0, }; - let mut terminal = Term::new(&config, size, MessageBuffer::new()); + let mut terminal = Term::new(&config, size, MessageBuffer::new(), Clipboard::new_nop()); let mut mouse = Mouse::default(); mouse.click_state = $initial_state; diff --git a/alacritty_terminal/src/lib.rs b/alacritty_terminal/src/lib.rs index ab1ba35e..182d7811 100644 --- a/alacritty_terminal/src/lib.rs +++ b/alacritty_terminal/src/lib.rs @@ -30,6 +30,7 @@ extern crate objc; pub mod macros; pub mod ansi; pub mod cli; +pub mod clipboard; pub mod config; mod cursor; pub mod display; diff --git a/alacritty_termi |