From 49cacfe787629fb61092fbc8b961f8ac9607149f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 5 Sep 2019 16:13:44 +0200 Subject: [PATCH] Refactor powermenu to rofi modus --- .config/rofi/modes/powermenu | 46 ++++++++++++++++++++++++++++++++++++ .config/sxhkd/sxhkdrc | 2 +- .local/bin/rofi-powermenu | 30 ----------------------- 3 files changed, 47 insertions(+), 31 deletions(-) create mode 100755 .config/rofi/modes/powermenu delete mode 100755 .local/bin/rofi-powermenu diff --git a/.config/rofi/modes/powermenu b/.config/rofi/modes/powermenu new file mode 100755 index 0000000..f03b2e4 --- /dev/null +++ b/.config/rofi/modes/powermenu @@ -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 2>/dev/null & + ;; +"Logout") + i3-msg exit + ;; +"Suspend") + lockscreen rofi /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 " %s\n" "$power_off_btn" + printf " %s\n" "$reboot_btn" + printf " %s\n" "$lock_btn" + printf " %s\n" "$suspend_btn" + printf " %s\n" "$logout_btn" +fi diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 4f57c15..c8059c6 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -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 diff --git a/.local/bin/rofi-powermenu b/.local/bin/rofi-powermenu deleted file mode 100755 index fdf1049..0000000 --- a/.local/bin/rofi-powermenu +++ /dev/null @@ -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