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
11 include_omnipresent = 1
13 activate_while_cycling = 1
14 ###########################################################################
17 """Focus the next window."""
21 """Focus the previous window."""
24 ###########################################################################
25 ###########################################################################
27 ###########################################################################
28 ### Internal stuff, should not be accessed outside the module. ###
29 ###########################################################################
39 def createpopup(self):
40 self.style = self.screen.style()
41 self.widget = otk.Widget(ob.openbox, self.style, otk.Widget.Vertical,
42 0, self.style.bevelWidth(), 1)
43 self.widget.setTexture(self.style.titlebarFocusBackground())
45 def destroypopup(self):
49 def shouldadd(self, client):
50 """Determines if a client should be added to the list."""
51 curdesk = self.screen.desktop()
52 desk = client.desktop()
54 if not client.normal(): return 0
55 if not (client.canFocus() or client.focusNotify()): return 0
56 if focus.avoid_skip_taskbar and client.skipTaskbar(): return 0
58 if include_icons and client.iconic(): return 1
59 if include_omnipresent and desk == 0xffffffff: return 1
60 if include_all_desktops: return 1
61 if desk == curdesk: return 1
65 def populatelist(self):
66 """Populates self.clients and self.menuwidgets, and then shows and
67 positions the cycling popup."""
72 current = self.clients[self.menupos]
73 except IndexError: current = 0
77 # get the list of clients
79 for i in focus._clients:
80 c = ob.openbox.findClient(i)
81 if c: self.clients.append(c)
83 font = self.style.labelFont()
85 height = font.height()
90 while i < len(self.clients):
92 if not self.shouldadd(c):
93 # make the clients and menuwidgets lists match
97 w = otk.FocusLabel(self.widget)
98 if current and c.window() == current.window():
103 self.menuwidgets.append(w)
105 if c.iconic(): t = c.iconTitle()
107 if len(t) > title_size_limit: # limit the length of titles
108 t = t[:title_size_limit / 2 - 2] + "..." + \
109 t[0 - title_size_limit / 2 - 2:]
110 length = font.measureString(t)
111 if length > longest: longest = length
116 # the window we were on may be gone
118 # try stay at the same spot in the menu
119 if oldpos >= len(self.clients):
120 self.menupos = len(self.clients) - 1
122 self.menupos = oldpos
124 # fit to the largest item in the menu
125 for w in self.menuwidgets:
126 w.fitSize(longest, height)
128 # show or hide the list and its child widgets
129 if len(self.clients) > 1:
130 area = self.screeninfo.rect()
132 self.widget.move(area.x() + (area.width() -
133 self.widget.width()) / 2,
134 area.y() + (area.height() -
135 self.widget.height()) / 2)
138 def activatetarget(self, final):
140 client = self.clients[self.menupos]
141 except IndexError: return # empty list makes for this
143 # move the to client's desktop if required
144 if not (client.iconic() or client.desktop() == 0xffffffff or \
145 client.desktop() == self.screen.desktop()):
146 root = self.screeninfo.rootWindow()
147 ob.send_client_msg(root, otk.Property_atoms().net_current_desktop,
148 root, client.desktop())
150 # send a net_active_window message for the target
151 if final or not client.iconic():
152 if final: r = focus.raise_window
154 ob.send_client_msg(self.screeninfo.rootWindow(),
155 otk.Property_atoms().openbox_active_window,
156 client.window(), final, r)
158 def cycle(self, data, forward):
162 self.state = data.state
163 self.screen = ob.openbox.screen(data.screen)
164 self.screeninfo = otk.display.screenInfo(data.screen)
167 self.clients = [] # so it doesnt try start partway through the list
170 ob.kgrab(self.screen.number(), _grabfunc)
171 # the pointer grab causes pointer events during the keyboard grab
172 # to go away, which means we don't get enter notifies when the
173 # popup disappears, screwing up the focus
174 ob.mgrab(self.screen.number())
176 self.menuwidgets[self.menupos].unfocus()
182 if self.menupos < 0: self.menupos = len(self.clients) - 1
183 elif self.menupos >= len(self.clients): self.menupos = 0
184 self.menuwidgets[self.menupos].focus()
185 if activate_while_cycling:
186 self.activatetarget(0) # activate, but dont deiconify/unshade/raise
188 def grabfunc(self, data):
189 if data.action == ob.KeyAction.Release:
190 # have all the modifiers this started with been released?
191 if not self.state & data.state:
194 self.activatetarget(1) # activate, and deiconify/unshade/raise
200 def _newwindow(data):
201 if _o.cycling: _o.populatelist()
203 def _closewindow(data):
204 if _o.cycling: _o.populatelist()
209 ob.ebind(ob.EventAction.NewWindow, _newwindow)
210 ob.ebind(ob.EventAction.CloseWindow, _closewindow)