Refactor powermenu to rofi modus

This commit is contained in:
Marty Oehme 2019-09-05 16:13:44 +02:00
parent 3d9ea5cffe
commit 49cacfe787
3 changed files with 47 additions and 31 deletions

46
.config/rofi/modes/powermenu Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env sh
#### User Options ###
#### Menu Options ###
power_off_btn=""
reboot_btn=""
lock_btn=""
suspend_btn="鈴"
logout_btn=""
# grep -a since it assumes with our nullcodes etc that this is a binary file
# grep -o to only leave the things we grep for
case $(echo "$*" | grep -a -o -e "Shutdown" -e "Reboot" -e "Lockscreen" -e "Logout" -e "Suspend") in
"Shutdown")
systemctl poweroff
;;
"Reboot")
systemctl reboot
;;
"Lockscreen")
# Completely detach from the parent script
# If in/outputs are not redirected, rofi will wait for the forked process as well.
lockscreen rofi </dev/null >/dev/null 2>/dev/null &
;;
"Logout")
i3-msg exit
;;
"Suspend")
lockscreen rofi </dev/null >/dev/null 2>/dev/null &
systemctl suspend
;;
esac
if [ -z "$*" ]; then
printf "\x00prompt\x1fPower> \n"
# we can use pango markup to hide text which we can then search. Neat!
printf "\0markup-rows\x1ftrue\n"
printf "\0filter\x1fshutdown\n"
printf "<!-- Shutdown Poweroff --> %s\n" "$power_off_btn"
printf "<!-- Reboot Restart --> %s\n" "$reboot_btn"
printf "<!-- Lockscreen --> %s\n" "$lock_btn"
printf "<!-- Suspend Sleep --> %s\n" "$suspend_btn"
printf "<!-- Exit X Logout --> %s\n" "$logout_btn"
fi

View file

@ -16,7 +16,7 @@ super + x
# Open System Power Menu
super + BackSpace
rofi-powermenu
rofi -modi "powermenu:modes/powermenu" -show powermenu -theme themes/powermenu
# enable function (/media) key functionality
# TODO: set up next song, previous song, pause, etc

View file

@ -1,30 +0,0 @@
#!/usr/bin/env sh
rofi_command="rofi -theme themes/powermenu.rasi"
### Options ###
power_off=""
reboot=""
lock=""
suspend_btn="鈴"
logout_btn=""
# Variable passed to rofi
chosen="$(printf "%s\n%s\n%s\n%s\n%s" "$power_off" "$reboot" "$lock" "$suspend_btn" "$logout_btn" | $rofi_command -dmenu -selected-row 2)"
case $chosen in
$power_off)
systemctl poweroff
;;
$reboot)
systemctl reboot
;;
$lock)
lockscreen
;;
$suspend_btn)
systemctl suspend
;;
$logout_btn)
i3-msg exit
;;
esac