PoC using xdg-screensaver's suspend mechanisms
This commit is contained in:
parent
c05fc3ae4d
commit
6652a581df
1 changed files with 10 additions and 7 deletions
|
@ -4,12 +4,15 @@
|
||||||
|
|
||||||
Requires the following executables:
|
Requires the following executables:
|
||||||
* xdg-screensaver
|
* xdg-screensaver
|
||||||
|
* xdotool
|
||||||
* notify-send
|
* notify-send
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
import psutil
|
||||||
|
import os
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
|
@ -17,7 +20,7 @@ class Module(bumblebee.engine.Module):
|
||||||
bumblebee.output.Widget(full_text="")
|
bumblebee.output.Widget(full_text="")
|
||||||
)
|
)
|
||||||
self._active = False
|
self._active = False
|
||||||
self.interval(1)
|
self._xid = 0
|
||||||
|
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd=self._toggle
|
cmd=self._toggle
|
||||||
|
@ -32,16 +35,16 @@ class Module(bumblebee.engine.Module):
|
||||||
self._active = not self._active
|
self._active = not self._active
|
||||||
try:
|
try:
|
||||||
if self._active:
|
if self._active:
|
||||||
bumblebee.util.execute("xdg-screensaver reset")
|
self._xid = bumblebee.util.execute("xdotool search --class \"i3bar\"").strip()
|
||||||
|
bumblebee.util.execute("xdg-screensaver suspend {}".format(self._xid))
|
||||||
bumblebee.util.execute("notify-send \"Consuming caffeine\"")
|
bumblebee.util.execute("notify-send \"Consuming caffeine\"")
|
||||||
else:
|
else:
|
||||||
|
for process in psutil.process_iter():
|
||||||
|
if process.cmdline() == ['/usr/bin/xprop','-id',str(self._xid),'-spy']:
|
||||||
|
pid = process.pid
|
||||||
|
os.kill(pid,9)
|
||||||
bumblebee.util.execute("notify-send \"Out of coffee\"")
|
bumblebee.util.execute("notify-send \"Out of coffee\"")
|
||||||
except:
|
except:
|
||||||
self._active = not self._active
|
self._active = not self._active
|
||||||
|
|
||||||
def update(self, widgets):
|
|
||||||
if self._active:
|
|
||||||
bumblebee.util.execute("xdg-screensaver reset")
|
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue