mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
parent
5cf77bf250
commit
1da986ae2b
6 changed files with 40 additions and 56 deletions
|
@ -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
|
||||
|
||||
|
|
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
impl ClipboardType for Clipboard {}
|
||||
|
||||
pub struct Primary;
|
||||
impl ClipboardType for Primary {}
|
||||
|
||||
pub struct WaylandClipboardContext<T: ClipboardType>(WaylandClipboard, PhantomData<T>);
|
||||
|
||||
impl<T: ClipboardType> WaylandClipboardContext<T> {
|
||||
/// Create a new clipboard context.
|
||||
pub fn new(display: &Display) -> Self {
|
||||
WaylandClipboardContext(WaylandClipboard::new(display), PhantomData)
|
||||
pub struct Clipboard {
|
||||
context: Arc<Mutex<WaylandClipboard>>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
)
|
||||
}
|
||||
pub struct Primary {
|
||||
context: Arc<Mutex<WaylandClipboard>>,
|
||||
}
|
||||
|
||||
impl ClipboardProvider for WaylandClipboardContext<Clipboard> {
|
||||
pub fn create_clipboards(display: &Display) -> (Primary, Clipboard) {
|
||||
let context = Arc::new(Mutex::new(WaylandClipboard::new(display)));
|
||||
|
||||
(Primary { context: context.clone() }, Clipboard { context } )
|
||||
}
|
||||
|
||||
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)));
|
||||
|
||||
(Primary { context: context.clone() }, Clipboard { context} )
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue