diff --git a/src/xgfx.rs b/src/xgfx.rs index ab173ebbb..ebd1796c3 100644 --- a/src/xgfx.rs +++ b/src/xgfx.rs @@ -27,6 +27,7 @@ pub struct Connection { pub atom_utf8_string: xcb::Atom, pub atom_xsel_data: xcb::Atom, pub atom_targets: xcb::Atom, + pub atom_clipboard: xcb::Atom, keysyms: *mut xcb_key_symbols_t, egl_display: Rc, egl_config: egli::FrameBufferConfigRef, @@ -75,6 +76,9 @@ impl Connection { let atom_targets = xcb::intern_atom(&conn, false, "TARGETS") .get_reply()? .atom(); + let atom_clipboard = xcb::intern_atom(&conn, false, "CLIPBOARD") + .get_reply()? + .atom(); let keysyms = unsafe { xcb_key_symbols_alloc(conn.get_raw_conn()) }; @@ -108,6 +112,7 @@ impl Connection { conn, screen_num, atom_protocols, + atom_clipboard, atom_delete, keysyms, atom_utf8_string, diff --git a/src/xwin.rs b/src/xwin.rs index f415047b9..d2b87aad1 100644 --- a/src/xwin.rs +++ b/src/xwin.rs @@ -356,6 +356,18 @@ impl<'a> term::TerminalHost for Host<'a> { xcb::ATOM_PRIMARY, self.timestamp, ); + // Also set the CLIPBOARD atom, not just the PRIMARY selection. + // TODO: make xterm clipboard selection configurable + xcb::set_selection_owner( + conn.conn(), + if self.clipboard.is_some() { + self.window.as_drawable() + } else { + xcb::NONE + }, + conn.atom_clipboard, + self.timestamp, + ); // TODO: icccm says that we should check that we got ownership and // amend our UI accordingly @@ -1337,13 +1349,13 @@ impl<'a> TerminalWindow<'a> { request.property() ); debug!( - "XSEL={}, UTF8={} PRIMARY={}", + "XSEL={}, UTF8={} PRIMARY={} clip={}", self.conn.atom_xsel_data, self.conn.atom_utf8_string, xcb::ATOM_PRIMARY, + self.conn.atom_clipboard, ); - // I'd like to use `match` here, but the atom values are not // known at compile time so we have to `if` like a caveman :-p let selprop = if request.target() == self.conn.atom_targets {