how to automatically turn off screen after lock screen via swaylock
Sharelter opened this issue · 3 comments
I want let all my screen off after lock my screen via sway lock
I followed archwiki and found this thing like below
To turn off a locked screen much sooner e.g. after 10 seconds, grep the process list for your locking manager and execute swaymsg "output * dpms off" accordingly like so:
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'
Here is my config swayidle config section in ~/.config/sway/config
### Idle configuration
exec swayidle -w \
timeout 315 'swaymsg "output * dpms off"' \
timeout 300 'swaylock -f' \
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi' \
before-sleep 'playerctl pause' \
before-sleep 'swaylock' \
resume 'swaymsg "output * dpms on"'
### Lock screen use Mod + L
bindsym $mod+l exec --no-startup-id swaylock -f
I thought that config this way will automatically detect whether swaylock is running after idle 10 seconds, if swaylock is running, it will turn off the screen.
But on my laptop, It could not automatically turn off screen after I use Mod + L shortcut to manually lock screen.
Are there any suggestions ?
Your swayidle command isn't valid. Run it in a command line to see the error, and refer to the swayidle manpage.
THX . I type it into the shell and the shell told me some error about resume argument.
I finally realized that the arrangement of each swayidle argument matters.
I put the resume up the before-sleep and no error message was generated.
if I arrange the timeout 300
after the timeout 10
like this
### Idle configuration
exec swayidle -w \
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi' \
timeout 300 'swaylock -f' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'playerctl pause' \
before-sleep 'swaylock' \
It will automatically turn off the screen after 10 seconds but cannot resume (turn on screen when hit any key on the keyboard)
Now my config looks like this
### Idle configuration
exec swayidle -w \
timeout 300 'swaylock -f' \
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'playerctl pause' \
before-sleep 'swaylock' \
Everything works fine now.
I added another swayidle command and swayidle works perfect for me now :)
Here is my final config
### Idle configuration #1 For manually lock the screen via Mod + L
exec swayidle -w \
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'playerctl pause' \
before-sleep 'swaylock' \
# This will turn off your displays after 10 seconds when the screen is locked, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
### Idle configuration #2 For lock the screen and turn off display after idle sometime
exec swayidle -w \
timeout 300 'swaylock -f' \
timeout 310 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'playerctl pause' \
before-sleep 'swaylock' \
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 10 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.