Skip to content

Commit

Permalink
#27: detect qdbus command name
Browse files Browse the repository at this point in the history
  • Loading branch information
antroids committed Mar 28, 2024
1 parent b28bb1d commit 1ebcbb7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 28 deletions.
68 changes: 56 additions & 12 deletions package/contents/ui/KWinConfig.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@ Item {
id: kWinConfig

readonly property string auroraeThemesPath: "aurorae/themes/"
readonly property string reconfigureCommand: "qdbus org.kde.KWin /KWin reconfigure"
readonly property string setBorderlessMaximizedWindowsCommand: "kwriteconfig6 --file kwinrc --group Windows --key BorderlessMaximizedWindows "
readonly property string getBorderlessMaximizedWindowsCommand: "kreadconfig6 --file kwinrc --group Windows --key BorderlessMaximizedWindows --default false"
readonly property string getAllKWinShortcutNamesCommand: "qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.shortcutNames"
readonly property string invokeKWinShortcutCommand: "qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "
readonly property string checkQdbusApplicationNameCommand: "if command -v qdbus > /dev/null; then echo qdbus; elif command -v qdbus6 > /dev/null; then echo qdbus6; else exit 1; fi"
property string reconfigureCommand: qdbusApplicationName + " org.kde.KWin /KWin reconfigure"
property string getAllKWinShortcutNamesCommand: qdbusApplicationName + " org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.shortcutNames"
property string invokeKWinShortcutCommand: qdbusApplicationName + " org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "
property var borderlessMaximizedWindows
property var callbacksOnExited: []
property var auroraeThemesLocations: StandardPaths.locateAll(StandardPaths.GenericDataLocation, auroraeThemesPath, StandardPaths.LocateDirectory)
property ListModel auroraeThemes
property var shortcutNames: []
property string qdbusApplicationName: "qdbus"
property string lastError: ""

function setBorderlessMaximizedWindows(val) {
let cmd = setBorderlessMaximizedWindowsCommand + val + " && " + reconfigureCommand + " && " + getBorderlessMaximizedWindowsCommand;
callbacksOnExited.push({
"cmd": cmd,
"callback": function(cmd, exitCode, exitStatus, stdout, stderr) {
borderlessMaximizedWindows = stdout.trim() == "true";
"callback": function (cmd, exitCode, exitStatus, stdout, stderr) {
if (exitCode == 0) {
borderlessMaximizedWindows = stdout.trim() == "true";
} else {
lastError = "Unable to update set BorderlessMaximizedWindows status: '" + stderr + "'";
}
}
});
executable.exec(cmd);
Expand All @@ -38,8 +45,12 @@ Item {
let cmd = getBorderlessMaximizedWindowsCommand;
callbacksOnExited.push({
"cmd": cmd,
"callback": function(cmd, exitCode, exitStatus, stdout, stderr) {
borderlessMaximizedWindows = stdout.trim() == "true";
"callback": function (cmd, exitCode, exitStatus, stdout, stderr) {
if (exitCode == 0) {
borderlessMaximizedWindows = stdout.trim() == "true";
} else {
lastError = "Unable to update get BorderlessMaximizedWindows status: '" + stderr + "'";
}
}
});
executable.exec(cmd);
Expand All @@ -65,8 +76,12 @@ Item {
let cmd = getAllKWinShortcutNamesCommand;
callbacksOnExited.push({
"cmd": cmd,
"callback": function(cmd, exitCode, exitStatus, stdout, stderr) {
shortcutNames = stdout.trim().split(/\r?\n/).sort();
"callback": function (cmd, exitCode, exitStatus, stdout, stderr) {
if (exitCode == 0) {
shortcutNames = stdout.trim().split(/\r?\n/).sort();
} else {
lastError = "Unable to update KWin shortcuts: '" + stderr + "'";
}
}
});
executable.exec(cmd);
Expand All @@ -81,13 +96,36 @@ Item {
print("Error: shortcut '" + trimmedShortcut + "' not found in the list!");
}

function updateQdbusApplicationName() {
let cmd = checkQdbusApplicationNameCommand;
callbacksOnExited.push({
"cmd": cmd,
"callback": function (cmd, exitCode, exitStatus, stdout, stderr) {
if (exitCode == 0) {
qdbusApplicationName = stdout.trim();
qdbusApplicationNameChanged();
} else {
lastError = "Unable to find QDbus command";
}
}
});
executable.exec(cmd);
}

function clearLastError() {
lastError = "";
}

ExecutableDataSource {
id: executable
}

Connections {
function onExited(cmd, exitCode, exitStatus, stdout, stderr) {
//print("onExited: cmd: " + cmd + "; stdout: " + stdout + "; stderr: " + stderr);
//print("onExited: cmd: " + cmd + "; exitCode:" + exitCode + "; stdout: " + stdout + "; stderr: " + stderr);
if (exitCode == 0) {
clearLastError();
}
for (var i = 0; i < callbacksOnExited.length; i++) {
if (callbacksOnExited[i].cmd === cmd) {
callbacksOnExited[i].callback(cmd, exitCode, exitStatus, stdout, stderr);
Expand Down Expand Up @@ -120,12 +158,18 @@ Item {
required property string fileName
required property string filePath
}

}

}

auroraeThemes: ListModel {
}

Component.onCompleted: function () {
updateQdbusApplicationName();
}

onQdbusApplicationNameChanged: function () {
updateBorderlessMaximizedWindows();
updateKWinShortcutNames();
}
}
8 changes: 8 additions & 0 deletions package/contents/ui/config/ConfigAppearance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ KCM.SimpleKCM {
onAuroraeThemesChanged: widgetButtonsAuroraeTheme.updateCurrentIndex()
}

Kirigami.InlineMessage {
anchors.left: parent.left
anchors.right: parent.right
text: kWinConfig.lastError
type: Kirigami.MessageType.Error
visible: kWinConfig.lastError !== ""
}

Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Window Control Buttons")
Expand Down
17 changes: 9 additions & 8 deletions package/contents/ui/config/ConfigBehavior.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ KCM.SimpleKCM {
KWinConfig {
id: kWinConfig

Component.onCompleted: function() {
updateBorderlessMaximizedWindows();
updateKWinShortcutNames();
}
onBorderlessMaximizedWindowsChanged: {
borderlessMaximizedWindowsCheckBox.checked = borderlessMaximizedWindows;
borderlessMaximizedWindowsCheckBox.enabled = true;
Expand All @@ -66,6 +62,14 @@ KCM.SimpleKCM {
visible: Utils.isX11()
}

Kirigami.InlineMessage {
anchors.left: parent.left
anchors.right: parent.right
text: kWinConfig.lastError
type: Kirigami.MessageType.Error
visible: kWinConfig.lastError !== ""
}

RowLayout {
Kirigami.FormData.label: i18n("Active task source:")

Expand All @@ -78,7 +82,6 @@ KCM.SimpleKCM {
KCM.ContextualHelpButton {
toolTipText: i18n("<p>How to obtain the active task from tasks manager: <br><b>Active task</b>: current active task after filtering. The widget will be disabled if the current active task is on another screen, regardless whether there are another tasks on this screen or not.<br/><b>Last active task</b>: show widget for the last active task after filters applied.<br/><b>Last active maximized task</b>: show widget for the last active maximized task after filters applied.</p>")
}

}

CheckBox {
Expand All @@ -87,7 +90,7 @@ KCM.SimpleKCM {
Kirigami.FormData.label: i18n("Borderless maximized windows:")
text: i18n("enabled")
enabled: false
onToggled: function() {
onToggled: function () {
enabled = false;
kWinConfig.setBorderlessMaximizedWindows(checked);
}
Expand Down Expand Up @@ -293,7 +296,5 @@ KCM.SimpleKCM {
initialValue: cfg_widgetMouseAreaWheelRightAction
onActivated: cfg_widgetMouseAreaWheelRightAction = currentValue
}

}

}
17 changes: 10 additions & 7 deletions package/contents/ui/config/KWinShortcutComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ ComboBox {
property var initialValue

function updateCurrentIndex() {
enabled = model.length > 1;
currentIndex = indexOfValue(initialValue);
}

Component.onCompleted: updateCurrentIndex()
onModelChanged: updateCurrentIndex()
Kirigami.FormData.label: label
model: [{
"shortcut": "",
"truncatedName": " "
}].concat(kWinConfig.shortcutNames.map((shortcut) => {
model: [
{
"shortcut": "",
"truncatedName": " "
}
].concat(kWinConfig.shortcutNames.map(shortcut => {
return ({
"shortcut": shortcut,
"truncatedName": Utils.truncateString(shortcut, 40)
});
"shortcut": shortcut,
"truncatedName": Utils.truncateString(shortcut, 40)
});
}))
valueRole: "shortcut"
textRole: "truncatedName"
Expand Down
2 changes: 1 addition & 1 deletion package/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Id": "com.github.antroids.application-title-bar",
"Name": "Application Title Bar",
"License": "GPL-3.0+",
"Version": "0.4.5",
"Version": "0.4.6",
"Website": "https://github.com/antroids/application-title-bar",
"FormFactors": [
"desktop"
Expand Down

0 comments on commit 1ebcbb7

Please sign in to comment.