sway
This commit is contained in:
parent
492f085d52
commit
bb021a1aae
30 changed files with 487 additions and 573 deletions
|
@ -19,68 +19,77 @@ let
|
|||
</svg>
|
||||
'';
|
||||
lockPng = pkgs.runCommand "lock.png" { } "${pkgs.imagemagick}/bin/convert ${lockSvg} $out";
|
||||
mod = config.xsession.windowManager.i3.config.modifier;
|
||||
xautolockState = "${config.xdg.cacheHome}/xautolock";
|
||||
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 {
|
||||
home.packages = [
|
||||
(pkgs.writeShellApplication {
|
||||
name = "xlock";
|
||||
text = ''
|
||||
${config.frogeye.hooks.lock}
|
||||
# TODO Reevaluate whether we want this or not
|
||||
if ! ${pkgs.lightdm}/bin/dm-tool lock
|
||||
then
|
||||
if [ -d ${config.xdg.cacheHome}/lockpatterns ]
|
||||
then
|
||||
pattern=$(${pkgs.findutils} ${config.xdg.cacheHome}/lockpatterns | sort -R | head -1)
|
||||
else
|
||||
pattern=${lockPng}
|
||||
fi
|
||||
revert() {
|
||||
${pkgs.xorg.xset}/bin/xset dpms 0 0 0
|
||||
}
|
||||
trap revert SIGHUP SIGINT SIGTERM
|
||||
${pkgs.xorg.xset}/bin/xset dpms 5 5 5
|
||||
${pkgs.i3lock}/bin/i3lock --nofork --color ${
|
||||
builtins.substring 1 6 lockColors.d
|
||||
} --image="$pattern" --tiling --ignore-empty-password
|
||||
revert
|
||||
fi
|
||||
'';
|
||||
})
|
||||
];
|
||||
xsession.windowManager.i3.config = {
|
||||
keybindings = {
|
||||
# Screen off commands
|
||||
"${mod}+F1" = "--release exec --no-startup-id ${pkgs.xorg.xset}/bin/xset dpms force off";
|
||||
# Toggle to save on buttons
|
||||
# xautolock -toggle doesn't allow to read state.
|
||||
# Writing into a file also allows frobar to display a lock icon
|
||||
"${mod}+F5" = "exec --no-startup-id ${pkgs.writeShellScript "xautolock-toggle" ''
|
||||
state="$(cat "${xautolockState}")"
|
||||
if [ "$state" = "disabled" ]
|
||||
then
|
||||
${pkgs.xautolock}/bin/xautolock -enable
|
||||
echo enabled > ${xautolockState}
|
||||
else
|
||||
${pkgs.xautolock}/bin/xautolock -disable
|
||||
echo disabled > ${xautolockState}
|
||||
fi
|
||||
''}";
|
||||
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;
|
||||
};
|
||||
startup = [
|
||||
# Stop screen after 10 minutes, 1 minutes after lock it
|
||||
};
|
||||
services.swayidle = {
|
||||
enable = true;
|
||||
timeouts = [
|
||||
{
|
||||
notification = false;
|
||||
command = "${pkgs.writeShellScript "xautolock-start" ''
|
||||
echo enabled > ${xautolockState}
|
||||
${pkgs.xautolock}/bin/xautolock -time 10 -locker '${pkgs.xorg.xset}/bin/xset dpms force standby' -killtime 1 -killer xlock
|
||||
# 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}
|
||||
''}";
|
||||
}
|
||||
# services.screen-locker.xautolock is hardcoded to use systemd for -locker (doesn't even work...)
|
||||
];
|
||||
};
|
||||
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
|
||||
''}";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
14
hm/desktop/lock/wayresume.diff
Normal file
14
hm/desktop/lock/wayresume.diff
Normal file
|
@ -0,0 +1,14 @@
|
|||
diff --git a/src/main.rs b/src/main.rs
|
||||
index 85930bd..586ee55 100644
|
||||
--- a/src/main.rs
|
||||
+++ b/src/main.rs
|
||||
@@ -110,7 +110,7 @@ impl SeatHandler for State {
|
||||
}
|
||||
|
||||
fn notification_cb(ctx: EventCtx<State, ExtIdleNotificationV1>) {
|
||||
- if let ext_idle_notification_v1::Event::Idled = ctx.event {
|
||||
+ if let ext_idle_notification_v1::Event::Resumed = ctx.event {
|
||||
ctx.state.exit = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue