Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ You can find its changes [documented below](#070---2021-01-01).
- X11: Added support for `get_monitors` ([#1804] by [@psychon])
- x11: Remove some unnecessary casts ([#1851] by [@psychon])
- `has_focus` method on `WidgetPod` ([#1825] by [@ForLoveOfCats])
- x11: Add support for getting clipboard contents ([#1805] by [@psychon])
- x11: Add support for getting and setting clipboard contents ([#1805] and [#1851] by [@psychon])
- Linux extension: primary_clipboard ([#1843] by [@Maan2003])

### Changed
Expand Down
36 changes: 29 additions & 7 deletions druid-shell/src/backend/x11/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub(crate) struct Application {
/// The X11 resource database used to query dpi.
pub(crate) rdb: Rc<ResourceDb>,
pub(crate) cursors: Cursors,
/// The clipboard implementation
clipboard: Clipboard,
/// The default screen of the connected display.
///
/// The connected display may also have additional screens.
Expand Down Expand Up @@ -211,6 +213,15 @@ impl Application {
.ok_or_else(|| anyhow!("Couldn't get visual from screen"))?;
let argb_visual_type = util::get_argb_visual_type(&*connection, &screen)?;

let timestamp = Rc::new(Cell::new(x11rb::CURRENT_TIME));
let pending_events = Default::default();
let clipboard = Clipboard::new(
Rc::clone(&connection),
screen_num,
Rc::clone(&pending_events),
Rc::clone(&timestamp),
)?;

Ok(Application {
connection,
rdb,
Expand All @@ -219,14 +230,15 @@ impl Application {
state,
idle_read,
cursors,
clipboard,
idle_write,
present_opcode,
root_visual_type,
argb_visual_type,
pending_events: Default::default(),
marker: std::marker::PhantomData,
render_argb32_pictformat_cursor,
timestamp: Rc::new(Cell::new(x11rb::CURRENT_TIME)),
timestamp,
})
}

Expand Down Expand Up @@ -497,6 +509,21 @@ impl Application {
w.handle_idle_notify(ev)
.context("IDLE_NOTIFY - failed to handle")?;
}
Event::SelectionClear(ev) => {
self.clipboard
.handle_clear(*ev)
.context("SELECTION_CLEAR event handling")?;
}
Event::SelectionRequest(ev) => {
self.clipboard
.handle_request(ev)
.context("SELECTION_REQUEST event handling")?;
}
Event::PropertyNotify(ev) => {
self.clipboard
.handle_property_notify(*ev)
.context("PROPERTY_NOTIFY event handling")?;
}
Event::Error(e) => {
// TODO: if an error is caused by the present extension, disable it and fall back
// to copying pixels. This is blocked on
Expand Down Expand Up @@ -633,12 +660,7 @@ impl Application {
}

pub fn clipboard(&self) -> Clipboard {
Clipboard::new(
Rc::clone(&self.connection),
self.screen_num,
Rc::clone(&self.pending_events),
Rc::clone(&self.timestamp),
)
self.clipboard.clone()
}

pub fn get_locale() -> String {
Expand Down
Loading