]> git.neil.brown.name Git - freerunner.git/commitdiff
Improve the check for "are any keys down"
authorNeil Brown <neilb@suse.de>
Fri, 30 Jan 2009 12:00:25 +0000 (23:00 +1100)
committerNeil Brown <neilb@suse.de>
Fri, 30 Jan 2009 12:00:25 +0000 (23:00 +1100)
I'm not sure this test is really needed, but while I still
have it, make it as accurate as possible.

lock/lock.py

index 27294af0cb2741b2fd5a991fd199da8a0c3423e4..9adc658b7081572829f1fc3c866b58b257ccb280 100644 (file)
@@ -50,7 +50,7 @@ class EvDev:
             if value == 0:
                 # 'up' - remove from downlist
                 if code in self.downlist:
-                    del self.downlist[self.downlist.index(code)]
+                    self.downlist.remove(code)
             else:
                 # 'down' - add to downlist
                 if code not in self.downlist:
@@ -58,26 +58,45 @@ class EvDev:
         self.on_event(self.down_count(), typ, code, value)
         return True
     def down_count(self):
+        if len(self.downlist) == 0:
+            return 0
+        # double check, we might have missed an 'up' event somehow.
+        try:
+            rv = fcntl.ioctl(self.f, EVIOCGKEY(768/8), (768/8) * " " )
+            l = len(rv)/4
+            ra = struct.unpack('%dI' % l, rv)
+            isup = []
+            for k in self.downlist:
+                by = int(k/8)
+                bt = k % 8
+                if by < l and ((ra[by] >> bt) & 1) == 0:
+                    isup.append[k]
+            for k in isup:
+                self.downlist.remove(k)
+        except:
+            pass
         return len(self.downlist)
 
     def grab(self):
         if self.grabbed:
             return
         #print "grab"
-        fcntl.ioctl(self.f, EVIOC_GRAB, 1)
+        fcntl.ioctl(self.f, EVIOCGRAB, 1)
         self.grabbed = True
     def ungrab(self):
         if not self.grabbed:
             return
         #print "release"
-        fcntl.ioctl(self.f, EVIOC_GRAB, 0)
+        fcntl.ioctl(self.f, EVIOCGRAB, 0)
         self.grabbed = False
 
 FBIOBLANK = 0x4611
 FB_BLANK_UNBLANK = 0
 FB_BLANK_POWERDOWN = 4
 
-EVIOC_GRAB = 0x40044590
+EVIOCGRAB = 0x40044590
+def EVIOCGKEY(len):
+    return 0x80004518 + len * 65536
 
 class Screen:
     def __init__(self):