2012-12-10 10:26:31 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported ScreenshotService */
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
const { Clutter, Graphene, Gio, GObject, GLib, Meta, Shell, St } = imports.gi;
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2014-04-25 12:43:10 -04:00
|
|
|
const GrabHelper = imports.ui.grabHelper;
|
2012-12-10 10:26:31 -05:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
|
|
|
const ScreenshotIface = loadInterfaceXML('org.gnome.Shell.Screenshot');
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var ScreenshotService = class {
|
|
|
|
constructor() {
|
2012-12-10 10:26:31 -05:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreenshotIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Screenshot');
|
|
|
|
|
2014-09-27 07:35:22 -04:00
|
|
|
this._screenShooter = new Map();
|
|
|
|
|
2014-10-03 10:33:37 -04:00
|
|
|
this._lockdownSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.lockdown' });
|
|
|
|
|
2012-12-10 10:26:31 -05:00
|
|
|
Gio.DBus.session.own_name('org.gnome.Shell.Screenshot', Gio.BusNameOwnerFlags.REPLACE, null, null);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-01-28 20:27:05 -05:00
|
|
|
_createScreenshot(invocation, needsDisk = true) {
|
2018-07-19 13:23:46 -04:00
|
|
|
let lockedDown = false;
|
|
|
|
if (needsDisk)
|
2019-01-28 20:18:52 -05:00
|
|
|
lockedDown = this._lockdownSettings.get_boolean('disable-save-to-disk');
|
2018-07-19 13:23:46 -04:00
|
|
|
|
2014-09-27 07:35:22 -04:00
|
|
|
let sender = invocation.get_sender();
|
2018-07-19 13:23:46 -04:00
|
|
|
if (this._screenShooter.has(sender) || lockedDown) {
|
2014-09-27 07:35:22 -04:00
|
|
|
invocation.return_value(GLib.Variant.new('(bs)', [false, '']));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let shooter = new Shell.Screenshot();
|
|
|
|
shooter._watchNameId =
|
|
|
|
Gio.bus_watch_name(Gio.BusType.SESSION, sender, 0, null,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onNameVanished.bind(this));
|
2014-09-27 07:35:22 -04:00
|
|
|
|
|
|
|
this._screenShooter.set(sender, shooter);
|
|
|
|
|
|
|
|
return shooter;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-27 07:35:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onNameVanished(connection, name) {
|
2014-09-27 07:35:22 -04:00
|
|
|
this._removeShooterForSender(name);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-27 07:35:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_removeShooterForSender(sender) {
|
2014-09-27 07:35:22 -04:00
|
|
|
let shooter = this._screenShooter.get(sender);
|
|
|
|
if (!shooter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Gio.bus_unwatch_name(shooter._watchNameId);
|
|
|
|
this._screenShooter.delete(sender);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-27 07:35:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_checkArea(x, y, width, height) {
|
2014-06-04 10:26:06 -04:00
|
|
|
return x >= 0 && y >= 0 &&
|
|
|
|
width > 0 && height > 0 &&
|
|
|
|
x + width <= global.screen_width &&
|
|
|
|
y + height <= global.screen_height;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-04 10:26:06 -04:00
|
|
|
|
2019-11-05 18:46:41 -05:00
|
|
|
*_resolveRelativeFilename(filename) {
|
|
|
|
if (GLib.str_has_suffix(filename, '.png'))
|
|
|
|
filename = filename.substr(0, -4);
|
|
|
|
|
|
|
|
let path = [
|
|
|
|
GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES),
|
|
|
|
GLib.get_home_dir(),
|
|
|
|
].find(p => GLib.file_test(p, GLib.FileTest.EXISTS));
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
yield Gio.File.new_for_path(
|
|
|
|
GLib.build_filenamev([path, `${filename}.png`]));
|
|
|
|
|
|
|
|
for (let idx = 1; ; idx++) {
|
|
|
|
yield Gio.File.new_for_path(
|
|
|
|
GLib.build_filenamev([path, `${filename}-${idx}.png`]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_createStream(filename) {
|
2019-11-05 18:48:25 -05:00
|
|
|
if (filename == '')
|
|
|
|
return [Gio.MemoryOutputStream.new_resizable(), null];
|
|
|
|
|
2019-11-05 18:46:41 -05:00
|
|
|
if (GLib.path_is_absolute(filename)) {
|
|
|
|
try {
|
|
|
|
let file = Gio.File.new_for_path(filename);
|
|
|
|
let stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null);
|
|
|
|
return [stream, file];
|
|
|
|
} catch (e) {
|
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let file of this._resolveRelativeFilename(filename)) {
|
|
|
|
try {
|
|
|
|
let stream = file.create(Gio.FileCreateFlags.NONE, null);
|
|
|
|
return [stream, file];
|
|
|
|
} catch (e) {
|
|
|
|
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS))
|
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
|
|
|
|
_onScreenshotComplete(result, area, stream, file, flash, invocation) {
|
2014-09-27 07:35:22 -04:00
|
|
|
if (result) {
|
|
|
|
if (flash) {
|
|
|
|
let flashspot = new Flashspot(area);
|
2017-10-30 20:38:18 -04:00
|
|
|
flashspot.fire(() => {
|
2014-09-27 07:35:22 -04:00
|
|
|
this._removeShooterForSender(invocation.get_sender());
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-01-29 16:02:57 -05:00
|
|
|
} else {
|
2014-09-27 07:35:22 -04:00
|
|
|
this._removeShooterForSender(invocation.get_sender());
|
2019-01-29 16:02:57 -05:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
}
|
|
|
|
|
2019-11-05 18:46:41 -05:00
|
|
|
stream.close(null);
|
|
|
|
|
2019-11-05 18:48:25 -05:00
|
|
|
let filenameUsed = '';
|
|
|
|
if (file) {
|
|
|
|
filenameUsed = file.get_path();
|
|
|
|
} else {
|
|
|
|
let bytes = stream.steal_as_bytes();
|
|
|
|
let clipboard = St.Clipboard.get_default();
|
|
|
|
clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes);
|
|
|
|
}
|
|
|
|
|
2012-12-10 10:26:31 -05:00
|
|
|
let retval = GLib.Variant.new('(bs)', [result, filenameUsed]);
|
|
|
|
invocation.return_value(retval);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_scaleArea(x, y, width, height) {
|
2014-06-16 14:28:17 -04:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
x *= scaleFactor;
|
|
|
|
y *= scaleFactor;
|
|
|
|
width *= scaleFactor;
|
|
|
|
height *= scaleFactor;
|
|
|
|
return [x, y, width, height];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-16 14:28:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_unscaleArea(x, y, width, height) {
|
2014-06-16 14:28:17 -04:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
x /= scaleFactor;
|
|
|
|
y /= scaleFactor;
|
|
|
|
width /= scaleFactor;
|
|
|
|
height /= scaleFactor;
|
|
|
|
return [x, y, width, height];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-16 14:28:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
ScreenshotAreaAsync(params, invocation) {
|
2019-02-04 05:58:00 -05:00
|
|
|
let [x, y, width, height, flash, filename] = params;
|
2014-06-16 14:28:17 -04:00
|
|
|
[x, y, width, height] = this._scaleArea(x, y, width, height);
|
2014-06-04 10:26:06 -04:00
|
|
|
if (!this._checkArea(x, y, width, height)) {
|
|
|
|
invocation.return_error_literal(Gio.IOErrorEnum,
|
|
|
|
Gio.IOErrorEnum.CANCELLED,
|
|
|
|
"Invalid params");
|
2013-03-02 08:59:05 -05:00
|
|
|
return;
|
|
|
|
}
|
2014-09-27 07:35:22 -04:00
|
|
|
let screenshot = this._createScreenshot(invocation);
|
|
|
|
if (!screenshot)
|
|
|
|
return;
|
2019-11-05 18:46:41 -05:00
|
|
|
|
|
|
|
let [stream, file] = this._createStream(filename);
|
|
|
|
|
2019-08-19 13:55:49 -04:00
|
|
|
screenshot.screenshot_area(x, y, width, height, stream,
|
2018-07-19 09:54:33 -04:00
|
|
|
(o, res) => {
|
|
|
|
try {
|
2019-11-05 18:46:41 -05:00
|
|
|
let [result, area] =
|
2018-07-19 09:54:33 -04:00
|
|
|
screenshot.screenshot_area_finish(res);
|
2019-09-12 18:41:47 -04:00
|
|
|
this._onScreenshotComplete(
|
2019-11-05 18:46:41 -05:00
|
|
|
result, area, stream, file, flash, invocation);
|
2018-07-19 09:54:33 -04:00
|
|
|
} catch (e) {
|
2019-08-19 13:55:49 -04:00
|
|
|
invocation.return_gerror(e);
|
2018-07-19 09:54:33 -04:00
|
|
|
}
|
2017-12-01 19:27:35 -05:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
ScreenshotWindowAsync(params, invocation) {
|
2019-01-31 08:43:52 -05:00
|
|
|
let [includeFrame, includeCursor, flash, filename] = params;
|
2014-09-27 07:35:22 -04:00
|
|
|
let screenshot = this._createScreenshot(invocation);
|
|
|
|
if (!screenshot)
|
|
|
|
return;
|
2019-11-05 18:46:41 -05:00
|
|
|
|
|
|
|
let [stream, file] = this._createStream(filename);
|
|
|
|
|
2019-08-19 13:55:49 -04:00
|
|
|
screenshot.screenshot_window(includeFrame, includeCursor, stream,
|
2018-07-19 09:54:33 -04:00
|
|
|
(o, res) => {
|
|
|
|
try {
|
2019-11-05 18:46:41 -05:00
|
|
|
let [result, area] =
|
2018-07-19 09:54:33 -04:00
|
|
|
screenshot.screenshot_window_finish(res);
|
2019-09-12 18:41:47 -04:00
|
|
|
this._onScreenshotComplete(
|
2019-11-05 18:46:41 -05:00
|
|
|
result, area, stream, file, flash, invocation);
|
2018-07-19 09:54:33 -04:00
|
|
|
} catch (e) {
|
2019-08-19 13:55:49 -04:00
|
|
|
invocation.return_gerror(e);
|
2018-07-19 09:54:33 -04:00
|
|
|
}
|
2017-12-01 19:27:35 -05:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
ScreenshotAsync(params, invocation) {
|
2019-01-31 08:43:52 -05:00
|
|
|
let [includeCursor, flash, filename] = params;
|
2014-09-27 07:35:22 -04:00
|
|
|
let screenshot = this._createScreenshot(invocation);
|
|
|
|
if (!screenshot)
|
|
|
|
return;
|
2019-11-05 18:46:41 -05:00
|
|
|
|
|
|
|
let [stream, file] = this._createStream(filename);
|
|
|
|
|
|
|
|
screenshot.screenshot(includeCursor, stream,
|
2018-07-19 09:54:33 -04:00
|
|
|
(o, res) => {
|
|
|
|
try {
|
2019-11-05 18:46:41 -05:00
|
|
|
let [result, area] =
|
2018-07-19 09:54:33 -04:00
|
|
|
screenshot.screenshot_finish(res);
|
2019-09-12 18:41:47 -04:00
|
|
|
this._onScreenshotComplete(
|
2019-11-05 18:46:41 -05:00
|
|
|
result, area, stream, file, flash, invocation);
|
2018-07-19 09:54:33 -04:00
|
|
|
} catch (e) {
|
2019-08-19 13:55:49 -04:00
|
|
|
invocation.return_gerror(e);
|
2018-07-19 09:54:33 -04:00
|
|
|
}
|
2017-12-01 19:27:35 -05:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-12-18 21:39:39 -05:00
|
|
|
async SelectAreaAsync(params, invocation) {
|
2012-12-10 10:26:31 -05:00
|
|
|
let selectArea = new SelectArea();
|
2019-12-18 21:39:39 -05:00
|
|
|
try {
|
|
|
|
let areaRectangle = await selectArea.selectAsync();
|
|
|
|
let retRectangle = this._unscaleArea(
|
|
|
|
areaRectangle.x, areaRectangle.y,
|
|
|
|
areaRectangle.width, areaRectangle.height);
|
|
|
|
invocation.return_value(GLib.Variant.new('(iiii)', retRectangle));
|
|
|
|
} catch (e) {
|
|
|
|
invocation.return_error_literal(
|
|
|
|
Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
|
|
|
|
'Operation was cancelled');
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
FlashAreaAsync(params, invocation) {
|
2014-06-04 10:26:06 -04:00
|
|
|
let [x, y, width, height] = params;
|
2014-06-16 14:28:17 -04:00
|
|
|
[x, y, width, height] = this._scaleArea(x, y, width, height);
|
2014-06-04 10:26:06 -04:00
|
|
|
if (!this._checkArea(x, y, width, height)) {
|
|
|
|
invocation.return_error_literal(Gio.IOErrorEnum,
|
|
|
|
Gio.IOErrorEnum.CANCELLED,
|
|
|
|
"Invalid params");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-19 15:06:04 -04:00
|
|
|
let flashspot = new Flashspot({ x, y, width, height });
|
2012-12-10 10:26:31 -05:00
|
|
|
flashspot.fire();
|
2014-06-04 10:26:06 -04:00
|
|
|
invocation.return_value(null);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-17 19:34:59 -04:00
|
|
|
|
2019-12-18 21:53:51 -05:00
|
|
|
async PickColorAsync(params, invocation) {
|
2018-07-17 19:34:59 -04:00
|
|
|
let pickPixel = new PickPixel();
|
2019-12-18 21:53:51 -05:00
|
|
|
try {
|
|
|
|
const coords = await pickPixel.pickAsync();
|
|
|
|
|
|
|
|
let screenshot = this._createScreenshot(invocation, false);
|
|
|
|
if (!screenshot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
screenshot.pick_color(coords.x, coords.y, (_o, res) => {
|
|
|
|
let [success_, color] = screenshot.pick_color_finish(res);
|
|
|
|
let { red, green, blue } = color;
|
|
|
|
let retval = GLib.Variant.new('(a{sv})', [{
|
|
|
|
color: GLib.Variant.new('(ddd)', [
|
|
|
|
red / 255.0,
|
|
|
|
green / 255.0,
|
|
|
|
blue / 255.0,
|
|
|
|
]),
|
|
|
|
}]);
|
|
|
|
this._removeShooterForSender(invocation.get_sender());
|
|
|
|
invocation.return_value(retval);
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
invocation.return_error_literal(
|
|
|
|
Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
|
|
|
|
'Operation was cancelled');
|
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-12-18 21:39:39 -05:00
|
|
|
var SelectArea = GObject.registerClass(
|
|
|
|
class SelectArea extends St.Widget {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
2012-12-10 10:26:31 -05:00
|
|
|
this._startX = -1;
|
|
|
|
this._startY = -1;
|
|
|
|
this._lastX = 0;
|
|
|
|
this._lastY = 0;
|
2014-04-25 12:43:10 -04:00
|
|
|
this._result = null;
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
super._init({
|
|
|
|
visible: false,
|
|
|
|
reactive: true,
|
|
|
|
x: 0,
|
2019-08-20 17:43:54 -04:00
|
|
|
y: 0,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
|
|
|
Main.uiGroup.add_actor(this);
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this._grabHelper = new GrabHelper.GrabHelper(this);
|
2014-04-25 12:43:10 -04:00
|
|
|
|
2012-12-10 10:26:31 -05:00
|
|
|
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
|
|
|
coordinate: Clutter.BindCoordinate.ALL });
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_constraint(constraint);
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-04-04 10:03:54 -04:00
|
|
|
this._rubberband = new St.Widget({
|
|
|
|
style_class: 'select-area-rubberband',
|
2019-08-20 17:43:54 -04:00
|
|
|
visible: false,
|
2019-04-04 10:03:54 -04:00
|
|
|
});
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_actor(this._rubberband);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-12-18 21:39:39 -05:00
|
|
|
async selectAsync() {
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
|
2019-07-16 05:24:13 -04:00
|
|
|
Main.uiGroup.set_child_above_sibling(this, null);
|
2019-12-18 21:39:39 -05:00
|
|
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getGeometry() {
|
2019-07-12 20:17:20 -04:00
|
|
|
return new Meta.Rectangle({
|
|
|
|
x: Math.min(this._startX, this._lastX),
|
|
|
|
y: Math.min(this._startY, this._lastY),
|
|
|
|
width: Math.abs(this._startX - this._lastX) + 1,
|
2019-08-20 17:43:54 -04:00
|
|
|
height: Math.abs(this._startY - this._lastY) + 1,
|
2019-07-12 20:17:20 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_motion_event(motionEvent) {
|
2019-09-10 02:49:50 -04:00
|
|
|
if (this._startX == -1 || this._startY == -1 || this._result)
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
[this._lastX, this._lastY] = [motionEvent.x, motionEvent.y];
|
2015-03-14 18:45:11 -04:00
|
|
|
this._lastX = Math.floor(this._lastX);
|
|
|
|
this._lastY = Math.floor(this._lastY);
|
2012-12-10 10:26:31 -05:00
|
|
|
let geometry = this._getGeometry();
|
|
|
|
|
|
|
|
this._rubberband.set_position(geometry.x, geometry.y);
|
|
|
|
this._rubberband.set_size(geometry.width, geometry.height);
|
2019-04-04 10:03:54 -04:00
|
|
|
this._rubberband.show();
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_button_press_event(buttonEvent) {
|
|
|
|
[this._startX, this._startY] = [buttonEvent.x, buttonEvent.y];
|
2015-03-14 18:45:11 -04:00
|
|
|
this._startX = Math.floor(this._startX);
|
|
|
|
this._startY = Math.floor(this._startY);
|
2012-12-10 10:26:31 -05:00
|
|
|
this._rubberband.set_position(this._startX, this._startY);
|
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-09-10 01:42:48 -04:00
|
|
|
vfunc_button_release_event() {
|
2014-04-25 12:43:10 -04:00
|
|
|
this._result = this._getGeometry();
|
2019-07-16 05:24:13 -04:00
|
|
|
this.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
opacity: 0,
|
|
|
|
duration: 200,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 17:43:54 -04:00
|
|
|
onComplete: () => this._grabHelper.ungrab(),
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2014-04-25 12:43:10 -04:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
|
|
|
|
2019-12-18 21:53:51 -05:00
|
|
|
var PickPixel = GObject.registerClass(
|
|
|
|
class PickPixel extends St.Widget {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
|
|
|
super._init({ visible: false, reactive: true });
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2018-07-17 19:34:59 -04:00
|
|
|
this._result = null;
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
Main.uiGroup.add_actor(this);
|
2018-07-17 19:34:59 -04:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
this._grabHelper = new GrabHelper.GrabHelper(this);
|
2018-07-17 19:34:59 -04:00
|
|
|
|
|
|
|
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
|
|
|
coordinate: Clutter.BindCoordinate.ALL });
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_constraint(constraint);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-17 19:34:59 -04:00
|
|
|
|
2019-12-18 21:53:51 -05:00
|
|
|
async pickAsync() {
|
2018-07-17 19:34:59 -04:00
|
|
|
global.display.set_cursor(Meta.Cursor.CROSSHAIR);
|
2019-07-16 05:24:13 -04:00
|
|
|
Main.uiGroup.set_child_above_sibling(this, null);
|
2019-12-18 21:53:51 -05:00
|
|
|
this.show();
|
2018-07-17 19:34:59 -04:00
|
|
|
|
2019-12-18 21:53:51 -05:00
|
|
|
await this._grabHelper.grabAsync({ actor: this });
|
2018-07-17 19:34:59 -04:00
|
|
|
|
|
|
|
global.display.set_cursor(Meta.Cursor.DEFAULT);
|
|
|
|
|
|
|
|
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2019-07-16 05:24:13 -04:00
|
|
|
this.destroy();
|
2018-07-17 19:34:59 -04:00
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2019-12-18 21:53:51 -05:00
|
|
|
|
|
|
|
return this._result;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_button_release_event(buttonEvent) {
|
|
|
|
let { x, y } = buttonEvent;
|
|
|
|
this._result = new Graphene.Point({ x, y });
|
|
|
|
this._grabHelper.ungrab();
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2018-07-17 19:34:59 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
2018-07-17 19:34:59 -04:00
|
|
|
|
2019-08-01 19:13:10 -04:00
|
|
|
var FLASHSPOT_ANIMATION_OUT_TIME = 500; // milliseconds
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var Flashspot = GObject.registerClass(
|
|
|
|
class Flashspot extends Lightbox.Lightbox {
|
|
|
|
_init(area) {
|
|
|
|
super._init(Main.uiGroup, {
|
|
|
|
inhibitEvents: true,
|
|
|
|
width: area.width,
|
2019-08-20 17:43:54 -04:00
|
|
|
height: area.height,
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|
|
|
|
this.style_class = 'flashspot';
|
|
|
|
this.set_position(area.x, area.y);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-12-10 10:26:31 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
fire(doneCallback) {
|
2019-07-16 05:24:13 -04:00
|
|
|
this.set({ visible: true, opacity: 255 });
|
|
|
|
this.ease({
|
2018-07-20 15:46:19 -04:00
|
|
|
opacity: 0,
|
|
|
|
duration: FLASHSPOT_ANIMATION_OUT_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => {
|
|
|
|
if (doneCallback)
|
|
|
|
doneCallback();
|
|
|
|
this.destroy();
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2012-12-10 10:26:31 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|