2019-08-25 20:53:42 +02:00
|
|
|
#pylint: disable=C0111,R0903
|
2016-12-10 15:36:18 +01:00
|
|
|
|
|
|
|
"""Enable/disable automatic screen locking.
|
2017-01-05 04:55:14 +01:00
|
|
|
|
|
|
|
Requires the following executables:
|
2019-08-25 20:53:42 +02:00
|
|
|
* xdg-screensaver
|
2019-08-27 21:31:50 +02:00
|
|
|
* xdotool
|
2017-01-05 04:55:14 +01:00
|
|
|
* notify-send
|
2016-12-10 15:36:18 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
2019-08-27 21:31:50 +02:00
|
|
|
import psutil
|
|
|
|
import os
|
2016-12-10 15:36:18 +01:00
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
2019-08-25 20:53:42 +02:00
|
|
|
bumblebee.output.Widget(full_text="")
|
2016-12-10 15:36:18 +01:00
|
|
|
)
|
2019-08-25 20:53:42 +02:00
|
|
|
self._active = False
|
2019-08-27 21:31:50 +02:00
|
|
|
self._xid = 0
|
2019-08-25 20:53:42 +02:00
|
|
|
|
2016-12-10 15:36:18 +01:00
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd=self._toggle
|
|
|
|
)
|
|
|
|
|
|
|
|
def state(self, widget):
|
2019-08-25 20:53:42 +02:00
|
|
|
if self._active:
|
2016-12-10 15:36:18 +01:00
|
|
|
return "activated"
|
|
|
|
return "deactivated"
|
|
|
|
|
2019-08-25 20:53:42 +02:00
|
|
|
def _toggle(self, event):
|
|
|
|
self._active = not self._active
|
2019-08-25 21:08:00 +02:00
|
|
|
try:
|
|
|
|
if self._active:
|
2019-08-27 21:31:50 +02:00
|
|
|
self._xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").strip()
|
|
|
|
bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid))
|
2019-08-25 21:08:00 +02:00
|
|
|
bumblebee.util.execute("notify-send \"Consuming caffeine\"")
|
|
|
|
else:
|
2019-08-27 21:31:50 +02:00
|
|
|
for process in psutil.process_iter():
|
|
|
|
if process.cmdline() == ['/usr/bin/xprop','-id',str(self._xid),'-spy']:
|
|
|
|
pid = process.pid
|
|
|
|
os.kill(pid,9)
|
2019-08-25 21:08:00 +02:00
|
|
|
bumblebee.util.execute("notify-send \"Out of coffee\"")
|
|
|
|
except:
|
|
|
|
self._active = not self._active
|
2019-08-25 20:53:42 +02:00
|
|
|
|
2016-12-10 15:36:18 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|