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 # show a pop-up list of windows while cycling ###
14 # send focus somewhere when nothing is left with the focus, if possible ###
17 ###########################################################################
22 # maintain a list of clients, stacked in focus order
24 # maintaint he current focused window
33 _clients.insert(_clients.index(_cyc_w), data.client.window())
36 _clients.append(data.client.window())
38 _clients.insert(1, data.client.window()) # insert in 2nd slot
45 if not _doing_stacked:
46 # not in the middle of stacked cycling, so who cares
47 _clients.remove(data.client.window())
49 # have to fix the cycling if we remove anything
50 win = data.client.window()
52 _do_stacked_cycle(data) # cycle off the window first
61 if not _doing_stacked: # only move the window when we're not cycling
62 win = data.client.window()
65 _clients.insert(0, win)
66 else: # if we are cycling, then update our pointer
67 _cyc_w = data.client.window()
68 global _list_widget, _list_labels, _list_windows
71 for w in _list_windows:
72 if w == _cyc_w: _list_labels[i].focus()
73 else: _list_labels[i].unfocus()
77 desktop = ob.openbox.screen(_cyc_screen).desktop()
79 client = ob.openbox.findClient(w)
80 if client and (client.desktop() == desktop and \
81 client.normal() and client.focus()):
86 _cyc_w = 0 # last window cycled to
89 def _do_stacked_cycle(data, forward):
91 global stacked_cycle_raise
94 clients = _clients[:] # make a copy
100 i = clients.index(_cyc_w) + 1
103 clients = clients[i:] + clients[:i]
105 desktop = ob.openbox.screen(data.screen).desktop()
107 client = ob.openbox.findClient(w)
108 if client and (client.desktop() == desktop and \
109 client.normal() and client.focus()):
110 if stacked_cycle_raise:
111 ob.openbox.screen(data.screen).raiseWindow(client)
114 def _focus_stacked_ungrab(data):
117 global _doing_stacked;
119 if data.action == ob.KeyAction.Release:
120 # have all the modifiers this started with been released?
121 if not _cyc_mask & data.state:
122 ob.kungrab() # ungrab ourself
125 client = ob.openbox.findClient(_cyc_w)
127 ob.openbox.screen(data.screen).raiseWindow(client)
128 global _list_widget, _list_labels, _list_windows
138 def focus_next_stacked(data, forward=1):
139 """Focus the next (or previous, with forward=0) window in a stacked
145 global _doing_stacked
148 if _cyc_key == data.key:
149 _do_stacked_cycle(data,forward)
151 _cyc_mask = data.state
154 _cyc_screen = data.screen
157 global cycle_popup_list
159 global _list_widget, _list_labels
160 if not _list_widget: # make the widget list
161 style = ob.openbox.screen(data.screen).style()
162 _list_widget = otk.Widget(ob.openbox, style,
163 otk.Widget.Vertical, 0,
164 style.bevelWidth(), 1)
165 t = style.titlebarFocusBackground()
166 _list_widget.setTexture(t)
169 font = style.labelFont()
170 height = font.height()
173 client = ob.openbox.findClient(c)
174 screen = ob.openbox.screen(data.screen)
175 desktop = screen.desktop()
176 if client and (client.desktop() == desktop and \
179 if len(t) > 50: # limit the length of titles
180 t = t[:24] + "..." + t[-24:]
182 _list_windows.append(c)
183 l = font.measureString(t) + 10 # add margin
184 if l > longest: longest = l
187 w = otk.FocusLabel(_list_widget)
188 w.resize(longest, height)
191 _list_labels.append(w)
192 _list_labels[0].focus()
193 _list_widget.update()
195 _list_widget.move(area.x() + (area.width() -
196 _list_widget.width()) / 2,
197 area.y() + (area.height() -
198 _list_widget.height()) / 2)
201 _list_widget = 0 #nothing to list
203 ob.kgrab(data.screen, _focus_stacked_ungrab)
204 focus_next_stacked(data, forward) # start with the first press
206 def focus_prev_stacked(data):
207 """Focus the previous window in a stacked order."""
208 focus_next_stacked(data, forward=0)
210 def focus_next(data, num=1, forward=1):
211 """Focus the next (or previous, with forward=0) window in a linear
213 screen = ob.openbox.screen(data.screen)
214 count = screen.clientCount()
216 if not count: return # no clients
220 client_win = data.client.window()
230 elif screen.client(i).window() == client_win:
232 if found == 1: # wraparound
233 if forward: target = 0
234 else: target = count - 1
237 curdesk = screen.desktop()
239 client = screen.client(t)
240 if client.normal() and \
241 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
244 screen.raiseWindow(client)
248 if t >= count: t -= count
252 if t == target: return # nothing to focus
254 def focus_prev(data, num=1):
255 """Focus the previous window in a linear order."""
256 focus_next(data, num, forward=0)
259 ob.ebind(ob.EventAction.NewWindow, _new_win)
260 ob.ebind(ob.EventAction.CloseWindow, _close_win)
261 ob.ebind(ob.EventAction.Focus, _focused)
263 print "Loaded focus.py"