]> Dogcows Code - chaz/openbox/blob - python/focus.py
dont skip enter events
[chaz/openbox] / python / focus.py
1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
4
5 import config, ob, hooks
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 False
33 if not (client.canFocus() or client.focusNotify()): return False
34 if client.iconic(): return False
35 if config.get('focus', 'avoid_skip_taskbar') and \
36 client.skipTaskbar(): return False
37
38 desk = client.desktop()
39 if not (desk == 0xffffffff or desk == desktop): return False
40
41 return True
42
43 def _focused(client):
44 global _clients, _skip
45
46 if _skip:
47 _skip -= 1
48 return
49
50 if client:
51 # move it to the top
52 _clients.remove(client)
53 _clients.insert(0, client)
54 elif config.get('focus', 'fallback'):
55 # pass around focus
56 desktop = ob.Openbox.desktop()
57 for c in _clients:
58 if focusable(c, desktop):
59 c.focus()
60 break
61
62 hooks.managed.append(lambda c: _clients.append(c))
63 hooks.closed.append(lambda c: _clients.remove(c))
64 hooks.focused.append(_focused)
65
66 print "Loaded focus.py"
This page took 0.038677 seconds and 4 git commands to generate.