]> Dogcows Code - chaz/openbox/blob - scripts/focus.py
4c3e5a136db98d8afd25665d27f9a20ec3298d89
[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
8 # maintain a list of clients, stacked in focus order
9 ob_clients = []
10 # maintaint he current focused window
11 ob_focused = 0;
12
13 def ob_new_win(data):
14 global ob_clients
15 if not len(ob_clients): ob_clients.append(data.client.window())
16 else: ob_clients.insert(1, data.client.window()) # insert in 2nd slot
17
18 def ob_close_win(data):
19 global ob_clients
20 ob_clients.remove(data.client.window())
21
22 def ob_focused(data):
23 global ob_clients
24 if data.client:
25 win = data.client.window()
26 ob_focused = win
27 # move it to the top
28 ob_clients.remove(win)
29 ob_clients.insert(0, win)
30 elif ob_focus_fallback:
31 # pass around focus
32 ob_focused = 0
33 desktop = openbox.screen(data.screen).desktop()
34 for w in ob_clients:
35 client = openbox.findClient(w)
36 if client and (client.desktop() == desktop and \
37 client.normal() and client.focus()):
38 break
39
40 ebind(EventNewWindow, ob_new_win)
41 ebind(EventCloseWindow, ob_close_win)
42 ebind(EventFocus, ob_focused)
43
44 def focus_next(data, num=1, forward=1):
45 """Focus the next (or previous, with forward=0) window in a linear
46 order."""
47 screen = openbox.screen(data.screen)
48 count = screen.clientCount()
49
50 if not count: return # no clients
51
52 target = 0
53 if data.client:
54 client_win = data.client.window()
55 found = 0
56 r = range(count)
57 if not forward:
58 r.reverse()
59 for i in r:
60 if found:
61 target = i
62 break
63 elif screen.client(i).window() == client_win:
64 found = 1
65 if not found: # wraparound
66 if forward: target = 0
67 else: target = count - 1
68
69 t = target
70 curdesk = screen.desktop()
71 while 1:
72 client = screen.client(t)
73 if client.normal() and \
74 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
75 and client.focus():
76 if ob_focus_raise:
77 screen.raiseWindow(client)
78 return
79 if forward:
80 t += num
81 if t >= count: t -= count
82 else:
83 t -= 1
84 if t < 0: t += count
85 if t == target: return # nothing to focus
86
87 def focus_prev(data, num=1):
88 """Focus the previous window in a linear order."""
89 focus_next(data, num, forward=0)
90
91
92 print "Loaded focus.py"
This page took 0.043629 seconds and 4 git commands to generate.