[Feb 26] Recalbox beta v3.1- Rock64 |[Feb 26] Recalbox 190222- RockPro64 / Minimal Debian by mrfixit2001 - 190222 - RockPro64 |[Feb 26] Q4OS 2.7-r2 - Pinebook 1080P / Pinebook |[Feb 22] Batocera Linux 5.20-20190121- RockPro64 | [Feb 19] Manjaro KDE 19.02 / Manjaro LXQT 19.02 - Pinebook1080P / Pinebook | [Feb 19] Slackware Aarch64 Miniroot and XFCE 20190201 - RockPro | [Feb 19] Slackware Aarch64 Miniroot and XFCE 20190201 - Rock64

Project Inspiration | Get Started | IRC Logs | Forum Rules/Policy


How to set the Power Off key binding in i3wm for the Pinebook
#1
Information 
Greetings,

The purpose of this blog post is to detail the steps necessary to set the Power Off key-binding for the Pinebook in i3 window manager.  We don't want the Pinebook to come crashing down if we accidentally touch the poweroff button -- so we'll set a key-binding that makes sense requiring at least two other keys , for instance the $mod key and the Shift key.  The following key-binding should bring the system down cleanly ( and power off properly ) without prompting for a password:

       $mod+Shift+XF86_PowerOff 

The key-binding will be placed in the i3 config;  but I'm getting ahead of myself.  The first step is to build the poweroff script in /usr/local/sbin/

Pb_poweroff.sh

Code:
#!/bin/sh

poweroff

The simple script above should be placed in  /usr/local/sbin/  and should be made active with the following commands:

       sudo  chown  root:root  Pb_poweroff.sh

       sudo  chmod  0754  Pb_poweroff.sh

The next step is to place a rule file in  /etc/sudoers.d/  so that the command trigger will not prompt for the sudo password when the key-binding is pressed.  Creat the following rule file in /etc/sudoers.d/  :

Pb_power_rule

Code:
# Pb power rule
Cmnd_Alias PBPOWEROFF=/usr/local/sbin/Pb_poweroff.sh
ALL ALL=NOPASSWD: PBPOWEROFF

Place the above rule file in the  /etc/sudoers.d/  directory and activate with the following commands :

       sudo  chown  root:root  Pb_power_rule

       sudo  chmod  0440  Pb_power_rule

The last step is to place the following bindsym entry in the i3 configuration  ~/.config/i3/config  , in your home directory:

       bindsym  $mod+Shift+XF86_PowerOff  exec  sudo  /usr/local/sbin/Pb_poweroff.sh

Place the above bindsym entry somewhere near the end of your i3 config after the "resize"  and before the "bar".  The configuration file is  ~/.config/i3/config

Activate the key-binding by either pressing $mod+Shift+c to re-read the config,  or $mod+Shift+r to restart i3wm.

Theory

Pressing the Pinebook power button returns scancode 124;  key-sym XF86_PowerOff.  This by default does nothing in i3wm;  unlike other OS window manager | desktops  ,  which typically pulls up the shutdown dialogue.

With our keybinding in effect the Pb_poweroff.sh script will be called with sudo,  and because the Pb_power_rule file exists in /etc/sudoers.d/  the command trigger will not prompt for the password,  but the poweroff command will simply take effect:   while holding down the mod key,  and the Shift key together,  press the power button and the i3 window manager will exit and the system will cleanly shutdown and power off.

Shy
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
Reply
#2

Greetings,

I'm going to expand a bit on the previous post by allowing for a parameter to be passed to the Pb_poweroff.sh script so that more than one key-binding may trigger the script for a different desired affect -- reboot for instance.  So let's first make some minor changes to the script in /usr/local/sbin/

Pb_poweroff.sh

Code:
#!/bin/sh

if [ "$1" = "OFF" ]
then
   systemctl poweroff
else
   systemctl reboot
fi


The default of the above script is to reboot the Pinebook, regardless of parameter.  On the other hand, if the parameter passed is "OFF" then the command script will shutdown and power off the Pinebook as expected.

To make the changes effective lets change our power off bindsym in  ~/.config/i3/config  to the following:

       bindsym $mod+Shift+XF86_PowerOff exec sudo /usr/local/sbin/Pb_poweroff.sh OFF

To make the reboot change effective add the following bindsym to  ~/.config/i3/config  :

       bindsym $mod+Control+XF86_PowerOff exec sudo /usr/local/sbin/Pb_poweroff.sh REBOOT

Notice I've changed the modifier key from Shift to Control,  and I've changed the parameter to REBOOT.  The effect is that the power button used with $mod+Shift will power off, while the power button used with $mod+Control will in fact reboot the system.

Note:  to make the changes active press $mod+Shift+c to re-read the config file, or press $mod+Shift+r to restart the i3 window manager.

Shy
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
Reply
#3
Greetings,

In this segment I'm pointing out that the sudo poweroff and sudo reboot commands are legacy commands ( see the man pages ).  Since systemd the systemctl command should be used with either the poweroff or reboot parms.  I have changed the Pb_poweroff.sh script to accommodate this change:

Pb_poweroff.sh

Code:
#!/bin/sh

if [ "$1" = "OFF" ]
then
   systemctl poweroff
else
   systemctl reboot
fi


Shy
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )
Reply
#4
Thank you Wink

Now I'll try to find solution for lid-hibernating, only one thing why I still can't use i3 properly
Reply
#5
Thanks Mark,
I got this configured yesterday. Have you figured out how to hibernate the system in i3? I tried systemctl hibernate and it throws an error: Sleep verb not supported. hybrid-sleep gave me the same error via logind.

With Trinity I just need to push the power button to hibernate. I'm using q4os with i3 right now. Any help and advice on hibernation with i3 on the pinebook would greatly be appreciated
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Information Manjaro ARM for Pinebook erchache2000 25 154 Yesterday, 05:22 AM
Last Post: Luke
  Armbian - Xenial Desktop (Pinebook) pineadmin 79 13,472 03-06-2019, 04:20 PM
Last Post: tllim
  How can I reliably get battery status on pinebook tillea 4 904 03-05-2019, 06:43 AM
Last Post: chessie
  Q4OS for PINEBOOK q4osteam 84 19,753 02-26-2019, 01:39 AM
Last Post: pineadmin
  Archlinux (mainline) for Pinebook anarsoul 48 11,126 02-15-2019, 02:19 PM
Last Post: e-minguez
  No display options on Pinebook or Pineboard Fox7799 0 146 02-06-2019, 11:56 AM
Last Post: Fox7799
  KDE Neon Pinebook remix edition RC image bshah 64 17,282 02-06-2019, 06:04 AM
Last Post: soupbowl
  Exagear Desktop on Pinebook AndyK 2 1,187 01-18-2019, 04:20 AM
Last Post: binholz
  DietPi for Pinebook Fourdee 10 2,063 01-09-2019, 08:38 AM
Last Post: WZ9V
Information How to set Keybindings for LCD Brightness in i3wm MarkHaysHarris777 2 756 12-09-2018, 12:40 PM
Last Post: Surehand53

Forum Jump:


Users browsing this thread: 1 Guest(s)