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 ###
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())
34 _create_popup_list(data)
38 _clients.append(data.client.window())
40 _clients.insert(1, data.client.window()) # insert in 2nd slot
47 if not _doing_stacked:
48 # not in the middle of stacked cycling, so who cares
49 _clients.remove(data.client.window())
51 # have to fix the cycling if we remove anything
52 win = data.client.window()
54 _do_stacked_cycle(data, 1) # cycle off the window first, forward
56 _create_popup_list(data)
64 if not _doing_stacked: # only move the window when we're not cycling
65 win = data.client.window()
68 _clients.insert(0, win)
69 else: # if we are cycling, then update our pointer
70 _cyc_w = data.client.window()
74 desktop = ob.openbox.screen(_cyc_screen).desktop()
76 client = ob.openbox.findClient(w)
77 if client and (client.desktop() == desktop and \
78 client.normal() and client.focus()):
83 _cyc_w = 0 # last window cycled to
86 def _do_stacked_cycle(data, forward):
88 global stacked_cycle_raise
91 clients = _clients[:] # make a copy
97 i = clients.index(_cyc_w) + 1
100 clients = clients[i:] + clients[:i]
102 desktop = ob.openbox.screen(data.screen).desktop()
104 client = ob.openbox.findClient(w)
105 if client and (client.desktop() == desktop and \
106 client.normal() and client.focus()):
107 if stacked_cycle_raise:
108 ob.openbox.screen(data.screen).raiseWindow(client)
111 def _focus_stacked_ungrab(data):
114 global _doing_stacked;
116 if data.action == ob.KeyAction.Release:
117 # have all the modifiers this started with been released?
118 if not _cyc_mask & data.state:
119 ob.kungrab() # ungrab ourself
122 client = ob.openbox.findClient(_cyc_w)
124 ob.openbox.screen(data.screen).raiseWindow(client)
125 _destroy_popup_list()
131 def _hilite_popup_list():
133 global _list_widget, _list_labels, _list_windows
136 for w in _list_windows:
137 if w == _cyc_w: _list_labels[i].focus()
138 else: _list_labels[i].unfocus()
141 def _destroy_popup_list():
142 global _list_widget, _list_labels, _list_windows
148 def _create_popup_list(data):
149 global _list_widget, _list_labels, _list_windows, _clients
152 _destroy_popup_list()
154 style = ob.openbox.screen(data.screen).style()
155 _list_widget = otk.Widget(ob.openbox, style,
156 otk.Widget.Vertical, 0,
157 style.bevelWidth(), 1)
158 t = style.titlebarFocusBackground()
159 _list_widget.setTexture(t)
162 font = style.labelFont()
163 height = font.height()
166 client = ob.openbox.findClient(c)
167 desktop = ob.openbox.screen(data.screen).desktop()
168 if client and (client.desktop() == desktop and \
171 if len(t) > 50: # limit the length of titles
172 t = t[:24] + "..." + t[-24:]
174 _list_windows.append(c)
175 l = font.measureString(t) + 10 # add margin
176 if l > longest: longest = l
179 w = otk.FocusLabel(_list_widget)
180 w.resize(longest, height)
183 _list_labels.append(w)
184 _list_labels[0].focus()
185 _list_widget.update()
186 area = otk.display.screenInfo(data.screen).rect()
187 _list_widget.move(area.x() + (area.width() -
188 _list_widget.width()) / 2,
189 area.y() + (area.height() -
190 _list_widget.height()) / 2)
193 _list_widget = 0 #nothing to list
195 def focus_next_stacked(data, forward=1):
196 """Focus the next (or previous, with forward=0) window in a stacked
202 global _doing_stacked
205 if _cyc_key == data.key:
206 _do_stacked_cycle(data,forward)
208 _cyc_mask = data.state
211 _cyc_screen = data.screen
214 global stacked_cycle_popup_list
215 if stacked_cycle_popup_list:
216 _create_popup_list(data)
218 ob.kgrab(data.screen, _focus_stacked_ungrab)
219 focus_next_stacked(data, forward) # start with the first press
221 def focus_prev_stacked(data):
222 """Focus the previous window in a stacked order."""
223 focus_next_stacked(data, forward=0)
225 def focus_next(data, num=1, forward=1):
226 """Focus the next (or previous, with forward=0) window in a linear
228 screen = ob.openbox.screen(data.screen)
229 count = screen.clientCount()
231 if not count: return # no clients
235 client_win = data.client.window()
245 elif screen.client(i).window() == client_win:
247 if found == 1: # wraparound
248 if forward: target = 0
249 else: target = count - 1
252 curdesk = screen.desktop()
254 client = screen.client(t)
255 if client.normal() and \
256 (client.desktop() == curdesk or client.desktop() == 0xffffffff)\
259 screen.raiseWindow(client)
263 if t >= count: t -= count
267 if t == target: return # nothing to focus
269 def focus_prev(data, num=1):
270 """Focus the previous window in a linear order."""
271 focus_next(data, num, forward=0)
274 ob.ebind(ob.EventAction.NewWindow, _new_win)
275 ob.ebind(ob.EventAction.CloseWindow, _close_win)
276 ob.ebind(ob.EventAction.Focus, _focused)
278 print "Loaded focus.py"