-
Notifications
You must be signed in to change notification settings - Fork 1
/
lircfirefox.py
executable file
·81 lines (74 loc) · 2.49 KB
/
lircfirefox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# vim: ts=4 sts=4 sw=4 tw=79 sta et
"""
An interface script for using lirc with Firefox, requires pylirc and xdotool
"""
__author__ = 'Patrick Butler'
__email__ = 'pbutler at killertux org'
__license__ = "GPLv2"
import subprocess
import sys
import pylirc
import time
def main(args):
"""
Fires off firefox, then inits pylirc and waits for remote presses
"""
xstatus = subprocess.Popen(["xset", "-q"], stdout = subprocess.PIPE)
xstatus.wait()
has_dpms = any("DPMS is Enabled" in line for line in xstatus.stdout)
if has_dpms:
subprocess.Popen(["xset", "-dpms"])
try:
ffox(args)
finally:
if has_dpms:
subprocess.Popen(["xset", "+dpms"])
def ffox(args):
ffox = subprocess.Popen(["/usr/bin/firefox"] + args[1:])
try:
if not pylirc.init("firefox", "~/.lircrc", 1):
return "Failed"
stop = False
while not stop:
codes = pylirc.nextcode(1)
if codes is None:
continue
for code in codes:
#print code
if code is None:
continue
config = code["config"].split()
if config[0] == "EXIT":
stop = True
break
if config[0] == "mousestepreset":
mousestep = 0
elif config[0] == "mousemove_relative":
if mousestep < 10:
mousestep += 1
config[2] = str(int(config[2]) * mousestep ** 2)
config[3] = str(int(config[3]) * mousestep ** 2)
subprocess.Popen(["xdotool"] + config)
except KeyboardInterrupt:
print "Exiting...."
p1 = subprocess.Popen(["xdotool", "search", "--title", "Mozilla Firefox"], stdout = subprocess.PIPE)
p1.wait()
windows = p1.stdout.readline().split()
for window in windows:
#print "'%s'" % window
subprocess.Popen(["xdotool", "windowfocus", str(window)])
subprocess.Popen(["xdotool", "key", "ctrl+q"])
# If we found windows and they're still running, wait 3 seconds
if len(windows) != 0 and ffox.poll() is None:
for i in range(30):
time.sleep(.1)
if ffox.poll() is not None:
break
# Okay now we can forcibly kill it
if ffox.poll() is None:
ffox.terminate()
return 0
if __name__ == "__main__":
sys.exit( main( sys.argv ) )