Write these as root first:
Then this is the python program I made. Just run it with python3 main.py
Code:
chmod 666 /dev/backlight/*
echo 'devfs_system_ruleset="localrules"' >> /etc/rc.conf
service devfs restart
pkg install python3 gtk3
Then this is the python program I made. Just run it with python3 main.py
Code:
import gi
import subprocess
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class BacklightAdjuster(Gtk.Window):
def __init__(self):
super().__init__(title="Backlight Controller")
self.set_border_width(20)
self.set_default_size(300, 100)
self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.add(self.box)
self.label = Gtk.Label(label="Adjust Brightness:")
self.box.pack_start(self.label, False, False, 5)
self.scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1, 100, 1)
self.scale.set_value(self.get_current_brightness())
self.scale.set_hexpand(True)
self.scale.connect("value-changed", self.on_value_changed)
self.box.pack_start(self.scale, True, True, 5)
def get_current_brightness(self):
try:
result = subprocess.run(["backlight"], capture_output=True, text=True)
return int(result.stdout.strip())
except Exception:
return 50 # Default to 50 if there's an issue
def on_value_changed(self, scale):
value = int(scale.get_value())
subprocess.run(["backlight", str(value)])
if __name__ == "__main__":
app = BacklightAdjuster()
app.connect("destroy", Gtk.main_quit)
app.show_all()
Gtk.main()