{ pkgs, lib, config, ... }: let # lockColors = with config.lib.stylix.colors.withHashtag; { a = base00; b = base01; d = base00; }; # Black or White, depending on current theme # lockColors = with config.lib.stylix.colors.withHashtag; { a = base0A; b = base0B; d = base00; }; # Green + Yellow lockColors = { a = "#82a401"; b = "#466c01"; d = "#648901"; }; # Old lockSvg = pkgs.writeText "lock.svg" '' ''; lockPng = pkgs.runCommand "lock.png" { } "${pkgs.imagemagick}/bin/convert ${lockSvg} $out"; mod = config.wayland.windowManager.sway.config.modifier; idleTime = 10; # minutes # Like wayidle but exit when there is activity wayresume = pkgs.wayidle.overrideAttrs (old: { pname = "wayresume"; patches = (old.patches or [ ]) ++ [ ./wayresume.diff ]; }); powerScreen = state: ''${config.wayland.windowManager.sway.package}/bin/swaymsg "output * power ${state}"''; in { # Can't use loginctl lock-session, auto-opened session has type greeter, even without that it couldn't figure it out config = lib.mkIf config.frogeye.desktop.xorg { programs.swaylock = { enable = true; settings = { color = (builtins.substring 1 6 lockColors.d); image = lockPng; tiling = true; ignore-empty-password = true; indicator-idle-visible = false; show-failed-attempts = true; indicator-radius = 100; }; }; services.swayidle = { enable = true; timeouts = [ { # Warn timeout = (idleTime - 1) * 60; command = ''${lib.getExe pkgs.libnotify} "Screen turns off in 1 minute"''; } { # Screen off timeout = idleTime * 60; command = powerScreen "off"; resumeCommand = powerScreen "on"; } { # Lock # Call swaylock, but also call another swayidle so screen is turned off after 10 seconds instead of minutes timeout = (idleTime + 1) * 60; command = "${pkgs.writeShellScript "lock" '' ${config.frogeye.hooks.lock} ${lib.getExe config.services.swayidle.package} timeout 10 ${lib.strings.escapeShellArg (powerScreen "off")} resume ${lib.strings.escapeShellArg (powerScreen "on")} & si=$! revert() { kill $si } trap revert 0 ${lib.getExe config.programs.swaylock.package} ''}"; } ]; }; stylix.targets.swaylock.enable = false; wayland.windowManager.sway.config.keybindings = lib.mkOptionDefault { # Turn screen off until activity "${mod}+F1" = ''--release exec ${powerScreen "off"} && ${lib.getExe wayresume} -t0; ${powerScreen "on"}''; # Toggle to save on buttons # TODO Bar indicator "${mod}+F5" = "exec --no-startup-id ${pkgs.writeShellScript "swayidle-toggle" '' if ${pkgs.systemd}/bin/systemctl --user is-active swayidle --quiet then ${pkgs.systemd}/bin/systemctl --user stop swayidle else ${pkgs.systemd}/bin/systemctl --user start swayidle fi ''}"; }; }; }