2016-11-23 13:57:29 +01:00
|
|
|
import subprocess
|
|
|
|
import shlex
|
|
|
|
|
|
|
|
import bumblebee.module
|
|
|
|
|
|
|
|
def description():
|
|
|
|
return "Enable/disable auto screen lock."
|
|
|
|
|
|
|
|
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-23 13:57:29 +01:00
|
|
|
self._activated = 0
|
2016-11-23 18:29:05 +01:00
|
|
|
output.add_callback(module="caffeine.activate", button=1, cmd=[ 'notify-send "Consuming caffeine"', 'xset s off' ])
|
|
|
|
output.add_callback(module="caffeine.deactivate", button=1, cmd=[ 'notify-send "Out of coffee"', 'xset s default' ])
|
2016-11-23 13:57:29 +01:00
|
|
|
|
|
|
|
def widgets(self):
|
|
|
|
output = subprocess.check_output(shlex.split("xset q"))
|
|
|
|
xset_out = output.decode().split("\n")
|
|
|
|
for line in xset_out:
|
|
|
|
if line.startswith(" timeout"):
|
|
|
|
timeout = int(line.split(" ")[4])
|
|
|
|
if timeout == 0:
|
|
|
|
self._activated = 1;
|
|
|
|
else:
|
|
|
|
self._activated = 0;
|
|
|
|
break
|
|
|
|
|
|
|
|
if self._activated == 0:
|
|
|
|
return bumblebee.output.Widget(self, "", instance="caffeine.activate")
|
|
|
|
elif self._activated == 1:
|
|
|
|
return bumblebee.output.Widget(self, "", instance="caffeine.deactivate")
|
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
if self._activated == 1:
|
|
|
|
return "activated"
|
|
|
|
else:
|
|
|
|
return "deactivated"
|
|
|
|
|