2016-11-07 22:00:02 +01:00
|
|
|
import bumblebee.module
|
|
|
|
|
|
|
|
def description():
|
|
|
|
return "Displays brightness percentage"
|
|
|
|
|
2016-11-09 19:37:09 +01:00
|
|
|
def parameters():
|
|
|
|
return [
|
|
|
|
"brightness.step: Steps (in percent) to increase/decrease brightness on scroll (defaults to 2)",
|
|
|
|
]
|
|
|
|
|
2016-11-07 22:00:02 +01:00
|
|
|
class Module(bumblebee.module.Module):
|
2016-12-02 18:53:34 +01:00
|
|
|
def __init__(self, output, config):
|
|
|
|
super(Module, self).__init__(output, config)
|
2016-11-07 22:00:02 +01:00
|
|
|
self._brightness = 0
|
|
|
|
self._max = 0
|
|
|
|
self._percent = 0
|
|
|
|
|
2016-11-09 19:37:09 +01:00
|
|
|
step = self._config.parameter("step", 2)
|
|
|
|
|
|
|
|
output.add_callback(module=self.instance(), button=4, cmd="xbacklight +{}%".format(step))
|
|
|
|
output.add_callback(module=self.instance(), button=5, cmd="xbacklight -{}%".format(step))
|
|
|
|
|
2016-11-07 22:00:02 +01:00
|
|
|
def widgets(self):
|
|
|
|
with open("/sys/class/backlight/intel_backlight/brightness") as f:
|
|
|
|
self._brightness = int(f.read())
|
|
|
|
with open("/sys/class/backlight/intel_backlight/max_brightness") as f:
|
|
|
|
self._max = int(f.read())
|
|
|
|
self._brightness = self._brightness if self._brightness < self._max else self._max
|
2016-11-09 19:32:26 +01:00
|
|
|
self._percent = int(round(self._brightness * 100 / self._max))
|
2016-11-07 22:00:02 +01:00
|
|
|
|
|
|
|
return bumblebee.output.Widget(self, "{:02d}%".format(self._percent))
|
|
|
|
|
2016-11-09 19:37:09 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|