search: copy result to clipboard if requested

Some search providers such as GNOME Characters want to copy search
results to clipboard.  However, on Wayland, clipboards are only
accessible from applications that have a visible surface on display.

This patch allows a search provider to request the shell to copy a
search result to clipboard when 'clipboardText' is included in the meta
of the result.

https://bugzilla.gnome.org/show_bug.cgi?id=775099
This commit is contained in:
Daiki Ueno 2017-05-03 10:28:31 +02:00
parent 65b9369aaf
commit 6734746707
2 changed files with 6 additions and 1 deletions

View File

@ -278,7 +278,8 @@ const RemoteSearchProvider = new Lang.Class({
name: metas[i]['name'], name: metas[i]['name'],
description: metas[i]['description'], description: metas[i]['description'],
createIcon: Lang.bind(this, createIcon: Lang.bind(this,
this.createIcon, metas[i]) }); this.createIcon, metas[i]),
clipboardText: metas[i]['clipboardText'] });
} }
callback(resultMetas); callback(resultMetas);
}, },

View File

@ -152,6 +152,8 @@ const SearchResultsBase = new Lang.Class({
this._resultDisplays = {}; this._resultDisplays = {};
this._clipboard = St.Clipboard.get_default();
this._cancellable = new Gio.Cancellable(); this._cancellable = new Gio.Cancellable();
}, },
@ -181,6 +183,8 @@ const SearchResultsBase = new Lang.Class({
_activateResult: function(result, id) { _activateResult: function(result, id) {
this.provider.activateResult(id, this._terms); this.provider.activateResult(id, this._terms);
if (result.metaInfo.clipboardText)
this._clipboard.set_text(St.ClipboardType.CLIPBOARD, result.metaInfo.clipboardText);
Main.overview.toggle(); Main.overview.toggle();
}, },