From 3ee805f85566e4e9670ef7a487dd7ec5a9a1eb52 Mon Sep 17 00:00:00 2001 From: Braydon Kains Date: Sat, 9 Sep 2023 09:47:14 -0400 Subject: [PATCH] sway config better and locking screen --- sway/config | 12 +++++++----- sway_manual_lock | 41 +++++++++++++++++++++++++++++++++++++++++ sway_setup.sh | 2 ++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100755 sway_manual_lock diff --git a/sway/config b/sway/config index aa6e295..293eb21 100644 --- a/sway/config +++ b/sway/config @@ -15,6 +15,8 @@ set $up k set $right l # Your preferred terminal emulator set $term foot +# Locker +set $locker sway_manual_lock # Your preferred application launcher # Note: pass the final command to swaymsg so that the resulting window can be opened # on the original workspace that the command was run on. @@ -236,13 +238,13 @@ bindsym XF86AudioPlay exec playerctl play-pause bindsym XF86AudioNext exec playerctl next bindsym XF86AudioPrev exec playerctl previous +# manually lock with mod+l +bindsym $mod+Ctrl+l exec $locker + # Turn off screen at 4 minutes, lock at 5 minutes. exec swayidle -w \ + before-sleep 'playerctl pause' \ timeout 300 '$locker' \ - timeout 240 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \ - before-sleep '$locker' - -# manually lock with mod+l -bindsym $mod+x exec --no-startup-id $locker + timeout 15 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' include /etc/sway/config.d/* diff --git a/sway_manual_lock b/sway_manual_lock new file mode 100755 index 0000000..9651b7e --- /dev/null +++ b/sway_manual_lock @@ -0,0 +1,41 @@ +#!/bin/sh + +### +# way_lock +# Lock Wayland session +# +# Run-Depends +# x11/swayidle +# x11/swaylock +# {any /bin/sh capable of background execution} +# +# Note: swayidle implements KDE's idle protocol[1], so the compositor +# acting as a window manager must support it. Swayidle will not +# work as intended otherwise. +# [1] https://github.com/swaywm/sway/blob/57d6f6f19e3088dcb8e202acade8c39a80075b4a/protocols/idle.xml +### + +# Number of seconds before screen turns off +timeout=10 + +# Turn screen off after $timeout seconds of inactivity. +# Turn it on again when there is activity. +# +# swayidle acts like a daemon, meaning it continues execution even after +# the script is terminated, so we need to execute it in the background +# to be able to terminate it later (unless you like your screen turning +# off every 10 seconds for some reason?) +swayidle \ + timeout $timeout 'swaymsg output \* dpms off' \ + resume 'swaymsg output \* dpms on' \ + & + +playerctl play-pause + +# Lock the screen and wait for it to be unlocked. +swaylock -f -e -c 1d2021 --inside-color 000000b3 -s fill -i ~/.cache/lockscreen + +# Screen unlocked: terminate swayidle and clean up PID +kill -TERM $! +wait + diff --git a/sway_setup.sh b/sway_setup.sh index 7833a7f..abd0457 100644 --- a/sway_setup.sh +++ b/sway_setup.sh @@ -1,3 +1,5 @@ #!/usr/bin/env bash ln -s $(pwd)/sway ~/.config +sudo ln -s sway_manual_lock /usr/bin +