]>
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 # 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 # """Focus the next (or previous, with forward=0) window in a stacked ###
22 # def focus_prev_stacked(data): ###
23 # """Focus the previous window in a stacked order.""" ###
24 # def focus_next(data, num=1, forward=1): ###
25 # """Focus the next (or previous, with forward=0) window in a linear ###
27 # def focus_prev(data, num=1): ###
28 # """Focus the previous window in a linear order.""" ###
30 # All of these functions call be used as callbacks for bindings ###
33 ###########################################################################
38 # maintain a list of clients, stacked in focus order
40 # maintaint he current focused window
49 _clients
.insert(_clients
.index(_cyc_w
), data
.client
.window())
50 _create_popup_list(data
)
51 _hilite_popup_list(data
)
54 _clients
.append(data
.client
.window())
56 _clients
.insert(1, data
.client
.window()) # insert in 2nd slot
63 if not _doing_stacked
:
64 # not in the middle of stacked cycling, so who cares
65 _clients
.remove(data
.client
.window())
67 # have to fix the cycling if we remove anything
68 win
= data
.client
.window()
70 _do_stacked_cycle(data
, 1) # cycle off the window first, forward
72 _create_popup_list(data
)
80 if not _doing_stacked
: # only move the window when we're not cycling
81 win
= data
.client
.window()
84 _clients
.insert(0, win
)
85 else: # if we are cycling, then update our pointer
86 _cyc_w
= data
.client
.window()
87 _hilite_popup_list(data
)
90 desktop
= ob
.openbox
.screen(_cyc_screen
).desktop()
92 client
= ob
.openbox
.findClient(w
)
93 if client
and (client
.desktop() == desktop
and \
94 client
.normal() and client
.focus()):
98 _hilite_popup_list(data
)
102 _cyc_w
= 0 # last window cycled to
105 def _do_stacked_cycle(data
, forward
):
107 global stacked_cycle_raise
110 clients
= _clients
[:] # make a copy
116 i
= clients
.index(_cyc_w
) + 1
119 clients
= clients
[i
:] + clients
[:i
]
121 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
123 client
= ob
.openbox
.findClient(w
)
124 if client
and (client
.desktop() == desktop
and \
125 client
.normal() and client
.focus()):
126 if stacked_cycle_raise
:
127 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
130 def _focus_stacked_ungrab(data
):
133 global _doing_stacked
;
135 if data
.action
== ob
.KeyAction
.Release
:
136 # have all the modifiers this started with been released?
137 if not _cyc_mask
& data
.state
:
138 _destroy_popup_list()
139 ob
.kungrab() # ungrab ourself
142 client
= ob
.openbox
.findClient(_cyc_w
)
144 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
150 def _hilite_popup_list(data
):
151 global _cyc_w
, _doing_stacked
152 global _list_widget
, _list_labels
, _list_windows
155 if not _list_widget
and _doing_stacked
:
156 _create_popup_list(data
)
160 for w
in _list_windows
:
162 _list_labels
[i
].focus()
165 _list_labels
[i
].unfocus()
168 _create_popup_list(data
)
170 def _destroy_popup_list():
171 global _list_widget
, _list_labels
, _list_windows
177 def _create_popup_list(data
):
178 global _list_widget
, _list_labels
, _list_windows
, _clients
181 _destroy_popup_list()
183 style
= ob
.openbox
.screen(data
.screen
).style()
184 _list_widget
= otk
.Widget(ob
.openbox
, style
,
185 otk
.Widget
.Vertical
, 0,
186 style
.bevelWidth(), 1)
187 t
= style
.titlebarFocusBackground()
188 _list_widget
.setTexture(t
)
191 font
= style
.labelFont()
192 height
= font
.height()
195 client
= ob
.openbox
.findClient(c
)
196 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
197 if client
and ((client
.desktop() == desktop
or
198 client
.desktop() == 0xffffffff) and \
199 client
.normal() and (client
.canFocus() or
200 client
.focusNotify())):
202 if len(t
) > 50: # limit the length of titles
203 t
= t
[:24] + "..." + t
[-24:]
205 _list_windows
.append(c
)
206 l
= font
.measureString(t
) + 10 # add margin
207 if l
> longest
: longest
= l
210 w
= otk
.FocusLabel(_list_widget
)
211 w
.resize(longest
, height
)
214 _list_labels
.append(w
)
215 _list_widget
.update()
216 area
= otk
.display
.screenInfo(data
.screen
).rect()
217 _list_widget
.move(area
.x() + (area
.width() -
218 _list_widget
.width()) / 2,
219 area
.y() + (area
.height() -
220 _list_widget
.height()) / 2)
223 _destroy_popup_list() # nothing (or only 1) to list
225 def focus_next_stacked(data
, forward
=1):
226 """Focus the next (or previous, with forward=0) window in a stacked
232 global _doing_stacked
235 if _cyc_key
== data
.key
:
236 _do_stacked_cycle(data
,forward
)
238 _cyc_mask
= data
.state
241 _cyc_screen
= data
.screen
244 global stacked_cycle_popup_list
245 if stacked_cycle_popup_list
:
246 _create_popup_list(data
)
248 ob
.kgrab(data
.screen
, _focus_stacked_ungrab
)
249 focus_next_stacked(data
, forward
) # start with the first press
251 def focus_prev_stacked(data
):
252 """Focus the previous window in a stacked order."""
253 focus_next_stacked(data
, forward
=0)
255 def focus_next(data
, num
=1, forward
=1):
256 """Focus the next (or previous, with forward=0) window in a linear
258 screen
= ob
.openbox
.screen(data
.screen
)
259 count
= screen
.clientCount()
261 if not count
: return # no clients
265 client_win
= data
.client
.window()
275 elif screen
.client(i
).window() == client_win
:
277 if found
== 1: # wraparound
278 if forward
: target
= 0
279 else: target
= count
- 1
282 curdesk
= screen
.desktop()
284 client
= screen
.client(t
)
285 if client
.normal() and \
286 (client
.desktop() == curdesk
or client
.desktop() == 0xffffffff)\
289 screen
.raiseWindow(client
)
293 if t
>= count
: t
-= count
297 if t
== target
: return # nothing to focus
299 def focus_prev(data
, num
=1):
300 """Focus the previous window in a linear order."""
301 focus_next(data
, num
, forward
=0)
304 ob
.ebind(ob
.EventAction
.NewWindow
, _new_win
)
305 ob
.ebind(ob
.EventAction
.CloseWindow
, _close_win
)
306 ob
.ebind(ob
.EventAction
.Focus
, _focused
)
308 print "Loaded focus.py"
This page took 0.046628 seconds and 4 git commands to generate.