summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2019-02-14 00:01:17 +0100
committerSebastian Reichel <sre@ring0.de>2019-02-14 00:01:17 +0100
commitb0a38d7b72a849f12062cbf2f2d172599a99fd83 (patch)
tree9b35427dfd0e06c1a895dbe35c07637495879724
parentad766020f25c20b4739c10aa8177e0da9c78a9ce (diff)
downloadtp-key-handler-b0a38d7b72a849f12062cbf2f2d172599a99fd83.tar.bz2
use percentage based brightness steps
-rwxr-xr-xtp-key-handler37
1 files changed, 29 insertions, 8 deletions
diff --git a/tp-key-handler b/tp-key-handler
index a47f8f8..259210f 100755
--- a/tp-key-handler
+++ b/tp-key-handler
@@ -130,21 +130,42 @@ class KeyhandlerDBUSService(dbus.service.Object):
popen.wait()
self._showMicState()
- @dbus.service.method('org.elektranox.keyhandler')
- def backlightDec(self):
- brightness = self._getBacklight() - 5
+ def _backlightChg(self, decrease):
+ brightness = self._getBacklight()
+ maximum = self._getMaxBacklight()
+ current = self._getBacklight() / maximum * 100
+ step = 1
+
+ # probably should implement something using a logarithmic scale
+ if current <= 2:
+ step = int(0.5 * maximum/100)
+ elif current <= 10:
+ step = int(1 * maximum/100)
+ elif current <= 50:
+ step = int(5 * maximum/100)
+ else:
+ step = int(10 * maximum/100)
+
+ if decrease:
+ brightness -= step
+ else:
+ brightness += step
+
if brightness < 0:
brightness = 0
+ if brightness > maximum:
+ brightness = maximum
self._setBacklight(brightness)
self._showBacklightState()
+
+ @dbus.service.method('org.elektranox.keyhandler')
+ def backlightDec(self):
+ self._backlightChg(True)
+
@dbus.service.method('org.elektranox.keyhandler')
def backlightInc(self):
- brightness = self._getBacklight() + 5
- if brightness > self._getMaxBacklight():
- brightness = self._getMaxBacklight()
- self._setBacklight(brightness)
- self._showBacklightState()
+ self._backlightChg(False)
@dbus.service.method('org.elektranox.keyhandler')
def XF86Display(self):