You are not logged in.

#1 2024-04-08 05:17:55

an24
Member
Registered: 2024-04-02
Posts: 10

Power button delay

Hello,

I have been trying to set a delay to the power button on my laptop (arch 6.6.25-1-lts / openbox). I have tried both logind and acpid, but obviously I am doing something wrong. The only thing I have been able to achieve is the delay after I touch the button. But it is not what I want. My goal is that the system is shut down only after I have been holding the power button pressed for 2-3 seconds.

Could somebody please give me some advice?

Thank you.

Offline

#2 2024-04-08 07:24:51

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

That's probably not gonna work.
The short press usually gets exposed to the OS, but the long press is done in HW and cuts power from the board - you cannot intercept that at all, but it will cause an (unclean) shutdown of the system.

https://en.wikipedia.org/wiki/XY_problem
Why are you trying to do this?

Offline

#3 2024-04-08 18:20:29

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

seth wrote:

That's probably not gonna work....Why are you trying to do this?

Thanks for the reply.

I have touched the power button instead of the backspace a few times already, and the system shuts down immediately, which is quite irritating. So, if can't do otherwise, I'll probably change the poweroff function to suspend or hibernate.

Thanks again.

Offline

#4 2024-04-08 19:16:18

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

When you "touch" the power button, does the system shut down properly or does it just power down abruptly?
The tail of the system journal of the previous boot (sudo journalctl -b -1) should indicate the shutdown process, a controlled shutdown in response to the power button shows up there - otherwise the journal ends abruptly w/o any shutdown messages.

Offline

#5 2024-04-08 19:20:53

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

Again, thanks for the reply.

The system shuts down properly. I have already reassigned the power button to suspend, and I think it will do for me.

Thank you!

Offline

#6 2024-04-08 19:32:22

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

So it's indeed handled by logind - make sure acpid isn't running.

https://man.archlinux.org/man/core/syst … .conf.5.en

HandlePowerKey=ignore
HandlePowerKeyLongPress=poweroff

does not do what you want? What happens instead?

nb. the overlaying structure, make sure no other setting for this is enabled/takes precendence.
Also I thing you'll have to restart the logind service to have this change apply.

Offline

#7 2024-04-08 19:56:07

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

I have tried
HandlePowerKey=ignore
HandlePowerKeyLongPress=poweroff

It shuts down the system after about 8 seconds. It is a bit too much. So I've changed it to
HandlePowerKeyLongPress=sleep 3 && poweroff

It did not change anything.

Offline

#8 2024-04-08 21:04:28

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

You cannot impact the delay of the long press - did the 8s press result in a clean shutdown or an immediate power loss?
(Ie. was it handled by systemd or the hard/firmware)

HandlePowerKeyLongPress=sleep 3 && poweroff

isn't a legal statement.

What you possibly could do would be to intercept the power key (short press) in acpid, sleep 3s, check whether the key is still pressed and then trigger "systemctl shutdown".

evtest --query /dev/input/event0 EV_KEY KEY_POWER

might come handy here (nb. that it's not necessarily event0, "evtest" prints you a list of event devices)

Offline

#9 2024-04-08 21:53:23

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

It was a clean shutdown. I will try what you suggest.

Thank you!

Offline

#10 2024-04-08 23:02:35

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

I give up. Thank you!

Offline

#11 2024-04-09 06:31:04

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

If you un-give up, post what you have, what it does and where you're stuck.

Offline

#12 2024-04-09 18:00:26

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

Post edited

Last edited by an24 (2024-04-10 00:05:26)

Offline

#13 2024-04-09 20:45:13

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

Regarding "evtest --query /dev/input/event0 EV_KEY KEY_POWER", I went through every event (0-12) and it returned nothing.

It returns a return code (for sure) and that's either "0" if the key isn't pressed or > 0 (typically 1) if it is.
You can

evtest --query /dev/input/event0 EV_KEY KEY_POWER && echo foo

If event0 is the correct device and the key is pressed, it'll print "foo"

Please use [code][/code] tags. Edit your post in this regard.

cat: /proc/acpi/button/power/PWRBTN/state: No such file or directory

means that entire approach isn't going anywhere and the takeaway is that

I always ask GPT how to do things

will only end up w/ you doing dumb things because chatGPT is an authorative bullshit generator. It's great at telling really eloquent nonsense, nonsense nevertheless.

Offline

#14 2024-04-10 00:15:30

an24
Member
Registered: 2024-04-02
Posts: 10

Re: Power button delay

seth wrote:

... entire approach ... will only end up w/ you doing dumb things because chatGPT is an authorative bullshit generator.

Well, that may be true, but so far chatGPT has been quite helpful and useful. And polite. And it is exactly because of people like you I prefer using "bullshit generators."

Offline

#15 2024-04-10 08:41:21

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,009

Re: Power button delay

I'm not "polite" because people get stupid ideas into their heads and unless you very explicitly tell them that it's stupid, even if you just leave a tiny bit of "well, that could probably be correct but…" they'll just insist on blindly running down that rabbit hole into a disaster.

It's your system, you can do whatever you want.
But chatgpt has - very politely, I'm sure - fed you misdirecting misinformation based on not understanding what it's talking about itfp.

Offline

Board footer

Powered by FluxBB