summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <wchibisovkirill@gmail.com>2019-08-12 02:16:24 +0300
committerChristian Duerr <contact@christianduerr.com>2019-08-16 01:33:37 +0200
commit1da986ae2b5dd7c54875d45716eb2820920feaae (patch)
tree84809cb43ba098262c25ed798721242f60e8062f
parent5cf77bf250712bf2630322f92c1025baa364922e (diff)
downloadalacritty-1da986ae2b5dd7c54875d45716eb2820920feaae.tar.gz
alacritty-1da986ae2b5dd7c54875d45716eb2820920feaae.zip
Fix smithay-clipboard integration
Fixes: #2574
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.lock6
-rw-r--r--alacritty_terminal/src/clipboard.rs24
-rw-r--r--copypasta/Cargo.toml2
-rw-r--r--copypasta/examples/wayland.rs4
-rw-r--r--copypasta/src/wayland_clipboard.rs49
6 files changed, 35 insertions, 51 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14871794..42120618 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Selecting trailing tab with semantic expansion
- URL parser incorrectly handling Markdown URLs and angled brackets
- Intermediate bytes of CSI sequences not checked
+- Wayland clipboard integration
## 0.3.3
diff --git a/Cargo.lock b/Cargo.lock
index ea8b4f96..1c02d54d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -360,7 +360,7 @@ dependencies = [
"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-client-toolkit 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "smithay-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "smithay-clipboard 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wayland-client 0.23.5 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1997,7 +1997,7 @@ dependencies = [
[[package]]
name = "smithay-clipboard"
-version = "0.3.3"
+version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2762,7 +2762,7 @@ dependencies = [
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum smithay-client-toolkit 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2ccb8c57049b2a34d2cc2b203fa785020ba0129d31920ef0d317430adaf748fa"
"checksum smithay-client-toolkit 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8c23093ebdaac1ad67558c7aef153522c6b3be7e0257820909e3a25c4519e78d"
-"checksum smithay-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e61f8a9ef7a15bd38c29b4a39d423776b2d6092723dc7df3f0545ce7a4751e"
+"checksum smithay-clipboard 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f396e0b3877db6855c2df5c730e7fbf547e92aee6cd4d4331d4536f52556e944"
"checksum socket2 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df028e0e632c2a1823d920ad74895e7f9128e6438cbc4bc6fd1f180e644767b9"
"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"
diff --git a/alacritty_terminal/src/clipboard.rs b/alacritty_terminal/src/clipboard.rs
index 0e40cd47..dc826481 100644
--- a/alacritty_terminal/src/clipboard.rs
+++ b/alacritty_terminal/src/clipboard.rs
@@ -17,10 +17,7 @@ use std::ffi::c_void;
use copypasta::nop_clipboard::NopClipboardContext;
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
-use copypasta::wayland_clipboard::{
- Clipboard as WaylandClipboardClipboard, Primary as WaylandPrimaryClipboard,
- WaylandClipboardContext,
-};
+use copypasta::wayland_clipboard;
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
use copypasta::x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext};
use copypasta::{ClipboardContext, ClipboardProvider};
@@ -39,22 +36,9 @@ impl Clipboard {
#[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 {
- clipboard: unsafe {
- Box::new(
- WaylandClipboardContext::<WaylandClipboardClipboard>::new_from_external(
- display,
- ),
- )
- },
- selection: unsafe {
- Some(Box::new(
- WaylandClipboardContext::<WaylandPrimaryClipboard>::new_from_external(
- display,
- ),
- ))
- },
- };
+ let (selection, clipboard) =
+ unsafe { wayland_clipboard::create_clipboards_from_external(display) };
+ return Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) };
}
Self {
diff --git a/copypasta/Cargo.toml b/copypasta/Cargo.toml
index ae65a7cb..3b9dd48c 100644
--- a/copypasta/Cargo.toml
+++ b/copypasta/Cargo.toml
@@ -17,7 +17,7 @@ objc-foundation = "0.1"
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies]
x11-clipboard = "0.3"
-smithay-clipboard = "0.3.2"
+smithay-clipboard = "0.3.4"
wayland-client = { version = "0.23.3", features = ["dlopen"] }
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dev-dependencies]
diff --git a/copypasta/examples/wayland.rs b/copypasta/examples/wayland.rs
index a718a3e8..159b708c 100644
--- a/copypasta/examples/wayland.rs
+++ b/copypasta/examples/wayland.rs
@@ -14,7 +14,7 @@ mod wayland {
extern crate copypasta;
extern crate smithay_client_toolkit as sctk;
- use wayland::copypasta::wayland_clipboard::{Clipboard, WaylandClipboardContext};
+ use wayland::copypasta::wayland_clipboard::create_clipboards;
use wayland::copypasta::ClipboardProvider;
use std::io::{Read, Seek, SeekFrom, Write};
@@ -37,7 +37,7 @@ mod wayland {
Display::connect_to_env().expect("Failed to connect to the wayland server.");
let env = Environment::from_display(&*display, &mut event_queue).unwrap();
- let mut ctx = WaylandClipboardContext::<Clipboard>::new(&display);
+ let (mut ctx, _) = create_clipboards(&display);
let cb_contents = Arc::new(Mutex::new(String::new()));
let seat = env.manager.instantiate_range(2, 6, NewProxy::implement_dummy).unwrap();
diff --git a/copypasta/src/wayland_clipboard.rs b/copypasta/src/wayland_clipboard.rs
index cb450725..b32f1290 100644
--- a/copypasta/src/wayland_clipboard.rs
+++ b/copypasta/src/wayland_clipboard.rs
@@ -14,57 +14,56 @@
use std::error::Error;
use std::ffi::c_void;
-use std::marker::PhantomData;
+use std::sync::{Arc, Mutex};
use smithay_clipboard::WaylandClipboard;
+
use wayland_client::sys::client::wl_display;
use wayland_client::Display;
use common::ClipboardProvider;
-pub trait ClipboardType: Send {}
+pub struct Clipboard {
+ context: Arc<Mutex<WaylandClipboard>>,
+}
-pub struct Clipboard;
-impl ClipboardType for Clipboard {}
+pub struct Primary {
+ context: Arc<Mutex<WaylandClipboard>>,
+}
-pub struct Primary;
-impl ClipboardType for Primary {}
+pub fn create_clipboards(display: &Display) -> (Primary, Clipboard) {
+ let context = Arc::new(Mutex::new(WaylandClipboard::new(display)));
-pub struct WaylandClipboardContext<T: ClipboardType>(WaylandClipboard, PhantomData<T>);
+ (Primary { context: context.clone() }, Clipboard { context } )
+}
-impl<T: ClipboardType> WaylandClipboardContext<T> {
- /// Create a new clipboard context.
- pub fn new(display: &Display) -> Self {
- WaylandClipboardContext(WaylandClipboard::new(display), PhantomData)
- }
+pub unsafe fn create_clipboards_from_external(display: *mut c_void) -> (Primary, Clipboard) {
+ let context =
+ Arc::new(Mutex::new(WaylandClipboard::new_from_external(display as *mut wl_display)));
- /// Create a new clipboard context from an external pointer.
- pub unsafe fn new_from_external(display: *mut c_void) -> Self {
- WaylandClipboardContext(
- WaylandClipboard::new_from_external(display as *mut wl_display),
- PhantomData,
- )
- }
+ (Primary { context: context.clone() }, Clipboard { context} )
}
-impl ClipboardProvider for WaylandClipboardContext<Clipboard> {
+impl ClipboardProvider for Clipboard {
fn get_contents(&mut self) -> Result<String, Box<dyn Error>> {
- Ok(self.0.load(None))
+ Ok(self.context.lock().unwrap().load(None))
}
fn set_contents(&mut self, data: String) -> Result<(), Box<dyn Error>> {
- self.0.store(None, data);
+ self.context.lock().unwrap().store(None, data);
+
Ok(())
}
}
-impl ClipboardProvider for WaylandClipboardContext<Primary> {
+impl ClipboardProvider for Primary {
fn get_contents(&mut self) -> Result<String, Box<dyn Error>> {
- Ok(self.0.load_primary(None))
+ Ok(self.context.lock().unwrap().load_primary(None))
}
fn set_contents(&mut self, data: String) -> Result<(), Box<dyn Error>> {
- self.0.store_primary(None, data);
+ self.context.lock().unwrap().store_primary(None, data);
+
Ok(())
}
}