Hello!
tl;dr: I would like the ability to draw on the desktop like plasmoids, but with access to the full KWin scripting API. I had a hack that worked well enough on X11, but no longer works on Wayland.
I am updating a manual tiling KWin script and would like to draw some rectangles using QML for display purposes only. Ideally I would like this to be drawn above the wallpaper, but below everything else on the desktop.
The code below came close enough on X11
main.qml:
import "../code/main.mjs" as Script
import QtQuick
import org.kde.kwin
import org.kde.plasma.core as PlasmaCore
Window {
id: root
visible: true
flags: Qt.X11BypassWindowManagerHint | Qt.WindowTransparentForInput
width: Workspace.workspaceWidth
height: Workspace.workspaceHeight
color: "transparent"
Component.onCompleted: {
Script.main(root);
}
}
main.ts:
export function main(rootWindow: any) {
const geometry = {
width: 30,
height: 20,
x: 5,
y: 5,
};
const borderWidth = 5;
const borderColor = "#00f";
const qmlStr = `
import QtQuick 2.0;
Rectangle {
color: "transparent";
width: ${geometry.width + borderWidth * 2};
height: ${geometry.height + borderWidth * 2};
x: ${geometry.x - borderWidth};
y: ${geometry.y - borderWidth};
border.color: "${borderColor}";
border.width: ${borderWidth};
}`;
// @ts-ignore
const sprite = Qt.createQmlObject(qmlStr, rootWindow, "dynamicSnippet1");
}
metadata.json:
{
...
"KPackageStructure": "KWin/Script",
"X-KDE-ConfigModule": "kwin/effects/configs/kcm_kwin4_genericscripted",
"X-Plasma-API": "declarativescript",
...
}
On Wayland, the same approach results in a new floating, transparent window, but it behaves like a regular window. This makes sense since Qt.X11BypassWindowManagerHint
, which was key to the desired behavior, doesn’t work on Wayland.
I’ve tried different Plasma objects as the root (plasmaquick/plasmawindow.h
, Item
, PlasmoidItem
), but none made a difference.
My next step would be to dig into libplasma to see how plasmoids avoid(?) creating new windows, but that doesn’t sound like a lot of fun.
I’m fairly lost so any input/advice/feedback would be much appreciated.
Thanks!
The desired behavior on X11: