]>
Dogcows Code - chaz/openbox/blob - scripts/stackedcycle.py
59dbc98e421265c961d79e453bac88e937083fa5
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
.widget
= otk
.Widget(self
.screen
.number(), ob
.openbox
,
60 otk
.Widget
.Vertical
, 0, 1)
62 def destroypopup(self
):
66 def shouldadd(self
, client
):
67 """Determines if a client should be added to the list."""
68 curdesk
= self
.screen
.desktop()
69 desk
= client
.desktop()
71 if not client
.normal(): return 0
72 if not (client
.canFocus() or client
.focusNotify()): return 0
73 if focus
.AVOID_SKIP_TASKBAR
and client
.skipTaskbar(): return 0
75 if INCLUDE_ICONS
and client
.iconic(): return 1
76 if INCLUDE_OMNIPRESENT
and desk
== 0xffffffff: return 1
77 if INCLUDE_ALL_DESKTOPS
: return 1
78 if desk
== curdesk
: return 1
82 def populatelist(self
):
83 """Populates self.clients and self.menuwidgets, and then shows and
84 positions the cycling popup."""
89 current
= self
.clients
[self
.menupos
]
90 except IndexError: current
= 0
94 # get the list of clients, keeping iconic windows at the bottom
97 for c
in focus
._clients
:
98 if c
.iconic(): iconic_clients
.append(c
)
99 else: self
.clients
.append(c
)
100 self
.clients
.extend(iconic_clients
)
104 self
.menuwidgets
= []
105 while i
< len(self
.clients
):
107 if not self
.shouldadd(c
):
108 # make the clients and menuwidgets lists match
112 w
= otk
.Label(self
.widget
)
113 if current
and c
.window() == current
.window():
116 self
.menuwidgets
.append(w
)
118 if c
.iconic(): t
= c
.iconTitle()
120 if len(t
) > TITLE_SIZE_LIMIT
: # limit the length of titles
121 t
= t
[:TITLE_SIZE_LIMIT
/ 2 - 2] + "..." + \
122 t
[0 - TITLE_SIZE_LIMIT
/ 2 - 2:]
127 # the window we were on may be gone
129 # try stay at the same spot in the menu
130 if oldpos
>= len(self
.clients
):
131 self
.menupos
= len(self
.clients
) - 1
133 self
.menupos
= oldpos
135 # find the size for the popup
138 for w
in self
.menuwidgets
:
140 if size
.width() > width
: width
= size
.width()
141 height
+= size
.height()
143 # show or hide the list and its child widgets
144 if len(self
.clients
) > 1:
145 size
= self
.screeninfo
.size()
146 self
.widget
.moveresize(otk
.Rect((size
.width() - width
) / 2,
147 (size
.height() - height
) / 2,
151 def activatetarget(self
, final
):
153 client
= self
.clients
[self
.menupos
]
154 except IndexError: return # empty list makes for this
156 # move the to client's desktop if required
157 if not (client
.iconic() or client
.desktop() == 0xffffffff or \
158 client
.desktop() == self
.screen
.desktop()):
159 root
= self
.screeninfo
.rootWindow()
160 ob
.send_client_msg(root
, otk
.atoms
.net_current_desktop
,
161 root
, client
.desktop())
163 # send a net_active_window message for the target
164 if final
or not client
.iconic():
165 if final
: r
= focuscycle
.RAISE_WINDOW
167 ob
.send_client_msg(self
.screeninfo
.rootWindow(),
168 otk
.atoms
.openbox_active_window
,
169 client
.window(), final
, r
)
171 def cycle(self
, data
, forward
):
173 ob
.kgrab(data
.screen
, _grabfunc
)
174 # the pointer grab causes pointer events during the keyboard grab
175 # to go away, which means we don't get enter notifies when the
176 # popup disappears, screwing up the focus
177 ob
.mgrab(data
.screen
)
181 self
.state
= data
.state
182 self
.screen
= ob
.openbox
.screen(data
.screen
)
183 self
.screeninfo
= otk
.display
.screenInfo(data
.screen
)
186 self
.clients
= [] # so it doesnt try start partway through the list
189 if not len(self
.clients
): return # don't both doing anything
191 self
.menuwidgets
[self
.menupos
].setHighlighted(0)
197 if self
.menupos
< 0: self
.menupos
= len(self
.clients
) - 1
198 elif self
.menupos
>= len(self
.clients
): self
.menupos
= 0
199 self
.menuwidgets
[self
.menupos
].setHighlighted(1)
200 if ACTIVATE_WHILE_CYCLING
:
201 self
.activatetarget(0) # activate, but dont deiconify/unshade/raise
203 def grabfunc(self
, data
):
206 # have all the modifiers this started with been released?
207 if (data
.action
== ob
.KeyAction
.Release
and
208 not self
.state
& data
.state
):
210 # has Escape been pressed?
211 elif data
.action
== ob
.KeyAction
.Press
and data
.key
== "Escape":
220 # activate, and deiconify/unshade/raise
221 self
.activatetarget(notreverting
)
226 def _newwindow(data
):
227 if _o
.cycling
: _o
.populatelist()
229 def _closewindow(data
):
230 if _o
.cycling
: _o
.populatelist()
235 ob
.ebind(ob
.EventAction
.NewWindow
, _newwindow
)
236 ob
.ebind(ob
.EventAction
.CloseWindow
, _closewindow
)
240 print "Loaded stackedcycle.py"
This page took 0.048893 seconds and 4 git commands to generate.