From 7a081f4dd3782f7a3297d75d614e72eed3eef286 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 23 Oct 2016 18:19:37 -0200 Subject: [PATCH] Glob expansion in backlight Using default settings ("*"), this will match any device found in backlight. Fix #442. --- i3pystatus/backlight.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/i3pystatus/backlight.py b/i3pystatus/backlight.py index 6622b5c..08ab4e0 100644 --- a/i3pystatus/backlight.py +++ b/i3pystatus/backlight.py @@ -1,6 +1,7 @@ from i3pystatus.file import File from i3pystatus import Module from i3pystatus.core.command import run_through_shell +import glob import shutil @@ -19,12 +20,14 @@ class Backlight(File): settings = ( ("format", "format string, formatters: brightness, max_brightness, percentage"), - ("backlight", "backlight, see `/sys/class/backlight/`"), + ("backlight", + "backlight, see `/sys/class/backlight/`. Supports glob expansion, i.e. `*` matches anything. " + "If it matches more than one filename, selects the first one in alphabetical order"), "color", ) required = () - backlight = "acpi_video0" + backlight = "*" format = "{brightness}/{max_brightness}" base_path = "/sys/class/backlight/{backlight}/" @@ -40,6 +43,7 @@ class Backlight(File): def init(self): self.base_path = self.base_path.format(backlight=self.backlight) + self.base_path = sorted(glob.glob(self.base_path))[0] self.has_xbacklight = shutil.which("xbacklight") is not None # xbacklight expects a percentage as parameter. Calculate the percentage