summaryrefslogtreecommitdiffstats
path: root/tomit
authorRaghavendra D Prabhu <[email protected]>2011-04-10 09:28:38 (GMT)
committer Raghavendra D Prabhu <[email protected]>2011-04-10 09:28:38 (GMT)
commit9be7ca6fd73c99610bec6c2ec608e8f3ffd1fdd0 (patch) (side-by-side diff)
tree723f9870d10e750ae6b14cbb0b409b4ac04a57ab /tomit
parentd116dc185b304f35c357f6db2863532ed2a158d1 (diff)
downloadScripts-9be7ca6fd73c99610bec6c2ec608e8f3ffd1fdd0.zip
Scripts-9be7ca6fd73c99610bec6c2ec608e8f3ffd1fdd0.tar.gz
Scripts-9be7ca6fd73c99610bec6c2ec608e8f3ffd1fdd0.tar.bz2
Updated scripts/ tomit - mouse killer / cmodprobe - modprobe handler
Diffstat (limited to 'tomit') (more/less context) (ignore whitespace changes)
-rwxr-xr-xtomit66
1 files changed, 66 insertions, 0 deletions
diff --git a/tomit b/tomit
new file mode 100755
index 0000000..429f89d
--- a/dev/null
+++ b/tomit
@@ -0,0 +1,66 @@
+#!/usr/bin/python2
+import signal
+import time, sys
+import subprocess, shlex
+import daemon
+import atexit
+
+import setproctitle as setp
+
+from Xlib.display import Display
+from Xlib import X
+from Xlib.protocol import request
+from Xlib.protocol import request,rq
+
+class Tomit(object):
+ def __init__(self,daemonize):
+ setp.setproctitle("tomit")
+ self.disp = Display()
+ self.mask = X.PointerMotionMask | X.PointerMotionHintMask | X.LeaveWindowMask | X.EnterWindowMask
+ self.root = self.disp.screen().root
+ self.root.change_attributes(event_mask = self.mask)
+ self.root.grab_pointer(1,self.mask,X.GrabModeSync,X.GrabModeAsync,X.NONE,X.NONE,X.CurrentTime)
+
+ self.xin='xinput set-prop "PIXART USB OPTICAL MOUSE" "Device Enabled"'
+ signal.signal(signal.SIGUSR1,self.renable)
+ atexit.register(self.cleanup)
+ if (daemonize == 1):
+ with daemon.DaemonContext():
+ self.loop()
+ else:
+ self.loop()
+
+ def cleanup(self):
+ proc = \
+ subprocess.Popen(shlex.split(self.xin+' "1"'))
+ proc.communicate()
+ return proc.returncode
+
+ def loop(self):
+ while True:
+ subprocess.Popen(shlex.split(self.xin+' "0"'))
+ ev = self.disp.next_event()
+ print repr(ev)
+ time.sleep(100)
+
+ def renable(self,signum,frame):
+ subprocess.Popen(shlex.split(self.xin+' "1"'))
+ self.disp.ungrab_pointer(X.CurrentTime)
+ while True:
+ proc = subprocess.Popen(shlex.split("inotifywait -t 60 \
+ /dev/input/by-id/usb-PIXART_USB_OPTICAL_MOUSE-event-mouse"))
+ proc.communicate()
+ if (proc.returncode == 2):
+ print "Re-disabling pointer"
+ subprocess.Popen(shlex.split(self.xin+' "0"'))
+ self.root.grab_pointer(1,self.mask,X.GrabModeSync,X.GrabModeAsync,X.NONE,X.NONE,X.CurrentTime)
+ break
+ else:
+ time.sleep(20)
+
+
+if __name__ == "__main__":
+ daemonize = 1
+ if len(sys.argv)>1:
+ daemonize = int(sys.argv[1])
+ sys.exit(Tomit(daemonize))