Skip to content

Commit

Permalink
refactor: port most dbus calls to org.kde.plasma.workspace.dbus
Browse files Browse the repository at this point in the history
calling org.kde.PlasmaShell.evaluateScript crashes crashes plasma for some reason so that one still uses gdbus for now
  • Loading branch information
luisbocanegra committed Jan 20, 2025
1 parent 4c347f5 commit 09dca49
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 37 deletions.
34 changes: 34 additions & 0 deletions package/contents/ui/DBusMethodCall.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma ComponentBehavior: Bound
pragma ValueTypeBehavior: Addressable

import QtQuick
import org.kde.plasma.workspace.dbus as DBus

QtObject {
id: root
property string busType: DBus.BusType.Session
property string service: ""
property string objectPath: ""
property string iface: ""
property string method: ""
property var arguments: []
property var signature: null
property var inSignature: null

property DBus.dbusMessage msg: {
"service": root.service,
"path": root.objectPath,
"iface": root.iface,
"member": root.method,
"arguments": root.arguments,
"signature": root.signature,
"inSignature": root.inSignature,
}

function call(callback) {
const reply = DBus.SessionBus.asyncCall(root.msg) as DBus.DBusPendingReply
if (callback) {
reply.finished.connect(() => callback(reply))
}
}
}
88 changes: 53 additions & 35 deletions package/contents/ui/DBusServiceModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,59 @@ Item {
property string serviceUtil: toolsDir+"service.py"
property string pythonExecutable: plasmoid.configuration.pythonExecutable
property string serviceCmd: pythonExecutable + " '" + serviceUtil + "' " + Plasmoid.containment.id + " " + Plasmoid.id
property string dbusName: Plasmoid.metaData.pluginId + ".c" + Plasmoid.containment.id + ".w" + Plasmoid.id
property string gdbusPartial: "gdbus call --session --dest "+dbusName+" --object-path /preset --method "+dbusName
property string pendingSwitchCmd: gdbusPartial +".pending_switch"
property string switchDoneCmd: gdbusPartial +".switch_done"
property string getPresetCmd: gdbusPartial +".preset"
property string getPropertyToApplyCmd: gdbusPartial + ".property"
property string quitServiceCmd: gdbusPartial +".quit"

readonly property string service: Plasmoid.metaData.pluginId + ".c" + Plasmoid.containment.id + ".w" + Plasmoid.id
readonly property string path: "/preset"

function setPreset(reply) {
if (reply?.value) {
// console.log("preset", reply.value)
preset = reply.value
}
}

function setProperty(reply) {
if (reply?.value) {
// console.log("property", reply.value)
propertyToApply = reply.value
}
}

DBusMethodCall {
id: dbusGetPreset
service: root.service
objectPath: "/preset"
iface: root.service
method: "preset"
arguments: []
signature: "s"
}

DBusMethodCall {
id: dbusGetProperty
service: root.service
objectPath: "/preset"
iface: root.service
method: "property"
arguments: []
signature: "s"
}

DBusMethodCall {
id: dbusQuit
service: root.service
objectPath: "/preset"
iface: root.service
method: "quit"
arguments: []
}

RunCommand {
id: runCommand
onExited: (cmd, exitCode, exitStatus, stdout, stderr) => {
// console.error(cmd, exitCode, exitStatus, stdout, stderr)
if (exitCode!==0) return
stdout = stdout
.trim()
.replace(/^\([']?/, "") // starting ( or ('
.replace(/[']?,\)$/, "") // ending ,) or ',)
// console.log(`stdout parsed: '${stdout}'`)
if(cmd === pendingSwitchCmd) {
switchIsPending = stdout === "true"
}
if (cmd === getPresetCmd) {
preset = stdout
switchIsPending = false
}
if (cmd === getPropertyToApplyCmd) {
propertyToApply = stdout
if (exitCode !== 0) {
console.error(cmd, exitCode, exitStatus, stdout, stderr)
}
}
}
Expand All @@ -54,28 +80,20 @@ Item {
if (enabled) {
runCommand.run(serviceCmd)
} else (
runCommand.run(quitServiceCmd)
dbusQuit.call()
)
}

onEnabledChanged: toggleService()

onSwitchIsPendingChanged: {
if (switchIsPending) {
runCommand.run(switchDoneCmd)
runCommand.run(getPresetCmd)
}
}

Timer {
id: updateTimer
interval: poolingRate
running: enabled
interval: root.poolingRate
running: root.enabled
repeat: true
onTriggered: {
runCommand.run(getPropertyToApplyCmd)
if (switchIsPending) return
runCommand.run(pendingSwitchCmd)
dbusGetPreset.call(root.setPreset)
dbusGetProperty.call(root.setProperty)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package/contents/ui/code/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function parseValue(rawValue) {
* @param {string} value - The value to set.
*/
function editProperty(object, path, value) {
console.log(`editing property path: ${path}, value: ${value}`)
console.log(`editing property path: '${path}' value: '${value}'`)
value = parseValue(value)
const keys = path.replace(/\[/g, ".").replace(/\]/g, "").split(".")
let current = object
Expand Down
13 changes: 12 additions & 1 deletion package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,22 @@ PlasmoidItem {
}
}

DBusMethodCall {
id: dbusKWinReconfigure
service: "org.kde.KWin"
objectPath: "/KWin"
iface: service
method: "reconfigure"
arguments: []
signature: null
inSignature: null
}

Timer {
id: reconfigureTimer
interval: 10
onTriggered: {
runCommand.run("gdbus call --session --dest org.kde.KWin --object-path /KWin --method org.kde.KWin.reconfigure")
dbusKWinReconfigure.call()
}
}

Expand Down

0 comments on commit 09dca49

Please sign in to comment.