diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-06-09 11:46:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-09 11:46:31 +0000 |
commit | bc2c34eb7f9eea251822d94ea534a1d2de03c5a1 (patch) | |
tree | 8aebbcb1f31dac6f9439f71e784605ca1133ea35 /alacritty_terminal | |
parent | 4cd55acd7820a7358f9175c106c91e0945fb15b2 (diff) |
Add wayland primary selection clipboard support
Diffstat (limited to 'alacritty_terminal')
-rw-r--r-- | alacritty_terminal/Cargo.toml | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/clipboard.rs | 57 | ||||
-rw-r--r-- | alacritty_terminal/src/input.rs | 10 | ||||
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 2 |
4 files changed, 43 insertions, 28 deletions
diff --git a/alacritty_terminal/Cargo.toml b/alacritty_terminal/Cargo.toml index 032191b8..8cd6c5e7 100644 --- a/alacritty_terminal/Cargo.toml +++ b/alacritty_terminal/Cargo.toml @@ -32,7 +32,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" } +copypasta = { path = "../copypasta" } [target.'cfg(unix)'.dependencies] nix = "0.13" diff --git a/alacritty_terminal/src/clipboard.rs b/alacritty_terminal/src/clipboard.rs index a310c991..827559bb 100644 --- a/alacritty_terminal/src/clipboard.rs +++ b/alacritty_terminal/src/clipboard.rs @@ -15,16 +15,19 @@ #[cfg(not(any(target_os = "macos", target_os = "windows")))] use std::ffi::c_void; -use clipboard::nop_clipboard::NopClipboardContext; +use copypasta::nop_clipboard::NopClipboardContext; #[cfg(not(any(target_os = "macos", target_os = "windows")))] -use clipboard::wayland_clipboard::WaylandClipboardContext; +use copypasta::wayland_clipboard::{ + Clipboard as WaylandClipboardClipboard, Primary as WaylandPrimaryClipboard, + WaylandClipboardContext, +}; #[cfg(not(any(target_os = "macos", target_os = "windows")))] -use clipboard::x11_clipboard::{Primary as X11SecondaryClipboard, X11ClipboardContext}; -use clipboard::{ClipboardContext, ClipboardProvider}; +use copypasta::x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}; +use copypasta::{ClipboardContext, ClipboardProvider}; pub struct Clipboard { - primary: Box<ClipboardProvider>, - secondary: Option<Box<ClipboardProvider>>, + clipboard: Box<ClipboardProvider>, + selection: Option<Box<ClipboardProvider>>, } impl Clipboard { @@ -37,41 +40,53 @@ impl Clipboard { 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, + clipboard: unsafe { + Box::new( + WaylandClipboardContext::<WaylandClipboardClipboard>::new_from_external( + display, + ), + ) + }, + selection: unsafe { + Some(Box::new( + WaylandClipboardContext::<WaylandPrimaryClipboard>::new_from_external( + display, + ), + )) + }, }; } Self { - primary: Box::new(ClipboardContext::new().unwrap()), - secondary: Some(Box::new(X11ClipboardContext::<X11SecondaryClipboard>::new().unwrap())), + clipboard: Box::new(ClipboardContext::new().unwrap()), + selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), } } // Use for tests and ref-tests pub fn new_nop() -> Self { - Self { primary: Box::new(NopClipboardContext::new().unwrap()), secondary: None } + Self { clipboard: Box::new(NopClipboardContext::new().unwrap()), selection: None } } } impl Default for Clipboard { fn default() -> Self { - Self { primary: Box::new(ClipboardContext::new().unwrap()), secondary: None } + Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None } } } #[derive(Debug)] pub enum ClipboardType { - Primary, - Secondary, + Clipboard, + Selection, } 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, + let clipboard = match (ty, &mut self.selection) { + (ClipboardType::Selection, Some(provider)) => provider, + (ClipboardType::Selection, None) => return, + _ => &mut self.clipboard, }; clipboard.set_contents(text.into()).unwrap_or_else(|err| { @@ -80,9 +95,9 @@ impl Clipboard { } pub fn load(&mut self, ty: ClipboardType) -> String { - let clipboard = match (ty, &mut self.secondary) { - (ClipboardType::Secondary, Some(provider)) => provider, - _ => &mut self.primary, + let clipboard = match (ty, &mut self.selection) { + (ClipboardType::Selection, Some(provider)) => provider, + _ => &mut self.clipboard, }; match clipboard.get_contents() { diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs index bd1610a2..17d427cd 100644 --- a/alacritty_terminal/src/input.rs +++ b/alacritty_terminal/src/input.rs @@ -280,16 +280,16 @@ impl Action { ctx.write_to_pty(s.clone().into_bytes()) }, Action::Copy => { - ctx.copy_selection(ClipboardType::Primary); + ctx.copy_selection(ClipboardType::Clipboard); }, Action::Paste => { - let text = ctx.terminal_mut().clipboard().load(ClipboardType::Primary); + let text = ctx.terminal_mut().clipboard().load(ClipboardType::Clipboard); self.paste(ctx, &text); }, Action::PasteSelection => { // Only paste if mouse events are not captured by an application if !mouse_mode { - let text = ctx.terminal_mut().clipboard().load(ClipboardType::Secondary); + let text = ctx.terminal_mut().clipboard().load(ClipboardType::Selection); self.paste(ctx, &text); } }, @@ -939,9 +939,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(ClipboardType::Primary); + self.ctx.copy_selection(ClipboardType::Clipboard); } - self.ctx.copy_selection(ClipboardType::Secondary); + self.ctx.copy_selection(ClipboardType::Selection); } } diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 2ec0621a..5cfd503d 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1897,7 +1897,7 @@ impl ansi::Handler for Term { /// Set the clipboard #[inline] fn set_clipboard(&mut self, string: &str) { - self.clipboard.store(ClipboardType::Primary, string); + self.clipboard.store(ClipboardType::Clipboard, string); } #[inline] |