From 19d74595d6b27b7b8922c7502c8ed05b474c2d7f Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 10 Sep 2024 00:01:17 -0700 Subject: [PATCH] core/window: premultiply background colors Apparently these are supposed to be premultiplied. Some docs would be nice. --- src/core/proxywindow.cpp | 21 ++++++++++++++------- src/core/windowinterface.hpp | 14 -------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/core/proxywindow.cpp b/src/core/proxywindow.cpp index c4b72a04..5d4659dd 100644 --- a/src/core/proxywindow.cpp +++ b/src/core/proxywindow.cpp @@ -287,16 +287,23 @@ QuickshellScreenInfo* ProxyWindowBase::screen() const { return QuickshellTracked::instance()->screenInfo(qscreen); } -QColor ProxyWindowBase::color() const { - if (this->window == nullptr) return this->mColor; - else return this->window->color(); -} +QColor ProxyWindowBase::color() const { return this->mColor; } void ProxyWindowBase::setColor(QColor color) { + this->mColor = color; + if (this->window == nullptr) { - this->mColor = color; - emit this->colorChanged(); - } else this->window->setColor(color); + if (color != this->mColor) emit this->colorChanged(); + } else { + auto premultiplied = QColor::fromRgbF( + color.redF() * color.alphaF(), + color.greenF() * color.alphaF(), + color.blueF() * color.alphaF(), + color.alphaF() + ); + + this->window->setColor(premultiplied); + } } PendingRegion* ProxyWindowBase::mask() const { return this->mMask; } diff --git a/src/core/windowinterface.hpp b/src/core/windowinterface.hpp index 3970d9da..f90df24c 100644 --- a/src/core/windowinterface.hpp +++ b/src/core/windowinterface.hpp @@ -46,20 +46,6 @@ class WindowInterface: public Reloadable { /// along with map[To|From]Item (which is not reactive). Q_PROPERTY(QObject* windowTransform READ windowTransform NOTIFY windowTransformChanged); /// The background color of the window. Defaults to white. - /// - /// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems. - /// > Using a colored content item over a transparent window is the recommended way to work around this: - /// > ```qml - /// > ProxyWindow { - /// > color: "transparent" - /// > Rectangle { - /// > anchors.fill: parent - /// > color: "#20ffffff" - /// > - /// > // your content here - /// > } - /// > } - /// > ``` Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged); /// The clickthrough mask. Defaults to null. ///