How can I map the power button in KWin?

Hello, how can I assign actions to the power button in KDE? I’m an LXQt user. LXQt provides the best support for KWin, which is why I like using it. However, the power button is the only thing causing issues; I couldn’t assign a shortcut to it. If there’s a developer who knows about powerdevil or how the system detects the power button, could you possibly show me some sample C++ code on how to do it? I’d appreciate the help :slightly_smiling_face:

This is a strange quote which should be clarified, as you present it as if it is an established fact.

KWin offers the best support for LXQt, not the other way around…

Plasma has deeper, native integration with KWin when compared with LXQt.

Is it not possible for you to write a shutdown command and bind that to a keyboard shortcut?

It would be fine to go with something like Meta_F12 or something to issue a shutdown command.

I don’t know, I prefer KDE Plasma because this stuff just works :wink:

It does seem strange that your issue is with LXQt, and yet you think that binding a power button is the realm of a KDE forum because you’re using KWin… yet KWin isn’t the tool being used for the shutdown.

Thanks for your feedback. I also love using LXQt :slightly_smiling_face:

Actually, it’s quite the opposite; LXQt offers the best support for KWin. This is because LXQt tools need to be specifically configured for KWin. And it provides this for many window managers using Wayland. Those using Wlroots are usually even easier. Its support is as follows

Even though there are shortcuts like Meta+F12, what I want is for the power button to work. KDE shortcuts can’t be assigned to the power button. Normally, every compositor provides this. This shows that KDE follows a different path. I want to write something simple myself using C++. Right now, I’m handling this with a script I wrote using libinput, but having such a script running in the background isn’t very practical.

#!/bin/sh
EVENT_ID=$(grep -l "Power Button" /sys/class/input/event*/device/name | head -n 1 | awk -F/ '{print $5}')

if [ -z "$EVENT_ID" ]; then
    echo "ERROR: Power Button not found"
    exit 1
fi

/usr/bin/libinput debug-events --device /dev/input/${EVENT_ID} | grep --line-buffered "KEYBOARD_KEY.*KEY_POWER.*116.*pressed" | while read l; do lxqt-leave; done