]>
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
56 _clients
.insert(_clients
.index(_cyc_w
), data
.client
.window())
57 _create_popup_list(data
)
58 _hilite_popup_list(data
)
61 _clients
.append(data
.client
.window())
63 _clients
.insert(1, data
.client
.window()) # insert in 2nd slot
70 if not _doing_stacked
:
71 # not in the middle of stacked cycling, so who cares
72 _clients
.remove(data
.client
.window())
74 # have to fix the cycling if we remove anything
75 win
= data
.client
.window()
77 _do_stacked_cycle(data
, 1) # cycle off the window first, forward
79 _create_popup_list(data
)
87 if not _doing_stacked
: # only move the window when we're not cycling
88 win
= data
.client
.window()
91 _clients
.insert(0, win
)
92 else: # if we are cycling, then update our pointer
93 _cyc_w
= data
.client
.window()
94 _hilite_popup_list(data
)
97 desktop
= ob
.openbox
.screen(_cyc_screen
).desktop()
99 client
= ob
.openbox
.findClient(w
)
100 if client
and not (avoid_skip_taskbar
and client
.skipTaskbar()) \
101 and (client
.desktop() == desktop
or
102 client
.desktop() == 0xffffffff) \
103 and client
.normal() and client
.focus():
107 _hilite_popup_list(data
)
111 _cyc_w
= 0 # last window cycled to
114 def _do_stacked_cycle(data
, forward
):
116 global stacked_cycle_raise
119 clients
= _clients
[:] # make a copy
125 i
= clients
.index(_cyc_w
) + 1
128 clients
= clients
[i
:] + clients
[:i
]
130 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
132 client
= ob
.openbox
.findClient(w
)
134 if client
and not (avoid_skip_taskbar
and client
.skipTaskbar()) and \
135 (client
.desktop() == desktop
or client
.desktop() == 0xffffffff)\
136 and client
.normal() and client
.focus():
137 if stacked_cycle_raise
:
138 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
141 def _focus_stacked_ungrab(data
):
144 global _doing_stacked
;
146 if data
.action
== ob
.KeyAction
.Release
:
147 # have all the modifiers this started with been released?
148 if not _cyc_mask
& data
.state
:
149 _destroy_popup_list()
154 client
= ob
.openbox
.findClient(_cyc_w
)
156 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
162 def _hilite_popup_list(data
):
163 global _cyc_w
, _doing_stacked
164 global _list_widget
, _list_labels
, _list_windows
167 if not _list_widget
and _doing_stacked
:
168 _create_popup_list(data
)
172 for w
in _list_windows
:
174 _list_labels
[i
].focus()
177 _list_labels
[i
].unfocus()
180 _create_popup_list(data
)
182 def _destroy_popup_list():
183 global _list_widget
, _list_labels
, _list_windows
189 def _create_popup_list(data
):
190 global avoid_skip_taskbar
191 global _list_widget
, _list_labels
, _list_windows
, _clients
194 _destroy_popup_list()
196 style
= ob
.openbox
.screen(data
.screen
).style()
197 _list_widget
= otk
.Widget(ob
.openbox
, style
,
198 otk
.Widget
.Vertical
, 0,
199 style
.bevelWidth(), 1)
200 t
= style
.titlebarFocusBackground()
201 _list_widget
.setTexture(t
)
204 font
= style
.labelFont()
205 height
= font
.height()
208 client
= ob
.openbox
.findClient(c
)
209 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
210 if client
and not (avoid_skip_taskbar
and client
.skipTaskbar()) and \
211 (client
.desktop() == desktop
or client
.desktop() == 0xffffffff)\
212 and client
.normal() and (client
.canFocus() or
213 client
.focusNotify()):
215 if len(t
) > 50: # limit the length of titles
216 t
= t
[:24] + "..." + t
[-24:]
218 _list_windows
.append(c
)
219 l
= font
.measureString(t
)
220 if l
> longest
: longest
= l
223 w
= otk
.FocusLabel(_list_widget
)
224 w
.fitSize(longest
, height
)
227 _list_labels
.append(w
)
228 _list_widget
.update()
229 area
= otk
.display
.screenInfo(data
.screen
).rect()
230 _list_widget
.move(area
.x() + (area
.width() -
231 _list_widget
.width()) / 2,
232 area
.y() + (area
.height() -
233 _list_widget
.height()) / 2)
236 _destroy_popup_list() # nothing (or only 1) to list
238 def focus_next_stacked(data
, forward
=1):
239 """Focus the next (or previous, with forward=0) window in a stacked
245 global _doing_stacked
248 if _cyc_key
== data
.key
:
249 _do_stacked_cycle(data
,forward
)
251 _cyc_mask
= data
.state
254 _cyc_screen
= data
.screen
257 global stacked_cycle_popup_list
258 if stacked_cycle_popup_list
:
259 _create_popup_list(data
)
261 ob
.kgrab(data
.screen
, _focus_stacked_ungrab
)
262 # the pointer grab causes pointer events during the keyboard grab to
263 # go away, which means we don't get enter notifies when the popup
264 # disappears, screwing up the focus
265 ob
.mgrab(data
.screen
)
266 focus_next_stacked(data
, forward
) # start with the first press
268 def focus_prev_stacked(data
):
269 """Focus the previous window in a stacked order."""
270 focus_next_stacked(data
, forward
=0)
272 def focus_next(data
, num
=1, forward
=1):
273 """Focus the next (or previous, with forward=0) window in a linear
275 global avoid_skip_taskbar
277 screen
= ob
.openbox
.screen(data
.screen
)
278 count
= screen
.clientCount()
280 if not count
: return # no clients
284 client_win
= data
.client
.window()
294 elif screen
.client(i
).window() == client_win
:
296 if found
== 1: # wraparound
297 if forward
: target
= 0
298 else: target
= count
- 1
301 curdesk
= screen
.desktop()
303 client
= screen
.client(t
)
304 if not (avoid_skip_taskbar
and client
.skipTaskbar()) and \
305 client
.normal() and (client
.desktop() == curdesk
or
306 client
.desktop() == 0xffffffff)\
309 screen
.raiseWindow(client
)
313 if t
>= count
: t
-= count
317 if t
== target
: return # nothing to focus
319 def focus_prev(data
, num
=1):
320 """Focus the previous window in a linear order."""
321 focus_next(data
, num
, forward
=0)
324 ob
.ebind(ob
.EventAction
.NewWindow
, _new_win
)
325 ob
.ebind(ob
.EventAction
.CloseWindow
, _close_win
)
326 ob
.ebind(ob
.EventAction
.Focus
, _focused
)
328 print "Loaded focus.py"
This page took 0.050598 seconds and 4 git commands to generate.