window: allow specifying the clipboard context when getting clipboard
refs: https://github.com/wez/wezterm/issues/183
This commit is contained in:
1 parent
fa86850a85
commit
a9d1429888
7 files changed
+45
-24
No files matched your search
@@ -1374,7 +1374,11 @@ impl TermWindow {
|
||||
}
|
||||
Paste => {
|
||||
let tab_id = tab.tab_id();
|
||||
let future = self.window.as_ref().unwrap().get_clipboard();
|
||||
let future = self
|
||||
.window
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get_clipboard(Clipboard::default());
|
||||
promise::spawn::spawn(async move {
|
||||
if let Ok(clip) = future.await {
|
||||
let mux = Mux::get().unwrap();
|
||||
@@ -2949,7 +2953,11 @@ impl TermWindow {
|
||||
}),
|
||||
) => {
|
||||
let tab_id = tab.tab_id();
|
||||
let future = self.window.as_ref().unwrap().get_clipboard();
|
||||
let future = self
|
||||
.window
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get_clipboard(Clipboard::default());
|
||||
promise::spawn::spawn(async move {
|
||||
if let Ok(clip) = future.await {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
+13
-1
@@ -47,6 +47,18 @@ pub enum Operator {
|
||||
MultiplyThenOver(Color),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Clipboard {
|
||||
Clipboard,
|
||||
PrimarySelection,
|
||||
}
|
||||
|
||||
impl Default for Clipboard {
|
||||
fn default() -> Self {
|
||||
Self::Clipboard
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Dimensions {
|
||||
pub pixel_width: usize,
|
||||
@@ -224,7 +236,7 @@ pub trait WindowOps {
|
||||
R: Send + 'static;
|
||||
|
||||
/// Initiate textual transfer from the clipboard
|
||||
fn get_clipboard(&self) -> Future<String>;
|
||||
fn get_clipboard(&self, clipboard: Clipboard) -> Future<String>;
|
||||
|
||||
/// Set some text in the clipboard
|
||||
fn set_clipboard(&self, text: String) -> Future<()>;
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::bitmaps::Image;
|
||||
use crate::connection::ConnectionOps;
|
||||
use crate::os::macos::bitmap::BitmapRef;
|
||||
use crate::{
|
||||
BitmapImage, Color, Connection, Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons,
|
||||
MouseCursor, MouseEvent, MouseEventKind, MousePress, Operator, PaintContext, Point, Rect,
|
||||
ScreenPoint, Size, WindowCallbacks, WindowOps, WindowOpsMut,
|
||||
BitmapImage, Clipboard, Color, Connection, Dimensions, KeyCode, KeyEvent, Modifiers,
|
||||
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Operator, PaintContext,
|
||||
Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowOps, WindowOpsMut,
|
||||
};
|
||||
use anyhow::{anyhow, bail, ensure};
|
||||
use cocoa::appkit::{
|
||||
@@ -479,7 +479,7 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_clipboard(&self) -> Future<String> {
|
||||
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
|
||||
use clipboard::ClipboardProvider;
|
||||
Future::result(
|
||||
clipboard::ClipboardContext::new()
|
||||
|
||||
@@ -8,8 +8,8 @@ use crate::input::*;
|
||||
use crate::os::wayland::connection::WaylandConnection;
|
||||
use crate::os::xkeysyms::keysym_to_keycode;
|
||||
use crate::{
|
||||
Connection, Dimensions, MouseCursor, Operator, PaintContext, Point, Rect, ScreenPoint, Window,
|
||||
WindowCallbacks, WindowOps, WindowOpsMut,
|
||||
Clipboard, Connection, Dimensions, MouseCursor, Operator, PaintContext, Point, Rect,
|
||||
ScreenPoint, Window, WindowCallbacks, WindowOps, WindowOpsMut,
|
||||
};
|
||||
use anyhow::{anyhow, bail, Context};
|
||||
use filedescriptor::FileDescriptor;
|
||||
@@ -758,7 +758,7 @@ impl WindowOps for WaylandWindow {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_clipboard(&self) -> Future<String> {
|
||||
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
|
||||
let mut promise = Promise::new();
|
||||
let future = promise.get_future().unwrap();
|
||||
let promise = Arc::new(Mutex::new(promise));
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::bitmaps::*;
|
||||
use crate::color::Color;
|
||||
use crate::connection::ConnectionOps;
|
||||
use crate::{
|
||||
Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, MouseEvent,
|
||||
Clipboard, Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, MouseEvent,
|
||||
MouseEventKind, MousePress, Operator, PaintContext, Point, Rect, ScreenPoint, WindowCallbacks,
|
||||
WindowOps, WindowOpsMut,
|
||||
};
|
||||
@@ -434,7 +434,7 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_clipboard(&self) -> Future<String> {
|
||||
fn get_clipboard(&self, _clipboard: Clipboard) -> Future<String> {
|
||||
Future::result(clipboard_win::get_clipboard_string().context("Error getting clipboard"))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::connection::ConnectionOps;
|
||||
use crate::os::xkeysyms;
|
||||
use crate::os::{Connection, Window};
|
||||
use crate::{
|
||||
Color, Dimensions, KeyEvent, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress,
|
||||
Operator, PaintContext, Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowOps,
|
||||
Clipboard, Color, Dimensions, KeyEvent, MouseButtons, MouseCursor, MouseEvent, MouseEventKind,
|
||||
MousePress, Operator, PaintContext, Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowOps,
|
||||
WindowOpsMut,
|
||||
};
|
||||
use anyhow::anyhow;
|
||||
@@ -970,7 +970,7 @@ impl WindowOps for XWindow {
|
||||
}
|
||||
|
||||
/// Initiate textual transfer from the clipboard
|
||||
fn get_clipboard(&self) -> Future<String> {
|
||||
fn get_clipboard(&self, clipboard: Clipboard) -> Future<String> {
|
||||
let mut promise = Promise::new();
|
||||
let future = promise.get_future().unwrap();
|
||||
let mut promise = Some(promise);
|
||||
@@ -989,11 +989,12 @@ impl WindowOps for XWindow {
|
||||
xcb::convert_selection(
|
||||
&inner.conn,
|
||||
inner.window_id,
|
||||
// Important: we request the clipboard rather than the
|
||||
// primary selection because, under wayland, access to the
|
||||
// primary selection is forbidden by default citing a security
|
||||
// concern.
|
||||
inner.conn.atom_clipboard,
|
||||
// Note that under xwayland, access to the primary selection is
|
||||
// forbidden by default citing a security concern.
|
||||
match clipboard {
|
||||
Clipboard::Clipboard => inner.conn.atom_clipboard,
|
||||
Clipboard::PrimarySelection => xcb::ATOM_PRIMARY,
|
||||
},
|
||||
inner.conn.atom_utf8_string,
|
||||
inner.conn.atom_xsel_data,
|
||||
inner.copy_and_paste.time,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::os::wayland::connection::WaylandConnection;
|
||||
use crate::os::wayland::window::WaylandWindow;
|
||||
use crate::os::x11::connection::XConnection;
|
||||
use crate::os::x11::window::XWindow;
|
||||
use crate::{MouseCursor, ScreenPoint, WindowCallbacks, WindowOps};
|
||||
use crate::{Clipboard, MouseCursor, ScreenPoint, WindowCallbacks, WindowOps};
|
||||
use promise::*;
|
||||
use std::any::Any;
|
||||
use std::rc::Rc;
|
||||
@@ -243,11 +243,11 @@ impl WindowOps for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_clipboard(&self) -> Future<String> {
|
||||
fn get_clipboard(&self, clipboard: Clipboard) -> Future<String> {
|
||||
match self {
|
||||
Self::X11(x) => x.get_clipboard(),
|
||||
Self::X11(x) => x.get_clipboard(clipboard),
|
||||
#[cfg(feature = "wayland")]
|
||||
Self::Wayland(w) => w.get_clipboard(),
|
||||
Self::Wayland(w) => w.get_clipboard(clipboard),
|
||||
}
|
||||
}
|
||||
fn set_clipboard(&self, text: String) -> Future<()> {
|
||||
|
||||
Reference in new issue
Block a user