1
0
Fork 0
mirror of https://github.com/SeriousBug/dotfiles synced 2025-02-20 05:19:48 -06:00

backlight control

This commit is contained in:
Kaan Barmore-Genç 2022-03-09 22:01:45 -05:00
parent 4248240e55
commit 3b59d9249a
4 changed files with 53 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"python.formatting.provider": "black"
}

44
sway/backlight.py Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env python3
import argparse
from decimal import Clamped
parser = argparse.ArgumentParser(
"backlight.py", description="Adjust backlight levels for intel backlight."
)
# You can either set min or max, or change some amount. Not all.
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument(
"change",
type=int,
nargs="?",
help="The mount, as a percentage, to change the brightness by. Negative numbers lower brightness.",
)
group.add_argument(
"--max", action="store_true", help="Set the brightness to max possible."
)
group.add_argument("--off", action="store_true", help="Set the brightness to 0.")
def backlight(file_name: str) -> str:
return f"/sys/class/backlight/intel_backlight/{file_name}"
args = parser.parse_args()
with open(backlight("max_brightness"), "r") as max_f:
max_brightness = int(max_f.read().strip())
with open(backlight("brightness"), "w+") as current_f:
current_brightness = int(current_f.read().strip())
if args.max:
current_f.write(str(max_brightness))
elif args.off:
current_f.write(str(0))
elif args.change:
percent = int(max_brightness / 100.0)
to = current_brightness + percent * args.change
# Make sure number is in bounds
# Bounding min at 1 to avoid fully shutting down screen without the off option
to = max(min(to, max_brightness), 1)
current_f.write(str(to))
else:
print(int((current_brightness / float(max_brightness)) * 100))

View file

@ -243,6 +243,9 @@ bindsym $mod+c mode "screenshot"
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
# Screen brightness
bindsym XF86MonBrightnessUp exec /home/kaan/.config/sway/backlight.py +5
bindsym XF86MonBrightnessDown exec /home/kaan/.config/sway/backlight.py -5
#
# Resizing containers:

View file

@ -66,6 +66,9 @@
"device": "intel_backlight",
"format": "{percent}% {icon}",
"format-icons": ["", ""],
"on-scroll-up": "/home/kaan/.config/sway/backlight.py +1",
"on-scroll-down": "/home/kaan/.config/sway/backlight.py -1",
"on-click": "/home/kaan/.config/sway/backlight.py --off"
},
"pulseaudio": {
// "scroll-step": 1, // %, can be a float