Dim screen on inactivity, then lock it

This commit is contained in:
Şahin Akkaya 2023-12-27 22:20:05 +03:00
parent 6ed1448668
commit 582418bbee
4 changed files with 54 additions and 2 deletions

View File

@ -32,6 +32,15 @@ monitor=HDMI-A-1,preferred,0x0,1.3
exec-once = dunst
exec-once = /usr/libexec/kf5/polkit-kde-authentication-agent-1
# Dim screen after 60 seconds of inactivity
exec-once = swayidle -w timeout 60 'dim-screen &' resume 'undim-screen'
# Lock screen after idle for 300s
exec-once = swayidle -w timeout 300 'lock-screen'
# Dim screen 5 seconds after screen is locked. no -w option here.
exec-once = swayidle timeout 5 'if pgrep -x swaylock; then dim-screen; fi' resume 'undim-screen'
# Turn monitors off 20 seconds after screen is locked
exec-once = swayidle -w timeout 20 'if pgrep -x swaylock; then hyprctl dispatch dpms off; fi' resume 'hyprctl dispatch dpms on'
# exec-once = /usr/libexec/polkit-gnome-authentication-agent-1
# Source a file (multi-file configs)
@ -219,14 +228,17 @@ bindm = $mainMod, mouse:273, resizewindow
# screen
bindle=,XF86MonBrightnessUp, exec, light -A 5
bindle=,XF86MonBrightnessDown, exec, light -U 5
bindle=,XF86MonBrightnessUp, exec, light -A 3; light -O
bindle=,XF86MonBrightnessDown, exec, light -U 3; light -O
# bindle=,XF86KbdBrightnessUp, exec, ags -r 'brightness.kbd++; indicator.kbd()'
# bindle=,XF86KbdBrightnessDown, exec, ags -r 'brightness.kbd--; indicator.kbd()'
#
#
bindle=,XF86AudioRaiseVolume, exec, volume up
bindle=,XF86AudioLowerVolume, exec, volume down
bindle=,XF86AudioMute, exec, volume toggle-mute
bind = $mainMod SHIFT, q, exec, lock-screen
# bindl = $mainMod SHIFT, L, exec, sleep 1 && hyprctl dispatch dpms off
windowrulev2 = stayfocused,class:(wofi)

30
scripts/dim-screen Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/python3
# Gradually decrease brightness level. Thanks ChatGPT
import subprocess
import time
def set_brightness(brightness):
subprocess.call(['light', '-S', str(brightness)])
def smooth_dimming(initial_brightness, final_brightness, duration, steps):
brightness_step = (initial_brightness - final_brightness) / steps
sleep_time = duration / steps
for i in range(steps + 1):
current_brightness = round(initial_brightness - i * brightness_step,2)
set_brightness(current_brightness)
print(current_brightness)
time.sleep(sleep_time)
set_brightness(final_brightness)
# Save brighness value for later
subprocess.call(['light', '-O'])
initial_brightness = float(subprocess.getoutput('light'))
final_brightness = 0 if initial_brightness < 20 else 5
dimming_duration = 0.3 if initial_brightness < 20 else .5
num_steps = 20 if initial_brightness < 20 else 50
smooth_dimming(initial_brightness, final_brightness, dimming_duration, num_steps)

3
scripts/lock-screen Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
swaylock -f

7
scripts/undim-screen Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if pid=$(pgrep -x "dim-screen"); then
kill $pid
fi
light -I