My collection of plugins for the Qtile window manager.
git clone https://mcol.xyz/code/qtools
Log | Files | Refs | README

commit 34cad2a53579e3ef78b08e6321a305160c861d8c
parent f03bb06d135d30d73b37530d9ea03166baf124a5
Author: mcol <mcol@posteo.net>
Date:   Sun, 12 Jan 2020 19:42:20 +0000

add smooth backlight change, and notify on searx instance removal

Diffstat:
Mqtools/backlight/backlight.py | 47+++++++++++++++++++++++++++++++++--------------
Mqtools/rofi_searx/searx.py | 4++++
2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/qtools/backlight/backlight.py b/qtools/backlight/backlight.py @@ -13,11 +13,15 @@ Example usage: """ import os +import time from libqtile.log_utils import logger from qtools import Notifier +_transition = 80 + + class Backlight(Notifier): """ This class controls screen backlight by directly reading and writing to the @@ -26,6 +30,7 @@ class Backlight(Notifier): defaults = [ ('summary', 'Backlight', 'Notification summary.'), ('interval', 10, 'Percentage interval by which to change backlight'), + ('smooth', True, 'Whether to smoothly change brightness level.'), ( 'path', '/sys/class/backlight/nv_backlight/brightness', @@ -36,31 +41,45 @@ class Backlight(Notifier): def __init__(self, **config): Notifier.__init__(self, **config) self.add_defaults(Backlight.defaults) + self.transition = _transition / self.interval / 1000 if not os.path.isfile(self.path): logger.error('Path passed to Backlight plugin is invalid') self.path = '/dev/null' - @property - def brightness(self): + def inc_brightness(self, qtile=None): + self.change(1) + + def dec_brightness(self, qtile=None): + self.change(-1) + + def change(self, direction): + start = self.get_brightness() + end = self.check_value(start + self.interval * direction) + self.show(end) + + if self.smooth: + for i in range( + start + direction, + end + direction, + direction + ): + with open(self.path, 'w') as f: + f.write(str(i)) + time.sleep(self.transition) + else: + with open(self.path, 'w') as f: + f.write(str(end)) + + def get_brightness(self): with open(self.path, 'r') as f: return int(f.read()) - @brightness.setter - def brightness(self, value): + def check_value(self, value): if value > 100: value = 100 elif value < 0: value = 0 elif value % self.interval: value = self.interval * round(value / self.interval) - - with open(self.path, 'w') as f: - f.write(str(value)) - self.show(value) - - def inc_brightness(self, qtile=None): - self.brightness += self.interval - - def dec_brightness(self, qtile=None): - self.brightness -= self.interval + return value diff --git a/qtools/rofi_searx/searx.py b/qtools/rofi_searx/searx.py @@ -46,6 +46,8 @@ class Searx(Notifier): ('theme', None, 'rofi theme to use.'), ('launcher', 'tor-browser --allow-remote {url}', 'Command used to open web ' 'browser. Requires {url} to place the search url.'), + ('notify_on_remove', True, 'Whether to make a notification when removing a ' + 'searx instance.'), ] def __init__(self, **config): @@ -88,6 +90,8 @@ class Searx(Notifier): if self.instances_file: self.instances.append(f'#{self.last_used}') self.save_instances() + if self.notify_on_remove: + self.show(self.last_used) self.last_used = None def load_instances(self, qtile=None):