Make sure state is reverted in case of error
This commit is contained in:
parent
43b29eedd2
commit
43988db4cc
1 changed files with 14 additions and 6 deletions
|
@ -55,7 +55,7 @@ class Module(bumblebee.engine.Module):
|
||||||
def _suspend_screensaver(self):
|
def _suspend_screensaver(self):
|
||||||
self._xid = self._get_i3bar_xid()
|
self._xid = self._get_i3bar_xid()
|
||||||
if self._xid is None:
|
if self._xid is None:
|
||||||
return
|
return False
|
||||||
|
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if pid == 0:
|
if pid == 0:
|
||||||
|
@ -64,12 +64,16 @@ class Module(bumblebee.engine.Module):
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
else:
|
else:
|
||||||
os.waitpid(pid, 0)
|
os.waitpid(pid, 0)
|
||||||
|
return True
|
||||||
|
|
||||||
def _resume_screensaver(self):
|
def _resume_screensaver(self):
|
||||||
for process in psutil.process_iter():
|
for process in psutil.process_iter():
|
||||||
if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']:
|
if process.cmdline() == [bumblebee.util.which('xprop'), '-id', str(self._xid), '-spy']:
|
||||||
pid = process.pid
|
try:
|
||||||
os.kill(pid, 9)
|
os.kill(process.pid, 9)
|
||||||
|
except OSError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def state(self, _):
|
def state(self, _):
|
||||||
if self._active:
|
if self._active:
|
||||||
|
@ -84,9 +88,13 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
self._active = not self._active
|
self._active = not self._active
|
||||||
if self._active:
|
if self._active:
|
||||||
self._suspend_screensaver()
|
success = self._suspend_screensaver()
|
||||||
else:
|
else:
|
||||||
self._resume_screensaver()
|
success = self._resume_screensaver()
|
||||||
|
|
||||||
|
if success:
|
||||||
self._notify()
|
self._notify()
|
||||||
|
else:
|
||||||
|
self._active = not self._active
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue