]>
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 ### Also see the options in the focus module. ###
8 ###########################################################################
9 include_all_desktops
= 0
10 """If this is non-zero then windows from all desktops will be included in
13 """If this is non-zero then windows which are iconified will be included
14 in the stacking list."""
15 include_omnipresent
= 1
16 """If this is non-zero then windows which are on all-desktops at once will
19 """This specifies a rough limit of characters for the cycling list titles.
20 Titles which are larger will be chopped with an elipsis in their
22 activate_while_cycling
= 1
23 """If this is non-zero then windows will be activated as they are
24 highlighted in the cycling list (except iconified windows)."""
25 ###########################################################################
28 """Focus the next window."""
30 raise RuntimeError("stackedcycle.next must be bound to a key" +
31 "combination with at least one modifier")
35 """Focus the previous window."""
37 raise RuntimeError("stackedcycle.previous must be bound to a key" +
38 "combination with at least one modifier")
41 ###########################################################################
42 ###########################################################################
44 ###########################################################################
45 ### Internal stuff, should not be accessed outside the module. ###
46 ###########################################################################
56 def createpopup(self
):
57 self
.style
= self
.screen
.style()
58 self
.widget
= otk
.Widget(ob
.openbox
, self
.style
, otk
.Widget
.Vertical
,
59 0, self
.style
.bevelWidth(), 1)
60 self
.widget
.setTexture(self
.style
.titlebarFocusBackground())
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
96 for i
in focus
._clients
:
97 c
= ob
.openbox
.findClient(i
)
98 if c
: self
.clients
.append(c
)
100 font
= self
.style
.labelFont()
102 height
= font
.height()
106 self
.menuwidgets
= []
107 while i
< len(self
.clients
):
109 if not self
.shouldadd(c
):
110 # make the clients and menuwidgets lists match
114 w
= otk
.FocusLabel(self
.widget
)
115 if current
and c
.window() == current
.window():
120 self
.menuwidgets
.append(w
)
122 if c
.iconic(): t
= c
.iconTitle()
124 if len(t
) > title_size_limit
: # limit the length of titles
125 t
= t
[:title_size_limit
/ 2 - 2] + "..." + \
126 t
[0 - title_size_limit
/ 2 - 2:]
127 length
= font
.measureString(t
)
128 if length
> longest
: longest
= length
133 # the window we were on may be gone
135 # try stay at the same spot in the menu
136 if oldpos
>= len(self
.clients
):
137 self
.menupos
= len(self
.clients
) - 1
139 self
.menupos
= oldpos
141 # fit to the largest item in the menu
142 for w
in self
.menuwidgets
:
143 w
.fitSize(longest
, height
)
145 # show or hide the list and its child widgets
146 if len(self
.clients
) > 1:
147 area
= self
.screeninfo
.rect()
149 self
.widget
.move(area
.x() + (area
.width() -
150 self
.widget
.width()) / 2,
151 area
.y() + (area
.height() -
152 self
.widget
.height()) / 2)
155 def activatetarget(self
, final
):
157 client
= self
.clients
[self
.menupos
]
158 except IndexError: return # empty list makes for this
160 # move the to client's desktop if required
161 if not (client
.iconic() or client
.desktop() == 0xffffffff or \
162 client
.desktop() == self
.screen
.desktop()):
163 root
= self
.screeninfo
.rootWindow()
164 ob
.send_client_msg(root
, otk
.Property_atoms().net_current_desktop
,
165 root
, client
.desktop())
167 # send a net_active_window message for the target
168 if final
or not client
.iconic():
169 if final
: r
= focus
.raise_window
171 ob
.send_client_msg(self
.screeninfo
.rootWindow(),
172 otk
.Property_atoms().openbox_active_window
,
173 client
.window(), final
, r
)
175 def cycle(self
, data
, forward
):
179 self
.state
= data
.state
180 self
.screen
= ob
.openbox
.screen(data
.screen
)
181 self
.screeninfo
= otk
.display
.screenInfo(data
.screen
)
184 self
.clients
= [] # so it doesnt try start partway through the list
187 ob
.kgrab(self
.screen
.number(), _grabfunc
)
188 # the pointer grab causes pointer events during the keyboard grab
189 # to go away, which means we don't get enter notifies when the
190 # popup disappears, screwing up the focus
191 ob
.mgrab(self
.screen
.number())
193 self
.menuwidgets
[self
.menupos
].unfocus()
199 if self
.menupos
< 0: self
.menupos
= len(self
.clients
) - 1
200 elif self
.menupos
>= len(self
.clients
): self
.menupos
= 0
201 self
.menuwidgets
[self
.menupos
].focus()
202 if activate_while_cycling
:
203 self
.activatetarget(0) # activate, but dont deiconify/unshade/raise
205 def grabfunc(self
, data
):
207 # have all the modifiers this started with been released?
208 if (data
.action
== ob
.KeyAction
.Release
and
209 not self
.state
& data
.state
):
211 # has Escape been pressed?
212 if data
.action
== ob
.KeyAction
.Press
and data
.key
== "Escape":
220 self
.activatetarget(1) # activate, and deiconify/unshade/raise
225 def _newwindow(data
):
226 if _o
.cycling
: _o
.populatelist()
228 def _closewindow(data
):
229 if _o
.cycling
: _o
.populatelist()
234 ob
.ebind(ob
.EventAction
.NewWindow
, _newwindow
)
235 ob
.ebind(ob
.EventAction
.CloseWindow
, _closewindow
)
This page took 0.046422 seconds and 5 git commands to generate.