-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbd_idle_light
33 lines (26 loc) · 1.31 KB
/
kbd_idle_light
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
dim_time=10 # time to wait before dimming the screen
now_idle=false # flag to indicate if user is currently idle
idle_brightness=0 # dimmed screen brightness to set when idle
brightness_file="/sys/devices/platform/dell-laptop/leds/dell::kbd_backlight/brightness"
cpu_limit=10 # CPU limit, adjust as needed (10 = 10% of system CPU)
# Set the priority of the current script
renice "$cpu_limit" "$$"
while true; do
# Fetch the idle time using gdbus
idle_time=$(gdbus call --session --dest org.gnome.Mutter.IdleMonitor --object-path /org/gnome/Mutter/IdleMonitor/Core --method org.gnome.Mutter.IdleMonitor.GetIdletime | awk '{print $2/1000}')
# Check if user has gone idle
if (( $(awk -v idle="$idle_time" -v time="$dim_time" 'BEGIN{ print (idle >= time) }') )) && [ "$now_idle" = false ]; then
# Save current brightness
brightness_before=$(cat "$brightness_file")
# Dim the screen
echo "$idle_brightness" | tee "$brightness_file"
now_idle=true
# Check if user has become active
elif (( $(awk -v idle="$idle_time" -v time="$dim_time" 'BEGIN{ print (idle < time) }') )) && [ "$now_idle" = true ]; then
# Set brightness to the value before dimming
echo "$brightness_before" | tee "$brightness_file"
now_idle=false
fi
sleep 1
done