From 737bc856c4d1a486d77d38b8fdb1ceb2da8896e8 Mon Sep 17 00:00:00 2001 From: abakkk Date: Sun, 20 Sep 2020 04:54:01 +0200 Subject: [PATCH] color-picker extension support The color picker use the ["Color Picker" extensions](https://github.com/tuberry/color-picker) if it is available thanks to `pickAsync` "api". In comparaison to the GS color picker, it provides a colored cursor and a menu to adjust the color. --- area.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/area.js b/area.js index 8945954..5e1fecc 100644 --- a/area.js +++ b/area.js @@ -50,6 +50,7 @@ const SVG_DEBUG_EXTENDS = false; const TEXT_CURSOR_TIME = 600; // ms const ELEMENT_GRABBER_TIME = 80; // ms, default is about 16 ms const GRID_TILES_HORIZONTAL_NUMBER = 30; +const COLOR_PICKER_EXTENSION_UUID = 'color-picker@tuberry'; const { Shapes, Transformations } = Elements; const { DisplayStrings } = Menu; @@ -75,10 +76,6 @@ const getColorFromString = function(string, fallback) { return color; }; -const getColorFromRGB = function(red, green, blue) { - return getColorFromString(`rgb(${red},${green},${blue})`, 'White'); -}; - // DrawingArea is the widget in which we draw, thanks to Cairo. // It creates and manages a DrawingElement for each "brushstroke". // It handles pointer/mouse/(touch?) events and some keyboard events. @@ -1038,8 +1035,10 @@ var DrawingArea = new Lang.Class({ }, _onColorPicked: function(color) { - let { red, green, blue } = color; - this.currentColor = getColorFromRGB(red, green, blue); + if (color instanceof Clutter.Color) + color = color.to_string().slice(0, -2); + + this.currentColor = getColorFromString(color); if (this.currentElement) { this.currentElement.color = this.currentColor; this._redisplay(); @@ -1056,6 +1055,20 @@ var DrawingArea = new Lang.Class({ // Translators: It is displayed in an OSD notification to ask the user to start picking, so it should use the imperative mood. this.emit('show-osd', Files.Icons.COLOR_PICKER, pgettext("osd-notification", "Pick a color"), "", -1, false); + let extension = Main.extensionManager && Main.extensionManager.lookup(COLOR_PICKER_EXTENSION_UUID); + if (extension && extension.state == ExtensionUtils.ExtensionState.ENABLED && extension.stateObj && extension.stateObj.pickAsync) { + extension.stateObj.pickAsync().then(result => { + if (typeof result == 'string') + this._onColorPicked(result); + else + this.initPointerCursor(); + }).catch(e => { + this.initPointerCursor(); + }); + + return; + } + try { let screenshot = new Shell.Screenshot(); let pickPixel = new Screenshot.PickPixel(screenshot);