Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Remap power button to hybrid-sleep button
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
OmamoriIchika
n00b
n00b


Joined: 27 Jan 2021
Posts: 61

PostPosted: Mon Mar 15, 2021 9:44 pm    Post subject: Remap power button to hybrid-sleep button Reply with quote

My laptop has tablet mode. A lot of time I will accidentally push the power button in tablet mode, so I want to remap power button to hybrid-sleep button using acpi. Can some check weather I’m doing right?

Code:

$sudo nano /etc/acpi/events/power
event=button/power
action=/etc/acpi/hybridsleepsys.sh

$sudo nano /etc/acpi/hybridsleepsys.sh
#!/bin/bash
loginctl hybrid-sleep

$sudo chmod u+x /etc/acpi/hybridsleepsys.sh

$sudo rc-service acpid restart
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3763
Location: Rasi, Finland

PostPosted: Thu Mar 18, 2021 10:01 pm    Post subject: Reply with quote

Are you using elogind or systemd?
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
OmamoriIchika
n00b
n00b


Joined: 27 Jan 2021
Posts: 61

PostPosted: Sat Mar 20, 2021 8:48 pm    Post subject: Reply with quote

Zucca wrote:
Are you using elogind or systemd?

I use elogind.


Code:

$sudo nano /etc/acpi/events/power
event=button/power
action=/etc/acpi/hybridsleepsys.sh

$sudo nano /etc/acpi/hybridsleepsys.sh
#!/bin/bash
[ "$2" = "PTBN" ] && exec loginctl hybrid-sleep

$sudo chmod u+x /etc/acpi/hybridsleepsys.sh

$sudo rc-service acpid restart


I change to this, but after I push power button, it still shutdown the PC.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3763
Location: Rasi, Finland

PostPosted: Sun Mar 21, 2021 7:28 am    Post subject: Reply with quote

I think this is because elogind grabs the power button input and runs the shutdown command before your script can run.

  • Edit as root your /etc/elogind/logind.conf.
  • Find the line which sets HandlePowerKey.
  • Change the line to: HandlePowerKey=hybrid-sleep
  • Make sure that line is also uncommented (does not start with #).
  • Run as root
    Code:
    rc-config restart elogind
    !!! This will terminate your current session and take you back to login screen.


This way you don't need script to execute sleep commands. ;)

EDIT: fixed the filename from elogind.conf to logind.conf
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!


Last edited by Zucca on Sun Mar 21, 2021 8:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3956

PostPosted: Sun Mar 21, 2021 8:05 pm    Post subject: Reply with quote

Zucca wrote:
Edit as root your /etc/elogind/elogind.conf
file not found here:
Code:
sys-auth/elogind Installed versions:  246.9.2(14:40:06 19/02/2021)(pam policykit -acl -audit -debug -doc -selinux KERNEL="linux")
Any idea what I am missing?
Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3763
Location: Rasi, Finland

PostPosted: Sun Mar 21, 2021 8:21 pm    Post subject: Reply with quote

CaptainBlood wrote:
Zucca wrote:
Edit as root your /etc/elogind/elogind.conf
file not found here
Oops! Indeed I wrote wrong filename. The correct one is: /etc/elogind/logind.conf
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3956

PostPosted: Sun Mar 21, 2021 8:37 pm    Post subject: Reply with quote

Tested working after
Code:
/etc/init.d/elogind restart
Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum