]>
Dogcows Code - chaz/openbox/blob - scripts/stackedcycle.py
1 ###########################################################################
2 ### Functions for cycling focus (in a 'stacked' order) between windows. ###
3 ###########################################################################
5 ###########################################################################
6 ### Options that affect the behavior of the stackedcycle module. ###
7 ###########################################################################
8 INCLUDE_ALL_DESKTOPS
= 0
9 """If this is non-zero then windows from all desktops will be included in
12 """If this is non-zero then windows which are iconified will be included
13 in the stacking list."""
14 INCLUDE_OMNIPRESENT
= 1
15 """If this is non-zero then windows which are on all-desktops at once will
18 """This specifies a rough limit of characters for the cycling list titles.
19 Titles which are larger will be chopped with an elipsis in their
21 ACTIVATE_WHILE_CYCLING
= 1
22 """If this is non-zero then windows will be activated as they are
23 highlighted in the cycling list (except iconified windows)."""
24 # See focus.AVOID_SKIP_TASKBAR
25 # See focuscycle.RAISE_WINDOW
26 ###########################################################################
29 """Focus the next window."""
31 raise RuntimeError("stackedcycle.next must be bound to a key" +
32 "combination with at least one modifier")
36 """Focus the previous window."""
38 raise RuntimeError("stackedcycle.previous must be bound to a key" +
39 "combination with at least one modifier")
42 ###########################################################################
43 ###########################################################################
45 ###########################################################################
46 ### Internal stuff, should not be accessed outside the module. ###
47 ###########################################################################
58 def createpopup(self
):
59 self
.style
= self
.screen
.style()
60 self
.widget
= otk
.Widget(ob
.openbox
, self
.style
, otk
.Widget
.Vertical
,
61 0, self
.style
.bevelWidth(), 1)
62 self
.widget
.setTexture(self
.style
.titlebarFocusBackground())
64 def destroypopup(self
):
68 def shouldadd(self
, client
):
69 """Determines if a client should be added to the list."""
70 curdesk
= self
.screen
.desktop()
71 desk
= client
.desktop()
73 if not client
.normal(): return 0
74 if not (client
.canFocus() or client
.focusNotify()): return 0
75 if focus
.AVOID_SKIP_TASKBAR
and client
.skipTaskbar(): return 0
77 if INCLUDE_ICONS
and client
.iconic(): return 1
78 if INCLUDE_OMNIPRESENT
and desk
== 0xffffffff: return 1
79 if INCLUDE_ALL_DESKTOPS
: return 1
80 if desk
== curdesk
: return 1
84 def populatelist(self
):
85 """Populates self.clients and self.menuwidgets, and then shows and
86 positions the cycling popup."""
91 current
= self
.clients
[self
.menupos
]
92 except IndexError: current
= 0
96 # get the list of clients, keeping iconic windows at the bottom
99 for c
in focus
._clients
:
100 if c
.iconic(): iconic_clients
.append(c
)
101 else: self
.clients
.append(c
)
102 self
.clients
.extend(iconic_clients
)
104 font
= self
.style
.labelFont()
106 height
= font
.height()
110 self
.menuwidgets
= []
111 while i
< len(self
.clients
):
113 if not self
.shouldadd(c
):
114 # make the clients and menuwidgets lists match
118 w
= otk
.FocusLabel(self
.widget
)
119 if current
and c
.window() == current
.window():
124 self
.menuwidgets
.append(w
)
126 if c
.iconic(): t
= c
.iconTitle()
128 if len(t
) > TITLE_SIZE_LIMIT
: # limit the length of titles
129 t
= t
[:TITLE_SIZE_LIMIT
/ 2 - 2] + "..." + \
130 t
[0 - TITLE_SIZE_LIMIT
/ 2 - 2:]
131 length
= font
.measureString(t
)
132 if length
> longest
: longest
= length
137 # the window we were on may be gone
139 # try stay at the same spot in the menu
140 if oldpos
>= len(self
.clients
):
141 self
.menupos
= len(self
.clients
) - 1
143 self
.menupos
= oldpos
145 # fit to the largest item in the menu
146 for w
in self
.menuwidgets
:
147 w
.fitSize(longest
, height
)
149 # show or hide the list and its child widgets
150 if len(self
.clients
) > 1:
151 area
= self
.screeninfo
.rect()
153 self
.widget
.move(area
.x() + (area
.width() -
154 self
.widget
.width()) / 2,
155 area
.y() + (area
.height() -
156 self
.widget
.height()) / 2)
159 def activatetarget(self
, final
):
161 client
= self
.clients
[self
.menupos
]
162 except IndexError: return # empty list makes for this
164 # move the to client's desktop if required
165 if not (client
.iconic() or client
.desktop() == 0xffffffff or \
166 client
.desktop() == self
.screen
.desktop()):
167 root
= self
.screeninfo
.rootWindow()
168 ob
.send_client_msg(root
, otk
.atoms
.net_current_desktop
,
169 root
, client
.desktop())
171 # send a net_active_window message for the target
172 if final
or not client
.iconic():
173 if final
: r
= focuscycle
.RAISE_WINDOW
175 ob
.send_client_msg(self
.screeninfo
.rootWindow(),
176 otk
.atoms
.openbox_active_window
,
177 client
.window(), final
, r
)
179 def cycle(self
, data
, forward
):
183 self
.state
= data
.state
184 self
.screen
= ob
.openbox
.screen(data
.screen
)
185 self
.screeninfo
= otk
.display
.screenInfo(data
.screen
)
188 self
.clients
= [] # so it doesnt try start partway through the list
191 ob
.kgrab(self
.screen
.number(), _grabfunc
)
192 # the pointer grab causes pointer events during the keyboard grab
193 # to go away, which means we don't get enter notifies when the
194 # popup disappears, screwing up the focus
195 ob
.mgrab(self
.screen
.number())
197 if not len(self
.clients
): return # don't both doing anything
199 self
.menuwidgets
[self
.menupos
].unfocus()
205 if self
.menupos
< 0: self
.menupos
= len(self
.clients
) - 1
206 elif self
.menupos
>= len(self
.clients
): self
.menupos
= 0
207 self
.menuwidgets
[self
.menupos
].focus()
208 if ACTIVATE_WHILE_CYCLING
:
209 self
.activatetarget(0) # activate, but dont deiconify/unshade/raise
211 def grabfunc(self
, data
):
214 # have all the modifiers this started with been released?
215 if (data
.action
== ob
.KeyAction
.Release
and
216 not self
.state
& data
.state
):
218 # has Escape been pressed?
219 elif data
.action
== ob
.KeyAction
.Press
and data
.key
== "Escape":
228 # activate, and deiconify/unshade/raise
229 self
.activatetarget(notreverting
)
234 def _newwindow(data
):
235 if _o
.cycling
: _o
.populatelist()
237 def _closewindow(data
):
238 if _o
.cycling
: _o
.populatelist()
243 ob
.ebind(ob
.EventAction
.NewWindow
, _newwindow
)
244 ob
.ebind(ob
.EventAction
.CloseWindow
, _closewindow
)
248 print "Loaded stackedcycle.py"
This page took 0.048028 seconds and 4 git commands to generate.