Skip to content

Commit 6de0278

Browse files
committed
feat: allow configuring stock panel settings
Makes use of the Plasma scripting API closes: #103
1 parent c6dfe49 commit 6de0278

File tree

5 files changed

+461
-9
lines changed

5 files changed

+461
-9
lines changed

package/contents/config/config.qml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ ConfigModel {
2121
source: "configGlobal.qml"
2222
}
2323

24+
ConfigCategory {
25+
name: i18n("Stock Panel Settings")
26+
icon: "configure-symbolic"
27+
source: "configStockPanelSettings.qml"
28+
}
29+
2430
ConfigCategory {
2531
name: i18n("Unified background")
2632
icon: "lines-connector-symbolic"

package/contents/ui/code/globals.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,37 @@ const baseOverrideConfig = {
209209
"disabledFallback": true
210210
}
211211

212+
const baseStockPanelSettings = {
213+
"position": {
214+
"enabled": false,
215+
"value": "top"
216+
},
217+
"alignment": {
218+
"enabled": false,
219+
"value": "center"
220+
},
221+
"lengthMode": {
222+
"enabled": false,
223+
"value": "fill"
224+
},
225+
"visibility": {
226+
"enabled": false,
227+
"value": "none"
228+
},
229+
"opacity": {
230+
"enabled": false,
231+
"value": "adaptive"
232+
},
233+
"floating": {
234+
"enabled": false,
235+
"value": false
236+
},
237+
"thickness": {
238+
"enabled": false,
239+
"value": 48
240+
}
241+
}
242+
212243
const defaultConfig = {
213244
"panel": basePanelConfig,
214245
"widgets": baseWidgetConfig,
@@ -236,14 +267,7 @@ const defaultConfig = {
236267
},
237268
"reloadInterval": 250
238269
},
239-
"stockPanelSettings": {
240-
"position": 3,
241-
"alignment": 2,
242-
"width": 2,
243-
"visibility": 3,
244-
"opacity": 2,
245-
"floating": false
246-
},
270+
"stockPanelSettings": baseStockPanelSettings,
247271
"configurationOverrides": {
248272
"overrides": {},
249273
"associations": {}

package/contents/ui/code/utils.js

+60
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,63 @@ function getWidgetRootDir() {
400400
path[path.length - 1] = 'contents/'
401401
return path.join('/')
402402
}
403+
404+
function getPanelPosition() {
405+
var location
406+
var screen = main.screen
407+
408+
switch (plasmoid.location) {
409+
case PlasmaCore.Types.TopEdge:
410+
location = "top"
411+
break
412+
case PlasmaCore.Types.BottomEdge:
413+
location = "bottom"
414+
break
415+
case PlasmaCore.Types.LeftEdge:
416+
location = "left"
417+
break
418+
case PlasmaCore.Types.RightEdge:
419+
location = "right"
420+
break
421+
}
422+
423+
console.log("location:" + location + " screen:" + screen);
424+
return { "screen": screen, "location": location }
425+
}
426+
427+
function setPanelModeScript(panelPosition, panelSettings) {
428+
var setPanelModeScript = `
429+
for (var id of panelIds) {
430+
var panel = panelById(id);
431+
if (panel.screen === ${panelPosition.screen} && panel.location === "${panelPosition.location}" ) {
432+
if (${panelSettings.visibility.enabled}) {
433+
panel.hiding = "${panelSettings.visibility.value}"
434+
}
435+
if (${panelSettings.thickness.enabled}) {
436+
panel.height = ${panelSettings.thickness.value}
437+
}
438+
if (${panelSettings.lengthMode.enabled}) {
439+
panel.lengthMode = "${panelSettings.lengthMode.value}"
440+
}
441+
if (${panelSettings.position.enabled}) {
442+
panel.location = "${panelSettings.position.value}"
443+
}
444+
if (${panelSettings.floating.enabled}) {
445+
panel.floating = ${panelSettings.floating.value}
446+
}
447+
if (${panelSettings.alignment.enabled}) {
448+
panel.alignment = "${panelSettings.alignment.value}"
449+
}
450+
if (${panelSettings.opacity.enabled}) {
451+
panel.opacity = "${panelSettings.opacity.value}"
452+
}
453+
break
454+
}
455+
}`
456+
return setPanelModeScript
457+
}
458+
459+
function evaluateScript(script) {
460+
console.error(script)
461+
runCommand.run("gdbus call --session --dest org.kde.plasmashell --object-path /PlasmaShell --method org.kde.PlasmaShell.evaluateScript '" + script + "'")
462+
}

0 commit comments

Comments
 (0)