Skip to content

Commit

Permalink
backlight module: add brightnessctl support (#2233)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabriF authored Jan 29, 2024
1 parent fa384fc commit df2bac2
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions py3status/modules/backlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(default 4)
cache_timeout: How often we refresh this module in seconds (default 10)
command: The program to use to change the backlight.
Currently xbacklight and light are supported. The program needs
Currently xbacklight, light and brightnessctl are supported. The program needs
to be installed and on your path. If no program is installed, this
module will attempt to use logind support instead
(default 'xbacklight')
Expand All @@ -35,6 +35,7 @@
Requires: one of
xbacklight: need for changing brightness, not detection
light: program to easily change brightness on backlight-controllers
brightnessctl: change brightness wayland compatible
dbus-python + logind v243: logind to change brightness without X
@author Tjaart van der Walt (github:tjaartvdwalt), Jérémy Rosen (github:boucman)
Expand Down Expand Up @@ -62,12 +63,19 @@ def get_device():
commands = {
"xbacklight": {
"get": lambda: ["xbacklight", "-get"],
"get_percent": True,
"set": lambda level: ["xbacklight", "-time", "0", "-set", str(level)],
},
"light": {
"get": lambda: ["light", "-G"],
"get_percent": True,
"set": lambda level: ["light", "-S", str(level)],
},
"brightnessctl": {
"get": lambda: ["brightnessctl", "g"],
"get_percent": False,
"set": lambda level: ["brightnessctl", "s", str(level) + "%"],
},
}


Expand Down Expand Up @@ -160,10 +168,15 @@ def _set_backlight_level(self, level):

def _get_backlight_level(self):
if self.command_available:
return float(self.py3.command_output(self._command_get()))
brightness = int(Path(f"{self.device}/brightness").read_text())
brightness_max = int(Path(f"{self.device}/max_brightness").read_text())
return brightness * 100 / brightness_max
brightness = float(self.py3.command_output(self._command_get()))
else:
brightness = int(Path(f"{self.device}/brightness").read_text())

if not self.command_available or (not commands[self.command]["get_percent"]):
brightness_max = int(Path(f"{self.device}/max_brightness").read_text())
return brightness * 100 / brightness_max
else:
return brightness

# Returns the string array for the command to get the current backlight level
def _command_get(self):
Expand Down

0 comments on commit df2bac2

Please sign in to comment.