1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
5 ###########################################################################
6 ### Options that affect the behavior of the focus module. ###
8 # raise the window also when it is focused ###
10 # raise as you cycle in stacked mode ###
11 stacked_cycle_raise = 0 ###
12 # send focus somewhere when nothing is left with the focus, if possible ###
15 ###########################################################################
19 # maintain a list of clients, stacked in focus order
21 # maintaint he current focused window
30 _clients.insert(_clients.index(_cyc_w), data.client.window())
33 _clients.append(data.client.window())
35 _clients.insert(1, data.client.window()) # insert in 2nd slot
42 if not _doing_stacked:
43 # not in the middle of stacked cycling, so who cares
44 _clients.remove(data.client.window())
46 # have to fix the cycling if we remove anything
47 win = data.client.window()
49 _do_stacked_cycle(data) # cycle off the window first
58 if not _doing_stacked: # only move the window when we're not cycling
59 win = data.client.window()
62 _clients.insert(0, win)
63 else: # if we are cycling, then update our pointer
64 _cyc_w = data.client.window()
67 desktop = ob.openbox.screen(_cyc_screen).desktop()
69 client = ob.openbox.findClient(w)
70 if client and (client.desktop() == desktop and \
71 client.normal() and client.focus()):
76 _cyc_w = 0 # last window cycled to
79 def _do_stacked_cycle(data, forward):
81 global stacked_cycle_raise
84 clients = _clients[:] # make a copy
90 i = clients.index(_cyc_w) + 1
93 clients = clients[i:] + clients[:i]
95 desktop = ob.openbox.screen(data.screen).desktop()
97 client = ob.openbox.findClient(w)
98 if client and (client.desktop() == desktop and \
99 client.normal() and client.focus()):
100 if stacked_cycle_raise:
101 ob.openbox.screen(data.screen).raiseWindow(client)
104 def _focus_stacked_ungrab(data):
107 global _doing_stacked;
109 if data.action == ob.KeyAction.Release:
110 # have all the modifiers this started with been released?
111 if not _cyc_mask & data.state:
112 ob.kungrab() # ungrab ourself
115 client = ob.openbox.findClient(_cyc_w)
117 ob.openbox.screen(data.screen).raiseWindow(client)
119 def focus_next_stacked(data, forward=1):
120 """Focus the next (or previous, with forward=0) window in a stacked
126 global _doing_stacked
129 if _cyc_key == data.key:
130 _do_stacked_cycle(data,forward)
132 _cyc_mask = data.state
135 _cyc_screen = data.screen
138 ob.kgrab(data.screen, _focus_stacked_ungrab)
139 focus_next_stacked(data, forward) # start with the first press
141 def focus_prev_stacked(data):
142 """Focus the previous window in a stacked order."""
143 focus_next_stacked(data, forward=0)
145 def focus_next(data, num=1, forward=1):
146 """Focus the next (or previous, with forward=0) window in a linear
148 screen = ob.openbox.screen(data.screen)
149 count = screen.clientCount()
151 if not count: return # no clients
155 client_win = data.client.window()
165 elif screen.client(i).window() == client_win:
167 if found == 1: # wraparound
168 if forward: target = 0
169 else: target = count - 1
172 curdesk = screen.desktop()
174 client = screen.client(t)
175 if client.normal() and \
176 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
179 screen.raiseWindow(client)
183 if t >= count: t -= count
187 if t == target: return # nothing to focus
189 def focus_prev(data, num=1):
190 """Focus the previous window in a linear order."""
191 focus_next(data, num, forward=0)
194 ob.ebind(ob.EventAction.NewWindow, _new_win)
195 ob.ebind(ob.EventAction.CloseWindow, _close_win)
196 ob.ebind(ob.EventAction.Focus, _focused)
198 print "Loaded focus.py"