Skip to content

Commit

Permalink
GTK Shell: Manually retrieve textual data from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ForLoveOfCats committed Apr 5, 2021
1 parent 5138e8b commit a40f334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You can find its changes [documented below](#070---2021-01-01).
### Fixed
- `Notification`s will not be delivered to the widget that sends them ([#1640] by [@cmyr])
- `TextBox` can handle standard keyboard shortcuts without needing menus ([#1660] by [@cmyr])
- GTK Shell: Prevent mangling of newline characters in clipboard ([#1695] by [@ForLoveOfCats])


- Fixed docs of derived Lens ([#1523] by [@Maan2003])
Expand Down Expand Up @@ -661,6 +662,7 @@ Last release without a changelog :(
[#1662]: https://github.com/linebender/druid/pull/1662
[#1677]: https://github.com/linebender/druid/pull/1677
[#1698]: https://github.com/linebender/druid/pull/1698
[#1695]: https://github.com/linebender/druid/pull/1695

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
20 changes: 19 additions & 1 deletion druid-shell/src/platform/gtk/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,25 @@ impl Clipboard {
pub fn get_string(&self) -> Option<String> {
let display = gdk::Display::get_default().unwrap();
let clipboard = gtk::Clipboard::get_default(&display).unwrap();
clipboard.wait_for_text().map(|s| s.to_string())

let targets = [
"UTF8_STRING",
"TEXT",
"STRING",
"text/plain;charset=utf-8",
"text/plain",
];

for target in &targets {
let atom = Atom::intern(target);
if let Some(selection) = clipboard.wait_for_contents(&atom) {
return std::str::from_utf8(&selection.get_data())
.ok()
.map(|text| text.to_string());
}
}

None
}

/// Given a list of supported clipboard types, returns the supported type which has
Expand Down

0 comments on commit a40f334

Please sign in to comment.