diff --git a/package/contents/ui/DBusMethodCall.qml b/package/contents/ui/DBusMethodCall.qml new file mode 100644 index 0000000..0433727 --- /dev/null +++ b/package/contents/ui/DBusMethodCall.qml @@ -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)) + } + } +} diff --git a/package/contents/ui/DBusServiceModel.qml b/package/contents/ui/DBusServiceModel.qml index 674ef39..0b1bb22 100644 --- a/package/contents/ui/DBusServiceModel.qml +++ b/package/contents/ui/DBusServiceModel.qml @@ -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) } } } @@ -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) } } } diff --git a/package/contents/ui/code/utils.js b/package/contents/ui/code/utils.js index 96f9cae..aace8d7 100644 --- a/package/contents/ui/code/utils.js +++ b/package/contents/ui/code/utils.js @@ -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 diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml index 6f1371a..990f7d1 100644 --- a/package/contents/ui/main.qml +++ b/package/contents/ui/main.qml @@ -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() } }