Better power menu handle

This commit is contained in:
Filippo Berto 2023-06-21 14:51:14 +02:00
parent ea23ad8fbf
commit 8c940dec07
No known key found for this signature in database
GPG key ID: FE98AE5EC52B1056
3 changed files with 31 additions and 70 deletions

View file

@ -44,20 +44,9 @@ let
-u true ${playerStatusSrc} &
wait
'';
confirm_command = { cmd, title ? null, text ? null, image ? null }:
lib.concatStringsSep " " [
"${pkgs.yad}/bin/yad --question --center --on-top --sticky --timeout=30 --timeout-indicator=bottom"
(if title == null then "" else ''--title "${title}"'')
(if image == null then "" else ''--image "${image}"'')
(if text == null then "" else ''--text "${text}"'')
"&& ${cmd}"
];
systemctl = "${pkgs.systemd}/bin/systemctl";
loginctl = "${pkgs.systemd}/bin/loginctl";
shutdown = "${pkgs.systemd}/bin/shutdown";
logout = pkgs.writeShellScript "logout" ''
session=`${loginctl} session-status | ${pkgs.coreutils}/bin/head -n 1 | ${pkgs.gawk}/bin/awk '{print $1}'`
${loginctl} terminate-session $session
powermenu = pkgs.writeShellScript "powermenu" ''
PATH=$PATH:"${lib.makeBinPath [ pkgs.rofi pkgs.rofi-power-menu pkgs.zsh ]}"
zsh -c 'rofi -show menu -modi "menu:rofi-power-menu --choices=shutdown/reboot/hibernate/logout"'
'';
colors = with pkgs.lib.nix-rice;
let alpha = 255 * opacity;
@ -295,37 +284,12 @@ in
type = "internal/temperature";
warn.temperature = "90";
};
"module/powermenu" = {
type = "custom/menu";
expand.right = true;
format.spacing = 1;
label = {
open = recursiveUpdate colors.normal { text = ""; };
close = recursiveUpdate colors.normal { text = ""; };
};
menu = [
[
{
text = "󰍃";
exec = confirm_command { cmd = logout; title = "Logout"; text = "Do you want to logout?"; };
}
{
text = "󰜉";
exec = confirm_command { cmd = "${systemctl} reboot"; title = "Reboot"; text = "Do you want to reboot?"; };
}
{
text = "";
exec = confirm_command { cmd = "${systemctl} hibernate"; title = "Hibernate"; text = "Do you want to hibernate?"; };
}
{
text = "";
exec = confirm_command { cmd = "${shutdown} now"; title = "Shutdown"; text = "Do you want to shutdown?"; };
}
]
];
type = "custom/script";
format = recursiveUpdate colors.normal { padding = 0; };
exec = "echo ";
click.left = "${powermenu}";
};
"module/notifications" = {
type = "custom/script";
format = recursiveUpdate colors.normal { padding = 0; };

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: {
{ pkgs, lib, ... }: {
imports = [
./nautilus.nix
# ./thunar.nix
@ -40,14 +40,17 @@
level=`printf "%.0f" $(${xbacklight} -get)`
${notify} -r 2 -h "int:value:$level" "Luminosità $level"
'';
powermenu = pkgs.writeShellScript "powermenu" ''
PATH=$PATH:"${lib.makeBinPath [ pkgs.rofi pkgs.rofi-power-menu ]}"
rofi -show menu -modi "menu:rofi-power-menu --choices=shutdown/reboot/hibernate/logout"
'';
in
{
enable = true;
keybindings = {
"alt + Tab" = "rofi -show window";
"Print" = "${pkgs.gnome.gnome-screenshot}/bin/gnome-screenshot";
"super + alt + {h,j,k,l}" =
"bspc node -z {left -20 0,bottom 0 20,top 0 -20,right 20 0}";
"super + alt + {h,j,k,l}" = "bspc node -z {left -20 0,bottom 0 20,top 0 -20,right 20 0}";
"super + alt + m" = "lockscreen";
"super + alt + p" = "autorandr -c";
"super + alt + shift + p" = "arandr";
@ -56,33 +59,26 @@
'';
"super + alt + o" = "${moveAllNodesToPrimary}";
"super + alt + r" = "${resetBspwm}";
"super + alt + shift + {h,j,k,l}" =
"bspc node -z {right -20 0,top 0 20,bottom 0 -20,left 20 0}";
"super + alt + shift + {h,j,k,l}" = "bspc node -z {right -20 0,top 0 20,bottom 0 -20,left 20 0}";
"super + bracket{left,right}" = "bspc desktop -f {prev,next}.local";
"super + b" = "${pkgs.update-background}/bin/update-background";
"super + ctrl + {1-9}" = "bspc node -o 0.{1-9}";
"super + ctrl + {h,j,k,l}" = "bspc node -p {west,south,north,east}";
"super + ctrl + {m,x,y,z}" =
"bspc node -g {marked,locked,sticky,private}";
"super + ctrl + shift + space" =
"bspc query -N -d | xargs -I id -n 1 bspc node id -p cancel";
"super + ctrl + {m,x,y,z}" = "bspc node -g {marked,locked,sticky,private}";
"super + ctrl + shift + space" = "bspc query -N -d | xargs -I id -n 1 bspc node id -p cancel";
"super + ctrl + space" = "bspc node -p cancel";
"super + e {_,+shift}" = "{${fileManager},${secondaryFileManager}}";
"super + shift + p" = "clipedit";
"super + Escape" = "pkill -USR1 -x sxhkd";
"super + g" = "bspc node -s biggest";
"super + {grave,Tab}" = "bspc {node,desktop} -f last";
"super + {h,j,k,l}" =
"dir={west,south,north,east}; bspc node -f $dir || bspc monitor -f $dir";
"super + {h,j,k,l}" = "dir={west,south,north,east}; bspc node -f $dir || bspc monitor -f $dir";
"super + {Left,Down,Up,Right}" = "bspc node -v {-20 0,0 20,0 -20,20 0}";
"super + m" = "bspc desktop -l next";
"super + n {_, + shift}" = "bsp-layout {next, previous}";
"super + {o,i}" =
"bspc wm -h off;bspc node {older,newer} -f;bspc wm -h on";
"super + {p,b,comma,period}" =
"bspc node -f @{parent,brother,first,second}";
"super + {_,shift + }{1-9,0}" =
"bspc {desktop -f,node -d} 'focused:^{1-9,10}'";
"super + {o,i}" = "bspc wm -h off;bspc node {older,newer} -f;bspc wm -h on";
"super + {p,b,comma,period}" = "bspc node -f @{parent,brother,first,second}";
"super + {_,shift + }{1-9,0}" = "bspc {desktop -f,node -d} 'focused:^{1-9,10}'";
"super + {_,shift + } c" = "bspc node -f {next,prev}.local";
"super + {_,shift + } space" = "rofi -show {drun,run}";
"super + shift + ctrl + d" = "rofi -show ssh";
@ -91,19 +87,15 @@
"super + shift + {h,j,k,l}" = ''
dir={west,south,north,east}; bspc node -s "$dir.local" --follow || bspc node -m "$dir" --follow
'';
"super + {_,shift + } Return" =
"{${primaryTerminal} , ${secondaryTerminal}}";
"super + {_,shift + } Return" = "{${primaryTerminal} , ${secondaryTerminal}}";
"super + {_,shift + } w" = "bspc node -{c,k}";
"super + {t,shift + t,s,f}" =
"bspc node -t {tiled,pseudo_tiled,floating,fullscreen}";
"super + {t,shift + t,s,f}" = "bspc node -t {tiled,pseudo_tiled,floating,fullscreen}";
# "super + y" = "bspc node newest.marked.local -n newest.!automatic.local";
"XF86Audio{LowerVolume,Mute,RaiseVolume}" =
"${pamixer} {-d 2 -u,-t,-i 2 -u} && ${notifyVolume}";
"XF86Audio{LowerVolume,Mute,RaiseVolume}" = "${pamixer} {-d 2 -u,-t,-i 2 -u} && ${notifyVolume}";
"XF86Audio{Next,Play,Prev}" = "${playerctl} {next,play-pause,previous}";
"super + alt + {Right,Down,Left}" =
"${playerctl} {next,play-pause,previous}";
"XF86MonBrightness{Up,Down}" =
" ${xbacklight} -{inc,dec} 10 && ${notifyBrightness}";
"super + alt + {Right,Down,Left}" = "${playerctl} {next,play-pause,previous}";
"XF86MonBrightness{Up,Down}" = "${xbacklight} -{inc,dec} 10 && ${notifyBrightness}";
"XF86PowerOff" = toString powermenu;
};
};
}

View file

@ -89,6 +89,11 @@ with lib; {
];
};
# Disable auto handling of power button
services.logind.extraConfig = ''
HandlePowerKey=ignore
'';
services.keybase.enable = true;
# Enable sound.