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 ###
13 stacked_cycle_popup_list = 1 ###
14 # send focus somewhere when nothing is left with the focus, if possible ###
19 # def focus_next_stacked(data, forward=1): ###
20 # def focus_prev_stacked(data): ###
21 # def focus_next(data, num=1, forward=1): ###
22 # def focus_prev(data, num=1): ###
24 # All of these functions call be used as callbacks for bindings ###
27 ###########################################################################
32 # maintain a list of clients, stacked in focus order
34 # maintaint he current focused window
43 _clients.insert(_clients.index(_cyc_w), data.client.window())
44 _create_popup_list(data)
48 _clients.append(data.client.window())
50 _clients.insert(1, data.client.window()) # insert in 2nd slot
57 if not _doing_stacked:
58 # not in the middle of stacked cycling, so who cares
59 _clients.remove(data.client.window())
61 # have to fix the cycling if we remove anything
62 win = data.client.window()
64 _do_stacked_cycle(data, 1) # cycle off the window first, forward
66 _create_popup_list(data)
74 if not _doing_stacked: # only move the window when we're not cycling
75 win = data.client.window()
78 _clients.insert(0, win)
79 else: # if we are cycling, then update our pointer
80 _cyc_w = data.client.window()
84 desktop = ob.openbox.screen(_cyc_screen).desktop()
86 client = ob.openbox.findClient(w)
87 if client and (client.desktop() == desktop and \
88 client.normal() and client.focus()):
93 _cyc_w = 0 # last window cycled to
96 def _do_stacked_cycle(data, forward):
98 global stacked_cycle_raise
101 clients = _clients[:] # make a copy
107 i = clients.index(_cyc_w) + 1
110 clients = clients[i:] + clients[:i]
112 desktop = ob.openbox.screen(data.screen).desktop()
114 client = ob.openbox.findClient(w)
115 if client and (client.desktop() == desktop and \
116 client.normal() and client.focus()):
117 if stacked_cycle_raise:
118 ob.openbox.screen(data.screen).raiseWindow(client)
121 def _focus_stacked_ungrab(data):
124 global _doing_stacked;
126 if data.action == ob.KeyAction.Release:
127 # have all the modifiers this started with been released?
128 if not _cyc_mask & data.state:
129 ob.kungrab() # ungrab ourself
132 client = ob.openbox.findClient(_cyc_w)
134 ob.openbox.screen(data.screen).raiseWindow(client)
135 _destroy_popup_list()
141 def _hilite_popup_list():
143 global _list_widget, _list_labels, _list_windows
146 for w in _list_windows:
147 if w == _cyc_w: _list_labels[i].focus()
148 else: _list_labels[i].unfocus()
151 def _destroy_popup_list():
152 global _list_widget, _list_labels, _list_windows
158 def _create_popup_list(data):
159 global _list_widget, _list_labels, _list_windows, _clients
162 _destroy_popup_list()
164 style = ob.openbox.screen(data.screen).style()
165 _list_widget = otk.Widget(ob.openbox, style,
166 otk.Widget.Vertical, 0,
167 style.bevelWidth(), 1)
168 t = style.titlebarFocusBackground()
169 _list_widget.setTexture(t)
172 font = style.labelFont()
173 height = font.height()
176 client = ob.openbox.findClient(c)
177 desktop = ob.openbox.screen(data.screen).desktop()
178 if client and (client.desktop() == desktop and \
181 if len(t) > 50: # limit the length of titles
182 t = t[:24] + "..." + t[-24:]
184 _list_windows.append(c)
185 l = font.measureString(t) + 10 # add margin
186 if l > longest: longest = l
189 w = otk.FocusLabel(_list_widget)
190 w.resize(longest, height)
193 _list_labels.append(w)
194 _list_labels[0].focus()
195 _list_widget.update()
196 area = otk.display.screenInfo(data.screen).rect()
197 _list_widget.move(area.x() + (area.width() -
198 _list_widget.width()) / 2,
199 area.y() + (area.height() -
200 _list_widget.height()) / 2)
203 _list_widget = 0 #nothing to list
205 def focus_next_stacked(data, forward=1):
206 """Focus the next (or previous, with forward=0) window in a stacked
212 global _doing_stacked
215 if _cyc_key == data.key:
216 _do_stacked_cycle(data,forward)
218 _cyc_mask = data.state
221 _cyc_screen = data.screen
224 global stacked_cycle_popup_list
225 if stacked_cycle_popup_list:
226 _create_popup_list(data)
228 ob.kgrab(data.screen, _focus_stacked_ungrab)
229 focus_next_stacked(data, forward) # start with the first press
231 def focus_prev_stacked(data):
232 """Focus the previous window in a stacked order."""
233 focus_next_stacked(data, forward=0)
235 def focus_next(data, num=1, forward=1):
236 """Focus the next (or previous, with forward=0) window in a linear
238 screen = ob.openbox.screen(data.screen)
239 count = screen.clientCount()
241 if not count: return # no clients
245 client_win = data.client.window()
255 elif screen.client(i).window() == client_win:
257 if found == 1: # wraparound
258 if forward: target = 0
259 else: target = count - 1
262 curdesk = screen.desktop()
264 client = screen.client(t)
265 if client.normal() and \
266 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
269 screen.raiseWindow(client)
273 if t >= count: t -= count
277 if t == target: return # nothing to focus
279 def focus_prev(data, num=1):
280 """Focus the previous window in a linear order."""
281 focus_next(data, num, forward=0)
284 ob.ebind(ob.EventAction.NewWindow, _new_win)
285 ob.ebind(ob.EventAction.CloseWindow, _close_win)
286 ob.ebind(ob.EventAction.Focus, _focused)
288 print "Loaded focus.py"