You are not logged in.
I'm running a vanilla distribution of Arch on my laptop and am looking at getting a hook onto the power button so it can execute any script I'd like when it's pressed.
By vanilla I mean I pulled the Linux base manually and added up what I needed such as XFCE4 and AwesomeWM, among many other tools and packages.
I got rid of the XFCE4 power management tools and I'm using mate-power-manager with power button actions set to "do nothing". If I set anything else it works as expected (e.g. sleep, hibernate or shutdown), but I am looking into hooking a custom script to open a homebrewed set of actions on power key pressed, depending on the context my machine is in.
I've read quite a few forums on the topic and ACPI is very often mentioned. That said, it does not run on my system and it seems it has been replaced (could not confirm that yet, I may have missed something) by systemd-logind.
My questions:
Is there anything I can do in the actual state of my install to capture a press on the power button?
Otherwise, should I install the ACPI service, and if so, won't it interfere or be redundant with systemd-logind?
Is there anything else I've missed that I could use?
Here is what I have tried so far:
Run xev and press the power button to get its name and hook to it through my AwesomeWM config:
> xev
FocusOut event, serial 36, synthetic NO, window 0x4600001,
mode NotifyGrab, detail NotifyAncestor
FocusOut event, serial 36, synthetic NO, window 0x4600001,
mode NotifyUngrab, detail NotifyPointer
FocusIn event, serial 36, synthetic NO, window 0x4600001,
mode NotifyUngrab, detail NotifyAncestor
KeymapNotify event, serial 36, synthetic NO, window 0x0,
keys: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 That gives nothing I can or know how to exploit.
It seems that no ACPI service is running on my machine as systemctl does not show any entry on it, and I can confirm systemctl shows this line for systemd-logind:
> systemctl --all
systemd-logind.service loaded active running User Login Managementjournalctl shows this line consistently when the power button is pressed (so close yet so far!):
> journalctl -f
Dec 27 22:41:35 local systemd-logind[581]: Power key pressed short.Here are the relevant info about my system I got via neofetch:
OS: Arch Linux x86_64
Host: XPS 15 9520
Kernel: 6.1.1-arch1-1
Shell: zsh 5.9
DE: Xfce 4.18
WM: awesome
CPU: 12th Gen Intel i9-12900HK (20) @ 4.900GHz
GPU: NVIDIA GeForce RTX 3050 Ti Mobile
GPU: Intel Alder Lake-P
Memory: 6945MiB / 31772MiB Thanks by advance for any help you can provide on this.
Last edited by GameLostException (2022-12-27 22:54:38)
Offline
Edit /etc/systemd/logind.conf, uncomment and change HandlePowerKey to "ignore" then add a keybind in Awesome.
I can't remember how Awesome handles keybinds but this example works for me in ~/.config/sway/config:
bindsym XF86PowerOff exec touch "$HOME/$(date)"Jin, Jîyan, Azadî
Offline
Oh boy, it worked perfectly: it seems that the /etc/systemd/logind.conf "not ignoring" the event was swallowing my Awesome's rc.lua hook to the power button:
...
awful.key({ }, "XF86PowerOff", function () naughty.notify({preset=naughty.config.presets.normal, title="FOO?", text="BAR!"})
end,
{description = "foo", group = "hotkeys"}),
...I now get a toast notification as expected, gonna hook my script now thanks to your flash-and-perfect answer. Thanks mate!
Last edited by GameLostException (2022-12-27 22:59:55)
Offline