mirror of
https://github.com/sahinakkaya/dotfiles.git
synced 2024-11-24 01:19:36 +01:00
42 lines
1.3 KiB
Python
Executable File
42 lines
1.3 KiB
Python
Executable File
#!/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'))
|
|
if initial_brightness < 20:
|
|
final_brightness = max(0, initial_brightness - 10)
|
|
elif initial_brightness < 40:
|
|
final_brightness = max(10, initial_brightness - 20)
|
|
elif initial_brightness < 60:
|
|
final_brightness = max(30, initial_brightness - 30)
|
|
elif initial_brightness < 80:
|
|
final_brightness = max(40, initial_brightness - 40)
|
|
elif initial_brightness < 100:
|
|
final_brightness = max(50, initial_brightness - 50)
|
|
|
|
|
|
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)
|