add suspend-and-hibernate and hybrid sleep optios

This commit is contained in:
Alpha 2024-07-18 15:50:00 +05:30
parent 7c6953721b
commit 79f9f9aa59
No known key found for this signature in database
GPG Key ID: E61724645DD4AC78

View File

@ -14,101 +14,119 @@ dir="$HOME/.config/rofi/powermenu/type-1"
theme='style-1' theme='style-1'
# CMDs # CMDs
uptime="`uptime -p | sed -e 's/up //g'`" uptime="$(uptime -p | sed -e 's/up //g')"
host=`hostname` host=$(hostname)
# Options # Options
shutdown=' Shutdown' shutdown=' Shutdown'
reboot=' Reboot' reboot=' Reboot'
lock=' Lock' lock=' Lock'
suspend=' Suspend' suspend=' Suspend'
hibernate='󰒲 Hibernate'
hybrid='󰜎 Hybrid Sleep'
susbernate=' Suspend then Hibernate'
logout=' Logout' logout=' Logout'
yes=' Yes' yes=' Yes'
no=' No' no=' No'
# Rofi CMD # Rofi CMD
rofi_cmd() { rofi_cmd() {
rofi -dmenu \ rofi -dmenu \
-p "$host" \ -p "$host" \
-mesg "Uptime: $uptime" \ -mesg "Uptime: $uptime" \
-theme ${dir}/${theme}.rasi -theme ${dir}/${theme}.rasi
} }
# Confirmation CMD # Confirmation CMD
confirm_cmd() { confirm_cmd() {
rofi -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 250px;}' \ rofi -theme-str 'window {location: center; anchor: center; fullscreen: false; width: 250px;}' \
-theme-str 'mainbox {children: [ "message", "listview" ];}' \ -theme-str 'mainbox {children: [ "message", "listview" ];}' \
-theme-str 'listview {columns: 2; lines: 1;}' \ -theme-str 'listview {columns: 2; lines: 1;}' \
-theme-str 'element-text {horizontal-align: 0.5;}' \ -theme-str 'element-text {horizontal-align: 0.5;}' \
-theme-str 'textbox {horizontal-align: 0.5;}' \ -theme-str 'textbox {horizontal-align: 0.5;}' \
-dmenu \ -dmenu \
-p 'Confirmation' \ -p 'Confirmation' \
-mesg 'Are you Sure?' \ -mesg 'Are you Sure?' \
-theme ${dir}/${theme}.rasi -theme ${dir}/${theme}.rasi
} }
# Ask for confirmation # Ask for confirmation
confirm_exit() { confirm_exit() {
echo -e "$yes\n$no" | confirm_cmd echo -e "$yes\n$no" | confirm_cmd
} }
# Pass variables to rofi dmenu # Pass variables to rofi dmenu
run_rofi() { run_rofi() {
echo -e "$lock\n$suspend\n$logout\n$reboot\n$shutdown" | rofi_cmd echo -e "$lock\n$suspend\n$hibernate\n$reboot\n$shutdown\n$hybrid\n$susbernate\n$logout" | rofi_cmd
} }
# Execute Command # Execute Command
run_cmd() { run_cmd() {
selected="$(confirm_exit)" selected="$(confirm_exit)"
if [[ "$selected" == "$yes" ]]; then if [[ "$selected" == "$yes" ]]; then
if [[ $1 == '--shutdown' ]]; then if [[ $1 == '--shutdown' ]]; then
systemctl poweroff systemctl poweroff
elif [[ $1 == '--reboot' ]]; then elif [[ $1 == '--reboot' ]]; then
systemctl reboot systemctl reboot
elif [[ $1 == '--suspend' ]]; then elif [[ $1 == '--suspend' ]]; then
mpc -q pause mpc -q pause
amixer set Master mute amixer set Master mute
systemctl suspend systemctl suspend
elif [[ $1 == '--logout' ]]; then elif [[ $1 == '--hibernate' ]]; then
if [[ "$DESKTOP_SESSION" == 'openbox' ]]; then systemctl hibernate
openbox --exit elif [[ $1 == '--hybrid' ]]; then
elif [[ "$DESKTOP_SESSION" == 'bspwm' ]]; then systemctl hybrid-sleep
bspc quit elif [[ $1 == '--susbernate' ]]; then
elif [[ "$DESKTOP_SESSION" == 'i3' ]]; then systemctl suspend-then-hibernate
i3-msg exit elif [[ $1 == '--logout ' ]]; then
elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then if [[ "$DESKTOP_SESSION" == 'openbox' ]]; then
qdbus org.kde.ksmserver /KSMServer logout 0 0 0 openbox --exit
elif [[ "$DESKTOP_SESSION" == 'hyprland' ]]; then elif [[ "$DESKTOP_SESSION" == 'bspwm' ]]; then
hyprctl dispatch exit bspc quit
fi elif [[ "$DESKTOP_SESSION" == 'i3' ]]; then
fi i3-msg exit
else elif [[ "$DESKTOP_SESSION" == 'plasma' ]]; then
exit 0 qdbus org.kde.ksmserver /KSMServer logout 0 0 0
fi elif [[ "$DESKTOP_SESSION" == 'hyprland' ]]; then
hyprctl dispatch exit
fi
fi
else
exit 0
fi
} }
# Actions # Actions
chosen="$(run_rofi)" chosen="$(run_rofi)"
case ${chosen} in case ${chosen} in
$shutdown) $shutdown)
run_cmd --shutdown run_cmd --shutdown
;; ;;
$reboot) $reboot)
run_cmd --reboot run_cmd --reboot
;; ;;
$lock) $lock)
if [[ -x '/usr/bin/betterlockscreen' ]]; then if [[ -x '/usr/bin/betterlockscreen' ]]; then
betterlockscreen -l betterlockscreen -l
elif [[ -x '/usr/bin/i3lock' ]]; then elif [[ -x '/usr/bin/i3lock' ]]; then
i3lock i3lock
elif [[ -x '/usr/bin/hyprlock' ]]; then elif [[ -x '/usr/bin/hyprlock' ]]; then
hyprlock hyprlock
fi fi
;; ;;
$suspend) $suspend)
run_cmd --suspend run_cmd --suspend
;; ;;
$logout) $hibernate)
run_cmd --logout run_cmd --hibernate
;; ;;
$hybrid)
run_cmd --hybrid
;;
$susbernate)
run_cmd --susbernate
;;
$logout)
run_cmd --logout
;;
esac esac