2016-12-10 15:36:18 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Enable/disable automatic screen locking.
|
2017-01-05 04:55:14 +01:00
|
|
|
|
|
|
|
Requires the following executables:
|
|
|
|
* xset
|
|
|
|
* notify-send
|
2016-12-10 15:36: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.caffeine)
|
|
|
|
)
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd=self._toggle
|
|
|
|
)
|
|
|
|
|
2016-12-11 11:37:24 +01:00
|
|
|
def caffeine(self, widget):
|
2016-12-10 15:36:18 +01:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
if self._active():
|
|
|
|
return "activated"
|
|
|
|
return "deactivated"
|
|
|
|
|
|
|
|
def _active(self):
|
|
|
|
for line in bumblebee.util.execute("xset q").split("\n"):
|
|
|
|
if "timeout" in line:
|
|
|
|
timeout = int(line.split(" ")[4])
|
|
|
|
if timeout == 0:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _toggle(self, widget):
|
|
|
|
if self._active():
|
2019-06-19 22:26:48 +02:00
|
|
|
bumblebee.util.execute("xset +dpms")
|
2016-12-10 15:36:18 +01:00
|
|
|
bumblebee.util.execute("xset s default")
|
|
|
|
bumblebee.util.execute("notify-send \"Out of coffee\"")
|
|
|
|
else:
|
2019-06-19 22:26:48 +02:00
|
|
|
bumblebee.util.execute("xset -dpms")
|
2016-12-10 15:36:18 +01:00
|
|
|
bumblebee.util.execute("xset s off")
|
|
|
|
bumblebee.util.execute("notify-send \"Consuming caffeine\"")
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|