Skip to content

Commit

Permalink
feat: prepare for per-widget configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Sep 20, 2024
1 parent 95bba20 commit 6b9b554
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 17 deletions.
169 changes: 160 additions & 9 deletions package/contents/ui/code/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,165 @@ const defaultConfig = {
"opacity": 2,
"floating": false
},
"perWidgetConfiguration": {
"widgets": {
"org.kde...": {}
},
"trayWidgets": {
"org.kde...": {}
"perWidgetConfiguration": [
{
"widgets": [
"luisbocanegra.panel.colorizer"
],
"configuration": {
"blurBehind": false,
"backgroundColor": {
"enabled": true,
"lightnessValue": 0.25,
"saturationValue": 0.6,
"alpha": 1,
"type": 0,
"custom": "#00004b",
"list": [
"#ED8796",
"#A6DA95",
"#EED49F",
"#8AADF4",
"#F5BDE6",
"#8BD5CA",
"#f5a97f"
],
"followColor": 0,
"saturationEnabled": false,
"lightnessEnabled": true,
"animation": {
"enabled": false,
"interval": 3000,
"smoothing": 800
},
"sourceType": 0,
"systemColorSet": "View",
"systemColor": "backgroundColor",
"enabled": true
},
"foregroundColor": {
"enabled": true,
"lightnessValue": 0.85,
"saturationValue": 0.75,
"alpha": 1,
"systemColor": "highlightColor",
"systemColorSet": "Header",
"type": 0,
"custom": "#ff9a00",
"list": [
"#ED8796",
"#A6DA95",
"#EED49F",
"#8AADF4",
"#F5BDE6",
"#8BD5CA",
"#f5a97f"
],
"followColor": 0,
"saturationEnabled": false,
"lightnessEnabled": false,
"animation": {
"enabled": false,
"interval": 3000,
"smoothing": 800
},
"sourceType": 0,
"enabled": true
},
"radius": {
"topLeft": 10,
"topRight": 5,
"bottomRight": 5,
"bottomLeft": 5
},
"margin": {
"right": 4,
"left": 4,
"top": 4,
"bottom": 4
},
"spacing": 3,
"border": {
"enabled": false,
"customSides": false,
"custom": {
"widths": {
"left": 0,
"bottom": 3,
"right": 0,
"top": 0
},
"margin": [],
"radius": 0
},
"width": 0,
"color": {
"lightnessValue": 0.35,
"saturationValue": 0.05,
"alpha": 1,
"systemColorSet": "View",
"type": 0,
"custom": "#eeff71",
"list": [
"#ED8796",
"#A6DA95",
"#EED49F",
"#8AADF4",
"#F5BDE6",
"#8BD5CA",
"#f5a97f"
],
"followColor": 1,
"saturationEnabled": false,
"lightnessEnabled": true,
"animation": {
"enabled": false,
"interval": 3000,
"smoothing": 800
},
"sourceType": 4,
"systemColor": "backgroundColor",
"enabled": true
}
},
"shadow": {
"enabled": false,
"color": {
"lightnessValue": 0.05,
"saturationValue": 0.05,
"alpha": 1,
"systemColorSet": "View",
"type": 0,
"custom": "#282828",
"list": [
"#ED8796",
"#A6DA95",
"#EED49F",
"#8AADF4",
"#F5BDE6",
"#8BD5CA",
"#f5a97f"
],
"followColor": 0,
"saturationEnabled": false,
"lightnessEnabled": true,
"animation": {
"enabled": false,
"interval": 3000,
"smoothing": 800
},
"sourceType": 1,
"systemColor": "backgroundColor",
"enabled": true
},
"size": 5,
"xOffset": 0,
"yOffset": 0
},
"enabled": true,
"radiusEnabled": true,
"marginEnabled": true,
}
}
}
]
}


26 changes: 20 additions & 6 deletions package/contents/ui/code/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,31 @@ var themeScopes = [
"Header"
]

function getCustomCfg(config, widgetName) {
if (!widgetName) return null
console.error("getCustomCfg()", config, widgetName)
let custom = config.perWidgetConfiguration
if (custom) {
const cfg = custom.find((cfg) => cfg.widgets.includes(widgetName))
if (cfg) {
console.error("customm ->", JSON.stringify(cfg.configuration))
return cfg.configuration
}
}
return null
}

function getItemCfg(itemType, widgetName) {
// TODO config per widget
function getItemCfg(itemType, widgetName, config) {
let custom = getCustomCfg(config, widgetName)
// TODO merge only the enabled ones with the global configuration
if (custom) return custom
if (itemType === Enums.ItemType.PanelBgItem) {
return panelSettings
} else if (itemType === Enums.ItemType.TrayItem || itemType === Enums.ItemType.TrayArrow) {
}
if (itemType === Enums.ItemType.TrayItem || itemType === Enums.ItemType.TrayArrow) {
return trayWidgetSettings
} else {
return widgetSettings
}
return widgetSettings
}

function scaleSaturation(color, saturation) {
Expand All @@ -236,7 +251,6 @@ function rgbToQtColor(rgb) {
}

function mergeConfigs(defaultConfig, existingConfig) {
console.error("mergeConfigs -> MERGE")
for (var key in defaultConfig) {
if (defaultConfig.hasOwnProperty(key)) {
if (typeof defaultConfig[key] === "object" && defaultConfig[key] !== null) {
Expand Down
5 changes: 3 additions & 2 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ PlasmoidItem {
property var trayWidgetSettings: cfg.trayWidgets
property var forceRecolorList: cfg.forceForegroundColor
property int forceRecolorCount: Object.keys(forceRecolorList).length
property var perWidgetConfiguration: cfg.perWidgetConfiguration
signal recolorNeeded()

onForceRecolorCountChanged: {
Expand Down Expand Up @@ -198,7 +199,7 @@ PlasmoidItem {
property bool requiresRefresh: false
property string widgetName: Utils.getWidgetName(target)
property var cfg: {
return Utils.getItemCfg(itemType, null) //TODO widget name here
return Utils.getItemCfg(itemType, widgetName, main.cfg)
}
property var bgColorCfg: cfg.backgroundColor
property var fgColorCfg: cfg.foregroundColor
Expand Down Expand Up @@ -534,7 +535,7 @@ PlasmoidItem {
}
}

layer.enabled: true
layer.enabled: cfg.border.customSides
layer.effect: MultiEffect {
maskEnabled: true
maskSpreadAtMax: 1
Expand Down

0 comments on commit 6b9b554

Please sign in to comment.