Skip to content

Commit fc94f22

Browse files
committed
feat!: support per widget instance customization
Widget id is now used to customize multiple instances of the same widget separately. StatusNotifier (tray app icon) doesn't have numeric id so uses -1 placeholder The affected settings are: - Force text/icons color cfg_forceForegroundColor.widgets - Unified background cfg_globalSettings.unifiedBackground - Preset overrides cfg_globalSettings.configurationOverrides.associations - Global overrides cfg_configurationOverrides.associations These settings are now stored as an array instead of key-value Previously stored key-value for these options is silently ignored and should be converted manually to fit the new format closes: #124 BREAKING CHANGE: Force text/icons, Unified background, Preset/global overrides now use id to address multiple instances of the same widget separately and should be reconfigured. Also widget ids are unique per panel so the setting needs to be recreated and mantained per panel
1 parent 7a527ff commit fc94f22

11 files changed

+247
-150
lines changed

package/contents/config/main.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
<entry
4545
name="configurationOverrides"
4646
type="String">
47-
<default>{"overrides": {}, "associations":{}}</default>
47+
<default>{"overrides": {}, "associations":[]}</default>
4848
</entry>
4949
<entry
5050
name="forceForegroundColor"
5151
type="String">
52-
<default>{"widgets":{}, "reloadInterval": 250}</default>
52+
<default>{"widgets":[], "reloadInterval": 250}</default>
5353
</entry>
5454
</group>
5555
</kcfg>

package/contents/ui/code/globals.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ const basePadding = {
154154
},
155155
}
156156

157-
const baseUnfiedBackground = {
158-
"org.kde.plasma.digitalclock": 0
159-
}
157+
const baseUnfiedBackground = []
160158

161159
const basePanelConfig = {
162160
"enabled": false,
@@ -248,31 +246,12 @@ const defaultConfig = {
248246
"enabled": true,
249247
"opacity": 1.0
250248
},
251-
"forceForegroundColor": {
252-
"widgets": {
253-
"com.github.antroids.application-title-bar": {
254-
"method": {
255-
"mask": false,
256-
"multiEffect": false
257-
},
258-
"reload": true
259-
},
260-
"org.kde.plasma.appmenu": {
261-
"method": {
262-
"mask": false,
263-
"multiEffect": false
264-
},
265-
"reload": true
266-
}
267-
},
268-
"reloadInterval": 250
269-
},
270249
"stockPanelSettings": baseStockPanelSettings,
271250
"configurationOverrides": {
272251
"overrides": {},
273-
"associations": {}
252+
"associations": []
274253
},
275-
"unifiedBackground": {}
254+
"unifiedBackground": []
276255
}
277256

278257
const ignoredConfigs = [

package/contents/ui/code/utils.js

+48-17
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ function findWidgets(panelLayout, panelWidgets) {
9595
// other situations
9696
if (!child.applet?.plasmoid?.pluginName) continue
9797
// Utils.dumpProps(child.applet.plasmoid)
98+
const id = child.applet.plasmoid.id
9899
const name = child.applet.plasmoid.pluginName
99100
const title = child.applet.plasmoid.title
100101
const icon = child.applet.plasmoid.icon
101-
if (panelWidgets.find((item) => item.name === name)) continue
102+
if (panelWidgets.find((item) => item.id === id)) continue
102103
// console.error(name, title, icon)
103-
panelWidgets.push({ "name": name, "title": title, "icon": icon, "inTray": false })
104+
panelWidgets.push({ "id": id, "name": name, "title": title, "icon": icon, "inTray": false })
104105
}
105106
return panelWidgets
106107
}
@@ -114,25 +115,28 @@ function findWidgetsTray(grid, panelWidgets) {
114115
const model = item.children[j].model
115116
// App tray icons
116117
if (model.itemType === "StatusNotifier") {
117-
// dumpProps(model)
118+
// in contrast with applet?.plasmoid.id, Id is not actually given by plasma,
119+
// but since there should be only a single instance of StatusNotifier per app,
120+
// model.Id _should_ be enough for any sane implementation of tray icon
118121
const name = model.Id
119122
const title = model.ToolTipTitle !== "" ? model.ToolTipTitle : model.Title
120123
const icon = model.IconName
121124
if (panelWidgets.find((item) => item.name === name)) continue
122125
// console.error(name, title, icon)
123-
panelWidgets.push({ "name": name, "title": title, "icon": icon, "inTray": true })
126+
panelWidgets.push({ "id": -1, "name": name, "title": title, "icon": icon, "inTray": true })
124127
}
128+
// normal plasmoids in tray
125129
if (model.itemType === "Plasmoid") {
126130
const applet = model.applet ?? null
131+
const id = applet?.plasmoid.id ?? -1
127132
const name = applet?.plasmoid.pluginName ?? ""
128133
const title = applet?.plasmoid.title ?? ""
129134
const icon = applet?.plasmoid.icon ?? ""
130-
if (panelWidgets.find((item) => item.name === name)) continue
135+
if (panelWidgets.find((item) => item.id === id)) continue
131136
// console.error(name, title, icon)
132-
panelWidgets.push({ "name": name, "title": title, "icon": icon, "inTray": true })
137+
panelWidgets.push({ "id": id, "name": name, "title": title, "icon": icon, "inTray": true })
133138
}
134139
}
135-
// panelWidgets.add(item)
136140
}
137141
}
138142
// find the expand tray arrow
@@ -143,17 +147,19 @@ function findWidgetsTray(grid, panelWidgets) {
143147
const name = "org.kde.plasma.systemtray.expand"
144148
if (panelWidgets.find((item) => item.name === name)) continue
145149
const title = item.subText || "Show hidden icons"
146-
panelWidgets.push({ "name": name, "title": title, "icon": "arrow-down", "inTray": true })
150+
panelWidgets.push({ "id": -1, "name": name, "title": title, "icon": "arrow-down", "inTray": true })
147151
}
148152
}
149153
}
150154
return panelWidgets
151155
}
152156

153-
function getWidgetName(item) {
157+
function getWidgetNameAndId(item) {
154158
let name = null
159+
let id = -1
155160
if (item.applet?.plasmoid?.pluginName) {
156161
name = item.applet.plasmoid.pluginName
162+
id = item.applet.plasmoid.id
157163
} else {
158164
for (let i in item.children) {
159165
if (!(item.children[i].model)) continue
@@ -163,13 +169,14 @@ function getWidgetName(item) {
163169
} else if (model.itemType === "Plasmoid") {
164170
const applet = model.applet ?? null
165171
name = applet?.plasmoid.pluginName ?? null
172+
name = applet?.plasmoid.id ?? -1
166173
}
167174
}
168175
}
169176
// if (name) {
170177
// console.error("@@@@ getWidgetName ->", name)
171178
// }
172-
return name
179+
return { name, id }
173180
}
174181

175182
var themeColors = [
@@ -205,11 +212,19 @@ var themeScopes = [
205212
"Header"
206213
]
207214

208-
function getCustomCfg(widgetName, configurationOverrides) {
209-
if (!widgetName) return null
215+
function getWidgetAsocIdx(id, name, config) {
216+
console.log("getWidgetAsocIdx()")
217+
return config.findIndex((item) => item.id == id && item.name == name)
218+
}
219+
220+
function getCustomCfg(widgetName, widgetId, configurationOverrides) {
221+
if (!widgetId) return null
210222
var custom = {}
211-
if (widgetName in configurationOverrides.associations) {
212-
const overrideNames = configurationOverrides.associations[widgetName]
223+
configurationOverrides.associations = clearOldWidgetConfig(configurationOverrides.associations)
224+
let asocIndex = getWidgetAsocIdx(widgetId, widgetName, configurationOverrides.associations)
225+
if (asocIndex !== -1) {
226+
227+
const overrideNames = configurationOverrides.associations[asocIndex].presets
213228

214229
for (let overrideName of overrideNames) {
215230
if (!(overrideName in configurationOverrides.overrides)) continue
@@ -251,10 +266,10 @@ function getEffectiveSettings(customSettings, globalSettings) {
251266
return effectiveSettings
252267
}
253268

254-
function getItemCfg(itemType, widgetName, config, configurationOverrides) {
269+
function getItemCfg(itemType, widgetName, widgetId, config, configurationOverrides) {
255270
let output = { override: false }
256-
let custom = getCustomCfg(widgetName, configurationOverrides)
257-
let presetOverrides = getCustomCfg(widgetName, config.configurationOverrides)
271+
let custom = getCustomCfg(widgetName, widgetId, configurationOverrides)
272+
let presetOverrides = getCustomCfg(widgetName, widgetId, config.configurationOverrides)
258273
if (presetOverrides) {
259274
if (custom && custom.disabledFallback) {
260275
custom = getEffectiveSettings(custom, presetOverrides)
@@ -460,3 +475,19 @@ for (var id of panelIds) {
460475
function evaluateScript(script) {
461476
runCommand.run("gdbus call --session --dest org.kde.plasmashell --object-path /PlasmaShell --method org.kde.PlasmaShell.evaluateScript '" + script + "'")
462477
}
478+
479+
function getForceFgWidgetConfig(id, name, config) {
480+
return config.find((item) => item.id == id && item.name == name)
481+
}
482+
483+
function clearOldWidgetConfig(config) {
484+
if (Array.isArray(config)) {
485+
return config
486+
}
487+
else return []
488+
}
489+
490+
function getWidgetConfigIdx(id, name, config) {
491+
// console.log("getWidgetConfigIdx()")
492+
return config.findIndex((item) => item.id == id && item.name == name)
493+
}

package/contents/ui/components/WidgetCardCheck.qml

+17-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ Kirigami.AbstractCard {
3838
}
3939
}
4040
}
41-
TextEdit {
42-
text: widget.name
43-
opacity: 0.6
44-
readOnly: true
45-
color: Kirigami.Theme.textColor
46-
selectedTextColor: Kirigami.Theme.highlightedTextColor
47-
selectionColor: Kirigami.Theme.highlightColor
41+
RowLayout {
42+
TextEdit {
43+
text: widget.name
44+
opacity: 0.6
45+
readOnly: true
46+
color: Kirigami.Theme.textColor
47+
selectedTextColor: Kirigami.Theme.highlightedTextColor
48+
selectionColor: Kirigami.Theme.highlightColor
49+
}
50+
TextEdit {
51+
text: widget.id
52+
opacity: 0.6
53+
readOnly: true
54+
color: Kirigami.Theme.textColor
55+
selectedTextColor: Kirigami.Theme.highlightedTextColor
56+
selectionColor: Kirigami.Theme.highlightColor
57+
}
4858
}
4959
}
5060
Item {

package/contents/ui/components/WidgetCardConfig.qml

+25-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import org.kde.kirigami as Kirigami
66
Kirigami.AbstractCard {
77
id: root
88
property var widget
9-
signal addOverride(widget: string, override: string, index: var)
10-
signal removeOverride(widget: string, index: int)
11-
signal clearOverrides(widget: string)
9+
signal addOverride(override: string, index: var)
10+
signal removeOverride(index: int)
11+
signal clearOverrides()
1212
property var configOverrides: []
13-
property var overrideAssociations: {}
13+
property var overrideAssociations: []
1414
property bool showList: false
15-
property var currentOverrides: overrideAssociations[widget.name] || []
15+
property var currentOverrides
1616
property var editingIndex: 0
1717

1818
contentItem: ColumnLayout {
@@ -45,13 +45,23 @@ Kirigami.AbstractCard {
4545
}
4646
}
4747
}
48-
TextEdit {
49-
text: widget.name
50-
opacity: 0.6
51-
readOnly: true
52-
color: Kirigami.Theme.textColor
53-
selectedTextColor: Kirigami.Theme.highlightedTextColor
54-
selectionColor: Kirigami.Theme.highlightColor
48+
RowLayout {
49+
TextEdit {
50+
text: widget.name
51+
opacity: 0.6
52+
readOnly: true
53+
color: Kirigami.Theme.textColor
54+
selectedTextColor: Kirigami.Theme.highlightedTextColor
55+
selectionColor: Kirigami.Theme.highlightColor
56+
}
57+
TextEdit {
58+
text: widget.id
59+
opacity: 0.6
60+
readOnly: true
61+
color: Kirigami.Theme.textColor
62+
selectedTextColor: Kirigami.Theme.highlightedTextColor
63+
selectionColor: Kirigami.Theme.highlightColor
64+
}
5565
}
5666
}
5767
Item {
@@ -76,7 +86,7 @@ Kirigami.AbstractCard {
7686
Button {
7787
icon.name: "edit-clear-symbolic"
7888
onClicked: {
79-
removeOverride(widget.name, index)
89+
removeOverride(index)
8090
}
8191
}
8292
}
@@ -86,7 +96,7 @@ Kirigami.AbstractCard {
8696
Button {
8797
icon.name: "edit-clear-all-symbolic"
8898
onClicked: {
89-
clearOverrides(widget.name)
99+
clearOverrides()
90100
}
91101
text: "Clear"
92102
visible: currentOverrides.length !== 0
@@ -124,7 +134,7 @@ Kirigami.AbstractCard {
124134
text: modelData
125135
onClicked: {
126136
showList = false
127-
addOverride(widget.name, text, root.editingIndex)
137+
addOverride(text, root.editingIndex)
128138
}
129139
Rectangle {
130140
color: index & 1 ? "transparent" : Kirigami.Theme.alternateBackgroundColor

package/contents/ui/components/WidgetCardUnifiedBg.qml

+17-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,23 @@ Kirigami.AbstractCard {
3737
}
3838
}
3939
}
40-
TextEdit {
41-
text: widget.name
42-
opacity: 0.6
43-
readOnly: true
44-
color: Kirigami.Theme.textColor
45-
selectedTextColor: Kirigami.Theme.highlightedTextColor
46-
selectionColor: Kirigami.Theme.highlightColor
40+
RowLayout {
41+
TextEdit {
42+
text: widget.name
43+
opacity: 0.6
44+
readOnly: true
45+
color: Kirigami.Theme.textColor
46+
selectedTextColor: Kirigami.Theme.highlightedTextColor
47+
selectionColor: Kirigami.Theme.highlightColor
48+
}
49+
TextEdit {
50+
text: widget.id
51+
opacity: 0.6
52+
readOnly: true
53+
color: Kirigami.Theme.textColor
54+
selectedTextColor: Kirigami.Theme.highlightedTextColor
55+
selectionColor: Kirigami.Theme.highlightColor
56+
}
4757
}
4858
}
4959
Item {

0 commit comments

Comments
 (0)