screenshot: Promisify PickPixel

Same as the previous commit, but for PickPixel.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/903
This commit is contained in:
Florian Müllner 2019-12-19 03:53:51 +01:00
parent 9db62236da
commit 3c87ad5aab

View File

@ -256,14 +256,15 @@ var ScreenshotService = class {
invocation.return_value(null); invocation.return_value(null);
} }
PickColorAsync(params, invocation) { async PickColorAsync(params, invocation) {
let pickPixel = new PickPixel(); let pickPixel = new PickPixel();
pickPixel.show(); try {
pickPixel.connect('finished', (obj, coords) => { const coords = await pickPixel.pickAsync();
if (coords) {
let screenshot = this._createScreenshot(invocation, false); let screenshot = this._createScreenshot(invocation, false);
if (!screenshot) if (!screenshot)
return; return;
screenshot.pick_color(coords.x, coords.y, (_o, res) => { screenshot.pick_color(coords.x, coords.y, (_o, res) => {
let [success_, color] = screenshot.pick_color_finish(res); let [success_, color] = screenshot.pick_color_finish(res);
let { red, green, blue } = color; let { red, green, blue } = color;
@ -277,11 +278,11 @@ var ScreenshotService = class {
this._removeShooterForSender(invocation.get_sender()); this._removeShooterForSender(invocation.get_sender());
invocation.return_value(retval); invocation.return_value(retval);
}); });
} else { } catch (e) {
invocation.return_error_literal(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED, invocation.return_error_literal(
"Operation was cancelled"); Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
'Operation was cancelled');
} }
});
} }
}; };
@ -378,9 +379,8 @@ class SelectArea extends St.Widget {
} }
}); });
var PickPixel = GObject.registerClass({ var PickPixel = GObject.registerClass(
Signals: { 'finished': { param_types: [Graphene.Point.$gtype] } }, class PickPixel extends St.Widget {
}, class PickPixel extends St.Widget {
_init() { _init() {
super._init({ visible: false, reactive: true }); super._init({ visible: false, reactive: true });
@ -395,14 +395,21 @@ var PickPixel = GObject.registerClass({
this.add_constraint(constraint); this.add_constraint(constraint);
} }
vfunc_show() { async pickAsync() {
if (!this._grabHelper.grab({ actor: this,
onUngrab: this._onUngrab.bind(this) }))
return;
global.display.set_cursor(Meta.Cursor.CROSSHAIR); global.display.set_cursor(Meta.Cursor.CROSSHAIR);
Main.uiGroup.set_child_above_sibling(this, null); Main.uiGroup.set_child_above_sibling(this, null);
super.vfunc_show(); this.show();
await this._grabHelper.grabAsync({ actor: this });
global.display.set_cursor(Meta.Cursor.DEFAULT);
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
this.destroy();
return GLib.SOURCE_REMOVE;
});
return this._result;
} }
vfunc_button_release_event(buttonEvent) { vfunc_button_release_event(buttonEvent) {
@ -411,16 +418,6 @@ var PickPixel = GObject.registerClass({
this._grabHelper.ungrab(); this._grabHelper.ungrab();
return Clutter.EVENT_PROPAGATE; return Clutter.EVENT_PROPAGATE;
} }
_onUngrab() {
global.display.set_cursor(Meta.Cursor.DEFAULT);
this.emit('finished', this._result);
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
this.destroy();
return GLib.SOURCE_REMOVE;
});
}
}); });
var FLASHSPOT_ANIMATION_OUT_TIME = 500; // milliseconds var FLASHSPOT_ANIMATION_OUT_TIME = 500; // milliseconds