]>
Dogcows Code - chaz/openbox/blob - scripts/focus.py
7bbee7e679059dd3992fa63d968e702186ce0d3b
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 ###
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())
36 _clients
.append(data
.client
.window())
38 _clients
.insert(1, data
.client
.window()) # insert in 2nd slot
45 if not _doing_stacked
:
46 # not in the middle of stacked cycling, so who cares
47 _clients
.remove(data
.client
.window())
49 # have to fix the cycling if we remove anything
50 win
= data
.client
.window()
52 _do_stacked_cycle(data
) # cycle off the window first
61 if not _doing_stacked
: # only move the window when we're not cycling
62 win
= data
.client
.window()
65 _clients
.insert(0, win
)
66 else: # if we are cycling, then update our pointer
67 _cyc_w
= data
.client
.window()
68 global _list_widget
, _list_labels
, _list_windows
71 for w
in _list_windows
:
72 if w
== _cyc_w
: _list_labels
[i
].focus()
73 else: _list_labels
[i
].unfocus()
77 desktop
= ob
.openbox
.screen(_cyc_screen
).desktop()
79 client
= ob
.openbox
.findClient(w
)
80 if client
and (client
.desktop() == desktop
and \
81 client
.normal() and client
.focus()):
86 _cyc_w
= 0 # last window cycled to
89 def _do_stacked_cycle(data
, forward
):
91 global stacked_cycle_raise
94 clients
= _clients
[:] # make a copy
100 i
= clients
.index(_cyc_w
) + 1
103 clients
= clients
[i
:] + clients
[:i
]
105 desktop
= ob
.openbox
.screen(data
.screen
).desktop()
107 client
= ob
.openbox
.findClient(w
)
108 if client
and (client
.desktop() == desktop
and \
109 client
.normal() and client
.focus()):
110 if stacked_cycle_raise
:
111 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
114 def _focus_stacked_ungrab(data
):
117 global _doing_stacked
;
119 if data
.action
== ob
.KeyAction
.Release
:
120 # have all the modifiers this started with been released?
121 if not _cyc_mask
& data
.state
:
122 ob
.kungrab() # ungrab ourself
125 client
= ob
.openbox
.findClient(_cyc_w
)
127 ob
.openbox
.screen(data
.screen
).raiseWindow(client
)
128 global _list_widget
, _list_labels
, _list_windows
138 def focus_next_stacked(data
, forward
=1):
139 """Focus the next (or previous, with forward=0) window in a stacked
145 global _doing_stacked
148 if _cyc_key
== data
.key
:
149 _do_stacked_cycle(data
,forward
)
151 _cyc_mask
= data
.state
154 _cyc_screen
= data
.screen
157 global cycle_popup_list
159 global _list_widget
, _list_labels
160 if not _list_widget
: # make the widget list
161 style
= ob
.openbox
.screen(data
.screen
).style()
162 _list_widget
= otk
.Widget(ob
.openbox
, style
,
163 otk
.Widget
.Vertical
, 0,
164 style
.bevelWidth(), 1)
165 t
= style
.labelFocusBackground()
166 _list_widget
.setTexture(t
)
169 font
= style
.labelFont()
170 height
= font
.height()
173 client
= ob
.openbox
.findClient(c
)
174 screen
= ob
.openbox
.screen(data
.screen
)
175 desktop
= screen
.desktop()
176 if client
and (client
.desktop() == desktop
and \
180 _list_windows
.append(c
)
181 l
= font
.measureString(t
)
182 if l
> longest
: longest
= l
185 w
= otk
.FocusLabel(_list_widget
)
186 w
.resize(longest
, height
)
189 _list_labels
.append(w
)
190 _list_labels
[0].focus()
191 _list_widget
.update()
193 _list_widget
.move(area
.x() + (area
.width() -
194 _list_widget
.width()) / 2,
195 area
.y() + (area
.height() -
196 _list_widget
.height()) / 2)
199 _list_widget
= 0 #nothing to list
201 ob
.kgrab(data
.screen
, _focus_stacked_ungrab
)
202 focus_next_stacked(data
, forward
) # start with the first press
204 def focus_prev_stacked(data
):
205 """Focus the previous window in a stacked order."""
206 focus_next_stacked(data
, forward
=0)
208 def focus_next(data
, num
=1, forward
=1):
209 """Focus the next (or previous, with forward=0) window in a linear
211 screen
= ob
.openbox
.screen(data
.screen
)
212 count
= screen
.clientCount()
214 if not count
: return # no clients
218 client_win
= data
.client
.window()
228 elif screen
.client(i
).window() == client_win
:
230 if found
== 1: # wraparound
231 if forward
: target
= 0
232 else: target
= count
- 1
235 curdesk
= screen
.desktop()
237 client
= screen
.client(t
)
238 if client
.normal() and \
239 (client
.desktop() == curdesk
or client
.desktop() == 0xffffffff)\
242 screen
.raiseWindow(client
)
246 if t
>= count
: t
-= count
250 if t
== target
: return # nothing to focus
252 def focus_prev(data
, num
=1):
253 """Focus the previous window in a linear order."""
254 focus_next(data
, num
, forward
=0)
257 ob
.ebind(ob
.EventAction
.NewWindow
, _new_win
)
258 ob
.ebind(ob
.EventAction
.CloseWindow
, _close_win
)
259 ob
.ebind(ob
.EventAction
.Focus
, _focused
)
261 print "Loaded focus.py"
This page took 0.04573 seconds and 4 git commands to generate.