1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
5 # raise the window also when it is focused
7 # send focus somewhere when nothing is left with the focus if possible
10 # maintain a list of clients, stacked in focus order
12 # maintaint he current focused window
17 global ob_doing_stacked
21 ob_clients.insert(ob_clients.index(ob_cyc_w), data.client.window())
23 if not len(ob_clients):
24 ob_clients.append(data.client.window())
26 ob_clients.insert(1, data.client.window()) # insert in 2nd slot
28 def ob_close_win(data):
31 global ob_doing_stacked
33 if not ob_doing_stacked:
34 # not in the middle of stacked cycling, so who cares
35 ob_clients.remove(data.client.window())
37 # have to fix the cycling if we remove anything
38 win = data.client.window()
40 do_stacked_cycle(data) # cycle off the window first
41 ob_clients.remove(win)
45 global ob_doing_stacked
49 if not ob_doing_stacked: # only move the window when we're not cycling
50 win = data.client.window()
52 ob_clients.remove(win)
53 ob_clients.insert(0, win)
54 else: # if we are cycling, then update our pointer
55 ob_cyc_w = data.client.window()
56 elif ob_focus_fallback:
58 desktop = openbox.screen(ob_cyc_screen).desktop()
60 client = openbox.findClient(w)
61 if client and (client.desktop() == desktop and \
62 client.normal() and client.focus()):
65 ebind(EventNewWindow, ob_new_win)
66 ebind(EventCloseWindow, ob_close_win)
67 ebind(EventFocus, ob_focused)
71 ob_cyc_w = 0 # last window cycled to
74 def do_stacked_cycle(data):
78 i = ob_clients.index(ob_cyc_w) + 1
82 clients = ob_clients[i:] + ob_clients[:i]
84 client = openbox.findClient(w)
85 if client and (client.desktop() == desktop and \
86 client.normal() and client.focus()):
89 def focus_next_stacked_grab(data):
93 global ob_doing_stacked;
95 if data.action == EventKeyRelease:
96 # have all the modifiers this started with been released?
97 if not ob_cyc_mask & data.state:
98 kungrab() # ungrab ourself
102 if ob_cyc_key == data.key:
103 # the next window to try focusing in ob_clients[ob_cyc_i]
105 do_stacked_cycle(data)
107 def focus_next_stacked(data, forward=1):
112 global ob_doing_stacked
113 ob_cyc_mask = data.state
114 ob_cyc_key = data.key
116 ob_cyc_screen = data.screen
119 kgrab(data.screen, focus_next_stacked_grab)
121 focus_next_stacked_grab(data) # start with the first press
123 def focus_prev_stacked(data):
126 def focus_next(data, num=1, forward=1):
127 """Focus the next (or previous, with forward=0) window in a linear
129 screen = openbox.screen(data.screen)
130 count = screen.clientCount()
132 if not count: return # no clients
136 client_win = data.client.window()
146 elif screen.client(i).window() == client_win:
148 if found == 1: # wraparound
149 if forward: target = 0
150 else: target = count - 1
153 curdesk = screen.desktop()
155 client = screen.client(t)
156 if client.normal() and \
157 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
160 screen.raiseWindow(client)
164 if t >= count: t -= count
168 if t == target: return # nothing to focus
170 def focus_prev(data, num=1):
171 """Focus the previous window in a linear order."""
172 focus_next(data, num, forward=0)
175 print "Loaded focus.py"