]> Dogcows Code - chaz/openbox/blob - scripts/focus.py
better skipping of focus events while stackedcycling, fixes bug where esc would still...
[chaz/openbox] / scripts / focus.py
1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
4
5 ###########################################################################
6 ### Options that affect the behavior of the focus module. ###
7 ###########################################################################
8 AVOID_SKIP_TASKBAR = 1
9 """Don't focus windows which have requested to not be displayed in taskbars.
10 You will still be able to focus the windows, but not through cycling, and
11 they won't be focused as a fallback if 'fallback' is enabled."""
12 FALLBACK = 0
13 """Send focus somewhere when nothing is left with the focus, if possible."""
14 ###########################################################################
15
16 ###########################################################################
17 ###########################################################################
18
19 ###########################################################################
20 ### Internal stuff, should not be accessed outside the module. ###
21 ###########################################################################
22
23 import ob
24
25 # maintain a list of clients, stacked in focus order
26 _clients = []
27 _skip = 0
28
29 def _focusable(client, desktop):
30 if not client.normal(): return 0
31 if not (client.canFocus() or client.focusNotify()): return 0
32 if client.iconic(): return 0
33 if AVOID_SKIP_TASKBAR and client.skipTaskbar(): return 0
34
35 desk = client.desktop()
36 if not (desk == 0xffffffff or desk == desktop): return 0
37
38 return 1
39
40 def _remove(client):
41 """This function exists because Swig pointers don't define a __eq__
42 function, so list.remove(ptr) does not work."""
43 win = client.window()
44 for i in range(len(_clients)):
45 if _clients[i].window() == win:
46 _clients.pop(i)
47 return
48 raise ValueError("_remove(x): x not in _clients list.")
49
50 def _focused(data):
51 global _clients
52
53 if _skip:
54 global _skip
55 _skip -= 1
56 return
57
58 if data.client:
59 print data.client.window()
60 # move it to the top
61 try:
62 _remove(data.client)
63 except ValueError: pass # happens if _focused comes before _newwindow
64 _clients.insert(0, data.client)
65 elif FALLBACK:
66 # pass around focus
67 desktop = ob.openbox.screen(data.screen).desktop()
68 for c in _clients:
69 if _focusable(c, desktop) and c.focus():
70 break
71
72 def _newwindow(data):
73 # make sure its not already in the list
74 win = data.client.window()
75 for i in range(len(_clients)):
76 if _clients[i].window() == win:
77 return
78 _clients.append(data.client)
79
80 def _closewindow(data):
81 _remove(data.client)
82
83 ob.ebind(ob.EventAction.NewWindow, _newwindow)
84 ob.ebind(ob.EventAction.CloseWindow, _closewindow)
85 ob.ebind(ob.EventAction.Focus, _focused)
86
87 print "Loaded focus.py"
This page took 0.037418 seconds and 4 git commands to generate.