Thank you so much for your input!
I managed to do it with KWin Scripting. It’s fairly easy, but I had a hell of time getting the shortcuts registered (bug report). It’s no replacement for xdotool, but I could do everything I wanted, and the execution is even less bug prone than xdotool.
In case you’re interested. The following script does the trick for me. Just put it in a main.js
as described in the tutorial and install it with kpackagetool5 --type=KWin/Script -i ~/path/to/script/dir/
.
// ***** collect relevant data *****
function getData () {
const client = workspace.activeClient;
const clientGeometry = client.frameGeometry;
const workspaceArea = workspace.clientArea(KWin.MaximizeArea, client.screen, client.desktop);
return {
client,
clientGeometry,
workspaceArea,
};
}
// ***** position the active window *****
// pos = string
function position (pos) {
const { client, clientGeometry, workspaceArea } = getData();
let x;
if (pos === "center") {
x = Math.round(workspaceArea.width / 2 - clientGeometry.width / 2);
} else if (pos === "left") {
x = 0;
} else if (pos === "right") {
x = workspaceArea.width - clientGeometry.width;
}
client.frameGeometry = {
x,
y: clientGeometry.y,
width: clientGeometry.width,
height: clientGeometry.height,
};
}
// ***** resize the active window ****
// width = integer
function resize (width) {
const { client, clientGeometry, workspaceArea } = getData();
const x = Math.round(workspaceArea.width / 2 - width / 2);
const y = workspaceArea.y;
const height = workspaceArea.height;
if (clientGeometry.height !== height ||
clientGeometry.width !== width ||
clientGeometry.y !== y ||
clientGeometry.x !== x) {
client.frameGeometry = {
x,
y,
width,
height,
};
}
}
// ***** shortcuts to resize the active window *****
const widths = [ 800, 1100, 1250, 1450 ];
registerShortcut(`MoRe Resize ${widths[0]}`, `MoRe Resize ${widths[0]}`, "Meta+Alt+B", () => resize(widths[0]));
registerShortcut(`MoRe Resize ${widths[1]}`, `MoRe Resize ${widths[1]}`, "Meta+Ctrl+B", () => resize(widths[1]));
registerShortcut(`MoRe Resize ${widths[2]}`, `MoRe Resize ${widths[2]}`, "Meta+B", () => resize(widths[2]));
registerShortcut(`MoRe Resize ${widths[3]}`, `MoRe Resize ${widths[3]}`, "Meta+Ctrl+Alt+B", () => resize(widths[3]));
// ***** shortcuts to position the active window *****
registerShortcut("MoRe Position Center", "MoRe Position Center", "Meta+Alt+Up", () => position("center"));
registerShortcut("MoRe Position Left", "MoRe Position Left", "Meta+Alt+Left", () => position("left"));
registerShortcut("MoRe Position Right", "MoRe Position Right", "Meta+Alt+Right", () => position("right"));