]>
Dogcows Code - chaz/openbox/blob - scripts/focus.py
1 ###########################################################################
2 ### Functions for helping out with your window focus. ###
3 ###########################################################################
5 ###########################################################################
6 ### Options that affect the behavior of the focus module. ###
8 # cycle_raise - raise the window also when it is focused ###
10 # avoid_skip_taskbar - Don't focus windows which have requested to not ###
11 ### be displayed in taskbars. You will still be able ###
12 ### to focus the windows, but not through cycling, ###
13 ### and they won't be focused as a fallback if ###
14 ### 'fallback' is enabled. ###
15 avoid_skip_taskbar
= 1 ###
16 # stacked_cycle_raise - raise as you cycle in stacked mode ###
17 stacked_cycle_raise
= 0 ###
18 # stacked_cycle_popup_list - show a pop-up list of windows while ###
20 stacked_cycle_popup_list
= 1 ###
21 # send focus somewhere when nothing is left with the focus, if possible ###
26 # def focus_next_stacked(data, forward=1): ###
27 # """Focus the next (or previous, with forward=0) window in a stacked ###
29 # def focus_prev_stacked(data): ###
30 # """Focus the previous window in a stacked order.""" ###
31 # def focus_next(data, num=1, forward=1): ###
32 # """Focus the next (or previous, with forward=0) window in a linear ###
34 # def focus_prev(data, num=1): ###
35 # """Focus the previous window in a linear order.""" ###
37 # All of these functions call be used as callbacks for bindings ###
40 ###########################################################################
45 # maintain a list of clients, stacked in focus order
47 # maintaint he current focused window
50 def _focusable(client
, desktop
):
51 if not (avoid_skip_taskbar
and client
.skipTaskbar()) and \
52 (client
.desktop() == desktop
or client
.desktop() == 0xffffffff) and \
53 client
.normal() and (client
.canFocus() or client
.focusNotify()):
63 _clients
.insert(_clients
.index(_cyc_w
), data
.client
.window())
64 _create_popup_list(data
)
65 _hilite_popup_list(data
)
68 _clients
.append(data
.client
.window())
70 _clients
.insert(1, data
.client
.window()) # insert in 2nd slot
77 if not _doing_stacked
:
78 # not in the middle of stacked cycling, so who cares
79 _clients
.remove(data
.client
.window())
81 # have to fix the cycling if we remove anything
82 win
= data
.client
.window()
84 _do_stacked_cycle(data
, 1) # cycle off the window first, forward
86 _create_popup_list(data
)
94 if not _doing_stacked
: # only move the window when we're not cycling
95 win
= data
.client
.window()
98 _clients
.insert(0, win
)
99 else: # if we are cycling, then update our pointer
100 _cyc_w
= data
.client
.window()
101 _hilite_popup_list(data
)
104 desktop
= ob
.openbox
.screen(_cyc_screen
).desktop()
106 client
= ob
.openbox
.findClient(w
)
107 if client
and _focusable(client
, desktop
) and client
.focus():
111 _hilite_popup_list(data
)
115 _cyc_w
= 0 # last window cycled to
118 def _do_stacked_cycle(data
, forward
):
120 global stacked_cycle_raise
123 clients
= _clients
[:] # make a copy
129 i
= clients
.index(_cyc_w
) + 1
132 clients
= clients
[i
:] + clients
[:i
]
134 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
136 client
= ob
.openbox
.findClient(w
)
138 if client
and _focusable(client
, desktop
) and client
.focus():
139 if stacked_cycle_raise
:
140 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
143 def _focus_stacked_ungrab(data
):
146 global _doing_stacked
;
148 if data
.action
== ob
.KeyAction
.Release
:
149 # have all the modifiers this started with been released?
150 if not _cyc_mask
& data
.state
:
151 _destroy_popup_list()
155 client
= ob
.openbox
.findClient(_cyc_w
)
158 #_focused(data) # resort the list as appropriate
160 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
166 def _hilite_popup_list(data
):
167 global _cyc_w
, _doing_stacked
168 global _list_widget
, _list_labels
, _list_windows
171 if not _list_widget
and _doing_stacked
:
172 _create_popup_list(data
)
176 for w
in _list_windows
:
178 _list_labels
[i
].focus()
181 _list_labels
[i
].unfocus()
184 _create_popup_list(data
)
186 def _destroy_popup_list():
187 global _list_widget
, _list_labels
, _list_windows
193 def _create_popup_list(data
):
194 global avoid_skip_taskbar
195 global _list_widget
, _list_labels
, _list_windows
, _clients
198 _destroy_popup_list()
200 style
= ob
.openbox
.screen(data
.screen
).style()
201 _list_widget
= otk
.Widget(ob
.openbox
, style
,
202 otk
.Widget
.Vertical
, 0,
203 style
.bevelWidth(), 1)
204 t
= style
.titlebarFocusBackground()
205 _list_widget
.setTexture(t
)
208 font
= style
.labelFont()
209 height
= font
.height()
211 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
213 client
= ob
.openbox
.findClient(c
)
214 if client
and _focusable(client
, desktop
):
216 if len(t
) > 50: # limit the length of titles
217 t
= t
[:24] + "..." + t
[-24:]
219 _list_windows
.append(c
)
220 l
= font
.measureString(t
)
221 if l
> longest
: longest
= l
224 w
= otk
.FocusLabel(_list_widget
)
225 w
.fitSize(longest
, height
)
228 _list_labels
.append(w
)
229 _list_widget
.update()
230 area
= otk
.display
.screenInfo(data
.screen
).rect()
231 _list_widget
.move(area
.x() + (area
.width() -
232 _list_widget
.width()) / 2,
233 area
.y() + (area
.height() -
234 _list_widget
.height()) / 2)
237 _destroy_popup_list() # nothing (or only 1) to list
239 def focus_next_stacked(data
, forward
=1):
240 """Focus the next (or previous, with forward=0) window in a stacked
246 global _doing_stacked
249 if _cyc_key
== data
.key
:
250 _do_stacked_cycle(data
,forward
)
252 _cyc_mask
= data
.state
255 _cyc_screen
= data
.screen
258 global stacked_cycle_popup_list
259 if stacked_cycle_popup_list
:
260 _create_popup_list(data
)
262 ob
.kgrab(data
.screen
, _focus_stacked_ungrab
)
263 # the pointer grab causes pointer events during the keyboard grab to
264 # go away, which means we don't get enter notifies when the popup
265 # disappears, screwing up the focus
266 ob
.mgrab(data
.screen
)
267 focus_next_stacked(data
, forward
) # start with the first press
269 def focus_prev_stacked(data
):
270 """Focus the previous window in a stacked order."""
271 focus_next_stacked(data
, forward
=0)
273 def focus_next(data
, num
=1, forward
=1):
274 """Focus the next (or previous, with forward=0) window in a linear
276 global avoid_skip_taskbar
278 screen
= ob
.openbox
.screen(data
.screen
)
279 count
= screen
.clientCount()
281 if not count
: return # no clients
285 client_win
= data
.client
.window()
295 elif screen
.client(i
).window() == client_win
:
297 if found
== 1: # wraparound
298 if forward
: target
= 0
299 else: target
= count
- 1
302 desktop
= screen
.desktop()
304 client
= screen
.client(t
)
305 if client
and _focusable(client
, desktop
) and client
.focus():
307 screen
.raiseWindow(client
)
311 if t
>= count
: t
-= count
315 if t
== target
: return # nothing to focus
317 def focus_prev(data
, num
=1):
318 """Focus the previous window in a linear order."""
319 focus_next(data
, num
, forward
=0)
322 ob
.ebind(ob
.EventAction
.NewWindow
, _new_win
)
323 ob
.ebind(ob
.EventAction
.CloseWindow
, _close_win
)
324 ob
.ebind(ob
.EventAction
.Focus
, _focused
)
326 print "Loaded focus.py"
This page took 0.050688 seconds and 4 git commands to generate.