1
1
#!/usr/bin/python
2
2
3
+ # To make this event driven, watch the root window for
4
+ # _NET_ACTIVE_WINDOW property changes. The down side of event driven
5
+ # is that the window observation may not coincide with the observed
6
+ # property change event. (i.e. active window changes twice before we
7
+ # can observe window focus once). Also, there's more back and forth
8
+ # when windows do switch (prop change event + get_input_focus).
9
+
3
10
import os
4
11
import re
5
12
import time
@@ -8,6 +15,8 @@ from Xlib import display
8
15
from select import select
9
16
from subprocess import Popen , PIPE
10
17
18
+ import hotshot
19
+
11
20
D = display .Display ()
12
21
13
22
oldname = newname = ''
@@ -56,18 +65,26 @@ xss_proc = Popen(['xscreensaver-command', '-watch'], stdout=PIPE)
56
65
fd_handlers [xss_proc .stdout ] = xss_event
57
66
infds = [xss_proc .stdout ]
58
67
59
- winmon ()
60
- running = True
61
- while running :
62
- try :
63
- (infda ,outfda ,errfda ) = select (infds , outfds , errfds , 0.3 )
64
- if infda :
65
- for fd in infda :
66
- fd_handlers [fd ](fd )
67
-
68
- # Always check window state
69
- winmon ()
70
- except KeyboardInterrupt :
71
- running = False
72
- # Because otherwise they don't clean up when we go away...
73
- os .kill (xss_proc .pid , 15 )
68
+ #profiler = hotshot.Profile()
69
+
70
+ def main ():
71
+
72
+ winmon ()
73
+ running = True
74
+ while running :
75
+ try :
76
+ (infda ,outfda ,errfda ) = select (infds , outfds , errfds , 0.3 )
77
+ if infda :
78
+ for fd in infda :
79
+ fd_handlers [fd ](fd )
80
+
81
+ # Always check window state
82
+ winmon ()
83
+ except KeyboardInterrupt :
84
+ running = False
85
+ # Because otherwise they don't clean up when we go away...
86
+ os .kill (xss_proc .pid , 15 )
87
+
88
+ #profiler.runcall(main)
89
+
90
+ main ()
0 commit comments