Skip to content

Commit

Permalink
feat: allow configuring stock panel settings
Browse files Browse the repository at this point in the history
Makes use of the Plasma scripting API

closes: #103
  • Loading branch information
luisbocanegra committed Nov 3, 2024
1 parent c6dfe49 commit 6de0278
Show file tree
Hide file tree
Showing 5 changed files with 461 additions and 9 deletions.
6 changes: 6 additions & 0 deletions package/contents/config/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ ConfigModel {
source: "configGlobal.qml"
}

ConfigCategory {
name: i18n("Stock Panel Settings")
icon: "configure-symbolic"
source: "configStockPanelSettings.qml"
}

ConfigCategory {
name: i18n("Unified background")
icon: "lines-connector-symbolic"
Expand Down
40 changes: 32 additions & 8 deletions package/contents/ui/code/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,37 @@ const baseOverrideConfig = {
"disabledFallback": true
}

const baseStockPanelSettings = {
"position": {
"enabled": false,
"value": "top"
},
"alignment": {
"enabled": false,
"value": "center"
},
"lengthMode": {
"enabled": false,
"value": "fill"
},
"visibility": {
"enabled": false,
"value": "none"
},
"opacity": {
"enabled": false,
"value": "adaptive"
},
"floating": {
"enabled": false,
"value": false
},
"thickness": {
"enabled": false,
"value": 48
}
}

const defaultConfig = {
"panel": basePanelConfig,
"widgets": baseWidgetConfig,
Expand Down Expand Up @@ -236,14 +267,7 @@ const defaultConfig = {
},
"reloadInterval": 250
},
"stockPanelSettings": {
"position": 3,
"alignment": 2,
"width": 2,
"visibility": 3,
"opacity": 2,
"floating": false
},
"stockPanelSettings": baseStockPanelSettings,
"configurationOverrides": {
"overrides": {},
"associations": {}
Expand Down
60 changes: 60 additions & 0 deletions package/contents/ui/code/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,63 @@ function getWidgetRootDir() {
path[path.length - 1] = 'contents/'
return path.join('/')
}

function getPanelPosition() {
var location
var screen = main.screen

switch (plasmoid.location) {
case PlasmaCore.Types.TopEdge:
location = "top"
break
case PlasmaCore.Types.BottomEdge:
location = "bottom"
break
case PlasmaCore.Types.LeftEdge:
location = "left"
break
case PlasmaCore.Types.RightEdge:
location = "right"
break
}

console.log("location:" + location + " screen:" + screen);
return { "screen": screen, "location": location }
}

function setPanelModeScript(panelPosition, panelSettings) {
var setPanelModeScript = `
for (var id of panelIds) {
var panel = panelById(id);
if (panel.screen === ${panelPosition.screen} && panel.location === "${panelPosition.location}" ) {
if (${panelSettings.visibility.enabled}) {
panel.hiding = "${panelSettings.visibility.value}"
}
if (${panelSettings.thickness.enabled}) {
panel.height = ${panelSettings.thickness.value}
}
if (${panelSettings.lengthMode.enabled}) {
panel.lengthMode = "${panelSettings.lengthMode.value}"
}
if (${panelSettings.position.enabled}) {
panel.location = "${panelSettings.position.value}"
}
if (${panelSettings.floating.enabled}) {
panel.floating = ${panelSettings.floating.value}
}
if (${panelSettings.alignment.enabled}) {
panel.alignment = "${panelSettings.alignment.value}"
}
if (${panelSettings.opacity.enabled}) {
panel.opacity = "${panelSettings.opacity.value}"
}
break
}
}`
return setPanelModeScript
}

function evaluateScript(script) {
console.error(script)
runCommand.run("gdbus call --session --dest org.kde.plasmashell --object-path /PlasmaShell --method org.kde.PlasmaShell.evaluateScript '" + script + "'")
}
Loading

0 comments on commit 6de0278

Please sign in to comment.