]> Dogcows Code - chaz/openbox/blob - scripts/focus.py
c0d60b1ee7bb06308f05cd65d5ea268e3738a42a
[chaz/openbox] / scripts / focus.py
1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
4
5 ob_focus_raise = 1
6 ob_focus_fallback = 0
7 ob_focus_stack = []
8
9 def ob_focused(data):
10 global ob_focus_raise
11 global ob_focus_fallback
12 global ob_focus_stack
13 if data.client:
14 window = data.client.window()
15 # add/move to front the stack
16 if window in ob_focus_stack:
17 ob_focus_stack.remove(window)
18 ob_focus_stack.insert(0, window)
19 elif ob_focus_fallback:
20 # pass around focus
21 desktop = openbox.screen(data.screen).desktop()
22 l = len(ob_focus_stack)
23 i = 0
24 while i < l:
25 w = ob_focus_stack[i]
26 client = openbox.findClient(w)
27 if not client: # window is gone, remove it
28 ob_focus_stack.pop(i)
29 l = l - 1
30 elif client.desktop() == desktop and \
31 client.normal() and client.focus():
32 break
33 else:
34 i = i + 1
35
36 ebind(EventFocus, ob_focused)
37
38 def focus_next(data, num=1, forward=1):
39 """Focus the next (or previous, with forward=0) window in a linear
40 order."""
41 screen = openbox.screen(data.screen)
42 count = screen.clientCount()
43
44 if not count: return # no clients
45
46 target = 0
47 if data.client:
48 client_win = data.client.window()
49 found = 0
50 r = range(count)
51 if not forward:
52 r.reverse()
53 for i in r:
54 if found:
55 target = i
56 break
57 elif screen.client(i).window() == client_win:
58 found = 1
59 if not found: # wraparound
60 if forward: target = 0
61 else: target = count - 1
62
63 t = target
64 curdesk = screen.desktop()
65 while 1:
66 client = screen.client(t)
67 if client.normal() and \
68 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
69 and client.focus():
70 if ob_focus_raise:
71 screen.raiseWindow(client)
72 return
73 if forward:
74 t += num
75 if t >= count: t -= count
76 else:
77 t -= 1
78 if t < 0: t += count
79 if t == target: return # nothing to focus
80
81 def focus_prev(data, num=1):
82 """Focus the previous window in a linear order."""
83 focus_next(data, num, forward=0)
84
85
86 print "Loaded focus.py"
This page took 0.039042 seconds and 3 git commands to generate.