From ef9113da43d375c8f9a027fc736f975d80de6a07 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Tue, 18 Jul 2023 15:51:25 +0200 Subject: [PATCH] ui/environment: Add a setSourceColor helper To simplify porting away from Clutter cairo helpers Part-of: --- js/ui/environment.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/ui/environment.js b/js/ui/environment.js index 868c97c07..ce0614813 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -4,6 +4,7 @@ import '../misc/dependencies.js'; import {setConsoleLogDomain} from 'console'; import * as Gettext from 'gettext'; +import Cairo from 'cairo'; import Clutter from 'gi://Clutter'; import Gdk from 'gi://Gdk'; import Gio from 'gi://Gio'; @@ -275,6 +276,16 @@ GObject.Object.prototype.disconnect_object = function (...args) { SignalTracker.registerDestroyableType(Clutter.Actor); +Cairo.Context.prototype.setSourceColor = function (color) { + const {red, green, blue, alpha} = color; + const rgb = [red, green, blue].map(v => v / 255.0); + + if (alpha !== 0xff) + this.setSourceRGBA(...rgb, alpha / 255.0); + else + this.setSourceRGB(...rgb); +}; + // Miscellaneous monkeypatching _patchContainerClass(St.BoxLayout);