2016-12-10 14:31:18 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Displays the brightness of a display
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* brightness.step: The amount of increase/decrease on scroll in % (defaults to 2)
|
2017-06-26 12:31:44 +02:00
|
|
|
* brightness.device_path: The device path (defaults to /sys/class/backlight/intel_backlight)
|
2017-01-05 04:55:14 +01:00
|
|
|
|
2016-12-10 14:31:18 +01:00
|
|
|
"""
|
|
|
|
|
2018-11-24 10:56:27 +01:00
|
|
|
import bumblebee.util
|
2016-12-10 14:31:18 +01:00
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.brightness)
|
|
|
|
)
|
|
|
|
self._brightness = 0
|
|
|
|
|
2017-06-26 12:31:44 +02:00
|
|
|
self._device_path = self.parameter("device_path", "/sys/class/backlight/intel_backlight")
|
2016-12-10 14:31:18 +01:00
|
|
|
step = self.parameter("step", 2)
|
|
|
|
|
2018-11-24 10:56:27 +01:00
|
|
|
if bumblebee.util.which("light"):
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP,
|
|
|
|
cmd="light -A {}%".format(step))
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN,
|
|
|
|
cmd="light -U {}%".format(step))
|
2019-06-14 12:04:36 +02:00
|
|
|
elif bumblebee.util.which("brightnessctl"):
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP,
|
|
|
|
cmd="brightnessctl s {}%+".format(step))
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN,
|
|
|
|
cmd="brightnessctl s {}%-".format(step))
|
2018-11-24 10:56:27 +01:00
|
|
|
else:
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP,
|
|
|
|
cmd="xbacklight +{}%".format(step))
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN,
|
|
|
|
cmd="xbacklight -{}%".format(step))
|
2016-12-10 14:31:18 +01:00
|
|
|
|
2016-12-11 11:37:24 +01:00
|
|
|
def brightness(self, widget):
|
2017-06-26 12:31:44 +02:00
|
|
|
if isinstance(self._brightness, float):
|
2018-01-31 21:52:16 +01:00
|
|
|
return "{:3.0f}%".format(self._brightness).strip()
|
2017-06-26 12:31:44 +02:00
|
|
|
else:
|
|
|
|
return "n/a"
|
2016-12-10 14:31:18 +01:00
|
|
|
|
|
|
|
def update(self, widgets):
|
2017-06-26 12:31:44 +02:00
|
|
|
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())
|
2017-10-13 17:06:18 +02:00
|
|
|
self._brightness = float(backlight*100/max_brightness)
|
2017-06-26 12:31:44 +02:00
|
|
|
except:
|
|
|
|
return "Error"
|
2016-12-10 14:31:18 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|