Skip to content

Commit 9cca3c7

Browse files
committed
fix: keep original color binding if fg color was never changed
before trying to apply the foreground color, we need to know if we have changed it in the first place, otherwise we have no easy way to restore the original binding for widgets that do dynamic color requires restarting plasma but is better than nothing
1 parent 371eaf4 commit 9cca3c7

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

package/contents/ui/main.qml

+18-11
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ PlasmoidItem {
228228
return newColor
229229
}
230230

231-
function applyFgColor(element, newColor, fgColorCfg, depth, wRecolorCfg) {
231+
function applyFgColor(element, newColor, fgColorCfg, depth, wRecolorCfg, fgColorModified) {
232232
let count = 0;
233233
let maxDepth = depth
234234
const forceMask = wRecolorCfg?.method?.mask ?? false
@@ -238,7 +238,11 @@ PlasmoidItem {
238238
var child = element.visibleChildren[i]
239239
let targetTypes = [Text,ToolButton,Label,Canvas,Kirigami.Icon]
240240
if (targetTypes.some(function (type) {return child instanceof type})) {
241-
if (child.color) {
241+
// before trying to apply the foreground color, we need to know if we
242+
// have changed it in the first place, otherwise we have no easy way to
243+
// restore the original binding for widgets that do dynamic color
244+
// requires restarting plasma but is better than nothing
245+
if ((fgColorCfg.enabled || fgColorModified) && child.color) {
242246
child.color = newColor
243247
}
244248
if (child.Kirigami?.Theme) {
@@ -267,7 +271,7 @@ PlasmoidItem {
267271
// repaintDebugComponent.createObject(child)
268272
}
269273
if (child.visibleChildren?.length ?? 0 > 0) {
270-
const result = applyFgColor(child, newColor, fgColorCfg, depth + 1, wRecolorCfg)
274+
const result = applyFgColor(child, newColor, fgColorCfg, depth + 1, wRecolorCfg, fgColorModified)
271275
count += result.count
272276
if (result.depth > maxDepth) {
273277
maxDepth = result.depth
@@ -368,9 +372,9 @@ PlasmoidItem {
368372
property int maxDepth: 0
369373
visible: cfgEnabled
370374
property bool cfgEnabled: cfg.enabled && isEnabled
371-
property bool bgEnabled: cfgEnabled ? bgColorCfg.enabled : false
372-
property bool fgEnabled: fgColorCfg.enabled && cfgEnabled
373-
property bool radiusEnabled: cfg.radius.enabled && cfgEnabled
375+
property bool bgEnabled: cfgEnabled && bgColorCfg.enabled
376+
property bool fgEnabled: cfgEnabled && fgColorCfg.enabled
377+
property bool radiusEnabled: cfgEnabled && cfg.radius.enabled
374378
property int topLeftRadius: !radiusEnabled || unifyBgType === 2 || unifyBgType === 3
375379
? 0
376380
: cfg.radius.corner.topLeft ?? 0
@@ -407,7 +411,7 @@ PlasmoidItem {
407411
}
408412
property string fgColor: {
409413
if (!fgEnabled && !inTray) {
410-
return Kirigami.Theme.textColor
414+
return main.Kirigami.Theme.textColor
411415
} else if ((!fgEnabled && inTray && widgetEnabled)) {
412416
// inherit tray widget fg color to tray icons
413417
return trayWidgetBgItem.fgColor
@@ -428,7 +432,6 @@ PlasmoidItem {
428432
width: height
429433
visible: false
430434
radius: height / 2
431-
color: fgColor
432435
anchors.right: parent.right
433436
Kirigami.Theme.colorSet: Kirigami.Theme[fgColorCfg.systemColorSet]
434437
}
@@ -438,7 +441,6 @@ PlasmoidItem {
438441
width: height
439442
visible: false
440443
radius: height / 2
441-
color: fgColor
442444
anchors.right: parent.right
443445
Kirigami.Theme.colorSet: Kirigami.Theme[bgColorCfg.systemColorSet]
444446
}
@@ -483,14 +485,19 @@ PlasmoidItem {
483485
recolorTimer.restart()
484486
}
485487

488+
property bool fgColorModified: false
489+
490+
onFgEnabledChanged: {
491+
if (fgEnabled) fgColorModified = true
492+
}
493+
486494
Timer {
487495
id: recolorTimer
488496
interval: 10
489497
onTriggered: {
490498
if (isPanel) return
491-
if (!fgEnabled) return
492499
if (widgetName === "org.kde.plasma.systemtray" && separateTray) return
493-
const result = applyFgColor(target, fgColor, fgColorCfg, 0, wRecolorCfg)
500+
const result = applyFgColor(target, fgColor, fgColorCfg, 0, wRecolorCfg, fgColorModified)
494501
if (result) {
495502
itemCount = result.count
496503
maxDepth = result.depth

0 commit comments

Comments
 (0)