From 431ab4e49cfc9bdb049257c3c0b3d1b698c758fd Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Thu, 9 Apr 2026 21:27:18 +0200 Subject: [PATCH] feat: nb make swayidle to a toggle --- hosts/nb/modules/sway/sway.conf | 10 ++------- hosts/nb/modules/sway/sway.nix | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/hosts/nb/modules/sway/sway.conf b/hosts/nb/modules/sway/sway.conf index f0976ae..c953990 100644 --- a/hosts/nb/modules/sway/sway.conf +++ b/hosts/nb/modules/sway/sway.conf @@ -212,7 +212,7 @@ bindsym $mod+Shift+c reload bindsym $mod+Shift+r restart # manage i3 session -bindsym $mod+Shift+e exec swaynag --background f1fa8c --border ffb86c --border-bottom-size 0 --button-background ffb86c --button-text 282a36 -t warning -f "pango:Hack 9" -m "Do you really want to exit?" -B "  Auto Suspend Off " "pkill swayidle" -B "  Exit " "swaymsg exit" -B "  Lock " "pkill swaynag && swaylock -c 252525 -s center -i ~/.wallpaper.png" -B "  Reboot " "pkill swaynag && reboot" -B "  Shutdown " "pkill swaynag && shutdown -h now" -B " Suspend " "pkill swaynag && systemctl suspend" +bindsym $mod+Shift+e exec session-menu # resize window bindsym $mod+r mode "  " @@ -299,13 +299,7 @@ exec thunderbird exec firefox exec nextcloud exec cryptomator -exec swayidle \ - before-sleep 'loginctl lock-session $XDG_SESSION_ID' \ - lock 'swaylock -c 252525 -s center -i ~/.wallpaper.png' \ - timeout 120 'light -O && light -S 10' \ - resume 'light -I' \ - timeout 180 'swaylock -c 252525 -s center -i ~/.wallpaper.png' \ - timeout 600 'systemctl suspend' +exec toggle-swayidle exec dunst #exec --no-startup-id swaybg -c "#000000" -m fill -i ~/.config/wallpaper/wot.jpg # exec --no-startup-id gnome-keyring-daemon --start --components=pkcs11,secrets,ssh diff --git a/hosts/nb/modules/sway/sway.nix b/hosts/nb/modules/sway/sway.nix index 3198322..afc09e5 100644 --- a/hosts/nb/modules/sway/sway.nix +++ b/hosts/nb/modules/sway/sway.nix @@ -72,6 +72,40 @@ let fi ''; + toggle-swayidle = pkgs.writeShellScriptBin "toggle-swayidle" '' + if pgrep -x swayidle >/dev/null; then + pkill -x swayidle + else + swayidle \ + before-sleep 'loginctl lock-session $XDG_SESSION_ID' \ + lock 'swaylock -c 252525 -s center -i ~/.wallpaper.png' \ + timeout 120 'light -O && light -S 10' \ + resume 'light -I' \ + timeout 180 'swaylock -c 252525 -s center -i ~/.wallpaper.png' \ + timeout 600 'systemctl suspend' & + disown + fi + ''; + + session-menu = pkgs.writeShellScriptBin "session-menu" '' + if pgrep -x swayidle >/dev/null; then + suspend_label="Auto Suspend Off" + else + suspend_label="Auto Suspend On" + fi + + swaynag \ + --background f1fa8c --border ffb86c --border-bottom-size 0 \ + --button-background ffb86c --button-text 282a36 \ + -t warning -f "pango:Hack 9" \ + -m "Do you really want to exit?" \ + -B " $suspend_label " "pkill swaynag; toggle-swayidle" \ + -B " Exit " "swaymsg exit" \ + -B " Lock " "pkill swaynag && swaylock -c 252525 -s center -i ~/.wallpaper.png" \ + -B " Reboot " "pkill swaynag && reboot" \ + -B " Shutdown " "pkill swaynag && shutdown -h now" \ + -B " Suspend " "pkill swaynag && systemctl suspend" + ''; sway-conf = builtins.readFile ./sway.conf + '' exec swaybg -m center -c 252525 -i ~/.wallpaper.png @@ -88,6 +122,8 @@ in { wayland wofi battery-alert-swaynag + toggle-swayidle + session-menu ]; programs.sway = {