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."""
32 """Focus the previous window."""
35 ###########################################################################
36 ###########################################################################
38 ###########################################################################
39 ### Internal stuff, should not be accessed outside the module. ###
40 ###########################################################################
50 def createpopup(self):
51 self.style = self.screen.style()
52 self.widget = otk.Widget(ob.openbox, self.style, otk.Widget.Vertical,
53 0, self.style.bevelWidth(), 1)
54 self.widget.setTexture(self.style.titlebarFocusBackground())
56 def destroypopup(self):
60 def shouldadd(self, client):
61 """Determines if a client should be added to the list."""
62 curdesk = self.screen.desktop()
63 desk = client.desktop()
65 if not client.normal(): return 0
66 if not (client.canFocus() or client.focusNotify()): return 0
67 if focus.avoid_skip_taskbar and client.skipTaskbar(): return 0
69 if include_icons and client.iconic(): return 1
70 if include_omnipresent and desk == 0xffffffff: return 1
71 if include_all_desktops: return 1
72 if desk == curdesk: return 1
76 def populatelist(self):
77 """Populates self.clients and self.menuwidgets, and then shows and
78 positions the cycling popup."""
83 current = self.clients[self.menupos]
84 except IndexError: current = 0
88 # get the list of clients
90 for i in focus._clients:
91 c = ob.openbox.findClient(i)
92 if c: self.clients.append(c)
94 font = self.style.labelFont()
96 height = font.height()
100 self.menuwidgets = []
101 while i < len(self.clients):
103 if not self.shouldadd(c):
104 # make the clients and menuwidgets lists match
108 w = otk.FocusLabel(self.widget)
109 if current and c.window() == current.window():
114 self.menuwidgets.append(w)
116 if c.iconic(): t = c.iconTitle()
118 if len(t) > title_size_limit: # limit the length of titles
119 t = t[:title_size_limit / 2 - 2] + "..." + \
120 t[0 - title_size_limit / 2 - 2:]
121 length = font.measureString(t)
122 if length > longest: longest = length
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 # fit to the largest item in the menu
136 for w in self.menuwidgets:
137 w.fitSize(longest, height)
139 # show or hide the list and its child widgets
140 if len(self.clients) > 1:
141 area = self.screeninfo.rect()
143 self.widget.move(area.x() + (area.width() -
144 self.widget.width()) / 2,
145 area.y() + (area.height() -
146 self.widget.height()) / 2)
149 def activatetarget(self, final):
151 client = self.clients[self.menupos]
152 except IndexError: return # empty list makes for this
154 # move the to client's desktop if required
155 if not (client.iconic() or client.desktop() == 0xffffffff or \
156 client.desktop() == self.screen.desktop()):
157 root = self.screeninfo.rootWindow()
158 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
159 root, client.desktop())
161 # send a net_active_window message for the target
162 if final or not client.iconic():
163 if final: r = focus.raise_window
165 ob.send_client_msg(self.screeninfo.rootWindow(),
166 otk.Property_atoms().openbox_active_window,
167 client.window(), final, r)
169 def cycle(self, data, forward):
173 self.state = data.state
174 self.screen = ob.openbox.screen(data.screen)
175 self.screeninfo = otk.display.screenInfo(data.screen)
178 self.clients = [] # so it doesnt try start partway through the list
181 ob.kgrab(self.screen.number(), _grabfunc)
182 # the pointer grab causes pointer events during the keyboard grab
183 # to go away, which means we don't get enter notifies when the
184 # popup disappears, screwing up the focus
185 ob.mgrab(self.screen.number())
187 self.menuwidgets[self.menupos].unfocus()
193 if self.menupos < 0: self.menupos = len(self.clients) - 1
194 elif self.menupos >= len(self.clients): self.menupos = 0
195 self.menuwidgets[self.menupos].focus()
196 if activate_while_cycling:
197 self.activatetarget(0) # activate, but dont deiconify/unshade/raise
199 def grabfunc(self, data):
200 if data.action == ob.KeyAction.Release:
201 # have all the modifiers this started with been released?
202 if not self.state & data.state:
205 self.activatetarget(1) # activate, and deiconify/unshade/raise
211 def _newwindow(data):
212 if _o.cycling: _o.populatelist()
214 def _closewindow(data):
215 if _o.cycling: _o.populatelist()
220 ob.ebind(ob.EventAction.NewWindow, _newwindow)
221 ob.ebind(ob.EventAction.CloseWindow, _closewindow)