summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-01-28 14:31:07 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-01-28 14:31:07 +0100
commite342d5c7241cd04352948fb6937e05a98000b70c (patch)
tree4a8cdf8e6d4c8863026b310d8b6dda9188ba475c
parent76532c49651a372a25010bc7f7f8b60eeebefdfd (diff)
downloadpylock-e342d5c7241cd04352948fb6937e05a98000b70c.tar
pylock-e342d5c7241cd04352948fb6937e05a98000b70c.zip
Handle failed device grabs and retry lock
-rw-r--r--LockWindow.py16
-rw-r--r--Locker.py7
-rw-r--r--pylock.py2
3 files changed, 21 insertions, 4 deletions
diff --git a/LockWindow.py b/LockWindow.py
index 97a8611..a3afcc9 100644
--- a/LockWindow.py
+++ b/LockWindow.py
@@ -42,6 +42,7 @@ class LockWindow(Gtk.Window):
self.display = Gdk.Display.get_default()
self.screen = self.display.get_default_screen()
+ self.devicesGrabbed = False
self.overlay = Gtk.Overlay()
self.add(self.overlay)
@@ -135,22 +136,33 @@ class LockWindow(Gtk.Window):
def _grabDevices(self, w, e):
self.promptEntry.grab_focus()
- for device in self.deviceManager.list_devices(Gdk.DeviceType.MASTER):
- device.grab(self.get_window(), Gdk.GrabOwnership.APPLICATION, True, Gdk.EventMask.ALL_EVENTS_MASK, None, Gdk.CURRENT_TIME)
+ if not self.devicesGrabbed:
+ for device in self.deviceManager.list_devices(Gdk.DeviceType.MASTER):
+ if device.grab(self.get_window(), Gdk.GrabOwnership.APPLICATION, True, Gdk.EventMask.ALL_EVENTS_MASK, None, Gdk.CURRENT_TIME) != Gdk.GrabStatus.SUCCESS:
+ self._ungrabDevices()
+ self.get_window().lower()
+ return False
self.present()
+ self.devicesGrabbed = True
+
return False
def _ungrabDevices(self):
for device in self.deviceManager.list_devices(Gdk.DeviceType.MASTER):
device.ungrab(Gdk.CURRENT_TIME)
+ self.devicesGrabbed = False
def lock(self):
self.show_all()
+ self.display.sync()
+ self._grabDevices(self, None)
+ return self.devicesGrabbed
def unlock(self):
self._ungrabDevices()
self.hide()
+
self.reset(False, True)
diff --git a/Locker.py b/Locker.py
index fd2f5ed..0f10fe0 100644
--- a/Locker.py
+++ b/Locker.py
@@ -66,7 +66,10 @@ class Locker(object):
def lock(self):
if not self.locked:
self.locked = True
- self.doLock(self.logoutTimeout)
+ if not self.doLock(self.logoutTimeout):
+ self.locked = False
+ GLib.timeout_add_seconds(1, self._checkLock)
+ return False
if self.doLogout is not None:
self.currentLogoutTimeout = self.logoutTimeout
@@ -74,6 +77,8 @@ class Locker(object):
if self.currentLogoutTimeout > 0:
GLib.timeout_add_seconds(1, self._checkLogout)
+ return True
+
def unlock(self):
if self.locked:
self.doUnlock()
diff --git a/pylock.py b/pylock.py
index 159b7d2..be8e901 100644
--- a/pylock.py
+++ b/pylock.py
@@ -91,7 +91,7 @@ if not Message.acquireSelection(window):
def lock(timeLeft):
window.updateLockMessage(args.username, timeLeft)
- window.lock()
+ return window.lock()
def logout():
try: