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