From 11f86b75c8139055c10c6a5837a0fb757bd8c677 Mon Sep 17 00:00:00 2001 From: jmg5e Date: Mon, 26 Jun 2017 05:31:44 -0500 Subject: [PATCH] removed xbacklight dependency for brightness module --- README.md | 1 - bumblebee/modules/brightness.py | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fa6ac70..6054b4d 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,6 @@ Modules and commandline utilities are only required for modules, the core itself # Required commandline utilities -* xbacklight (for the module 'brightness') * xset (for the module 'caffeine') * notify-send (for the module 'caffeine') * cmus-remote (for the module 'cmus') diff --git a/bumblebee/modules/brightness.py b/bumblebee/modules/brightness.py index 716a734..e61be7e 100644 --- a/bumblebee/modules/brightness.py +++ b/bumblebee/modules/brightness.py @@ -2,11 +2,9 @@ """Displays the brightness of a display -Requires the following executable: - * xbacklight - Parameters: * brightness.step: The amount of increase/decrease on scroll in % (defaults to 2) + * brightness.device_path: The device path (defaults to /sys/class/backlight/intel_backlight) """ @@ -21,6 +19,7 @@ class Module(bumblebee.engine.Module): ) self._brightness = 0 + self._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight") step = self.parameter("step", 2) engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, @@ -29,9 +28,19 @@ class Module(bumblebee.engine.Module): cmd="xbacklight -{}%".format(step)) def brightness(self, widget): - return "{:03.0f}%".format(self._brightness) + if isinstance(self._brightness, float): + return "{:03.0f}%".format(self._brightness) + else: + return "n/a" def update(self, widgets): - self._brightness = float(bumblebee.util.execute("xbacklight -get")) + try: + with open("{}/brightness".format(self._device_path)) as f: + backlight = int(f.readline()) + with open("{}/max_brightness".format(self._device_path)) as f: + max_brightness = int(f.readline()) + self._brightness=float(backlight*100/max_brightness) + except: + return "Error" # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4