dotfiles/modules/nixos/graphical/rofi/power.nix

64 lines
1.4 KiB
Nix
Raw Permalink Normal View History

2023-04-02 16:25:33 +00:00
{ config, pkgs, ... }:
let
rofi = config.home-manager.users.${config.user}.programs.rofi.finalPackage;
in {
# Adapted from:
# https://gitlab.com/vahnrr/rofi-menus/-/blob/b1f0e8a676eda5552e27ef631b0d43e660b23b8e/scripts/rofi-power
# A rofi powered menu to execute power related action.
config.powerCommand = builtins.toString (pkgs.writeShellScript "powermenu" ''
power_off=''
reboot=''
lock=''
suspend='󰒲'
2023-04-02 16:25:33 +00:00
log_out=''
chosen=$(printf '%s;%s;%s;%s;%s\n' \
"$power_off" \
"$reboot" \
"$lock" \
"$suspend" \
"$log_out" \
| ${rofi}/bin/rofi \
2023-04-02 19:52:45 +00:00
-theme-str '@import "power.rasi"' \
-hover-select \
2023-08-06 22:06:50 +00:00
-me-select-entry "" \
2023-04-02 19:52:45 +00:00
-me-accept-entry MousePrimary \
2023-04-02 16:25:33 +00:00
-dmenu \
-sep ';' \
-selected-row 2)
confirm () {
${builtins.readFile ./rofi-prompt.sh}
}
2023-04-02 16:25:33 +00:00
case "$chosen" in
"$power_off")
confirm 'Shutdown?' && doas shutdown now
2023-04-02 16:25:33 +00:00
;;
"$reboot")
confirm 'Reboot?' && doas reboot
2023-04-02 16:25:33 +00:00
;;
"$lock")
${pkgs.betterlockscreen}/bin/betterlockscreen --lock --display 1 --blur 0.5 --span
;;
"$suspend")
systemctl suspend
;;
"$log_out")
confirm 'Logout?' && i3-msg exit
2023-04-02 16:25:33 +00:00
;;
*) exit 1 ;;
esac
'');
}