Changeset View
Changeset View
Standalone View
Standalone View
focuschain.cpp
Show All 35 Lines | |||||
36 | 36 | | |||
37 | FocusChain::~FocusChain() | 37 | FocusChain::~FocusChain() | ||
38 | { | 38 | { | ||
39 | s_manager = NULL; | 39 | s_manager = NULL; | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | void FocusChain::remove(AbstractClient *client) | 42 | void FocusChain::remove(AbstractClient *client) | ||
43 | { | 43 | { | ||
44 | for (DesktopChains::iterator it = m_desktopFocusChains.begin(); | 44 | for (auto it = m_desktopFocusChains.begin(); | ||
45 | it != m_desktopFocusChains.end(); | 45 | it != m_desktopFocusChains.end(); | ||
46 | ++it) { | 46 | ++it) { | ||
47 | it.value().removeAll(client); | 47 | it.value().removeAll(client); | ||
48 | } | 48 | } | ||
49 | m_mostRecentlyUsed.removeAll(client); | 49 | m_mostRecentlyUsed.removeAll(client); | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | void FocusChain::resize(uint previousSize, uint newSize) | 52 | void FocusChain::resize(uint previousSize, uint newSize) | ||
53 | { | 53 | { | ||
54 | for (uint i = previousSize + 1; i <= newSize; ++i) { | 54 | for (uint i = previousSize + 1; i <= newSize; ++i) { | ||
55 | m_desktopFocusChains.insert(i, QList<AbstractClient*>()); | 55 | m_desktopFocusChains.insert(i, Chain()); | ||
56 | } | 56 | } | ||
57 | for (uint i = previousSize; i > newSize; --i) { | 57 | for (uint i = previousSize; i > newSize; --i) { | ||
58 | m_desktopFocusChains.remove(i); | 58 | m_desktopFocusChains.remove(i); | ||
59 | } | 59 | } | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | AbstractClient *FocusChain::getForActivation(uint desktop) const | 62 | AbstractClient *FocusChain::getForActivation(uint desktop) const | ||
63 | { | 63 | { | ||
64 | return getForActivation(desktop, screens()->current()); | 64 | return getForActivation(desktop, screens()->current()); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | AbstractClient *FocusChain::getForActivation(uint desktop, int screen) const | 67 | AbstractClient *FocusChain::getForActivation(uint desktop, int screen) const | ||
68 | { | 68 | { | ||
69 | DesktopChains::const_iterator it = m_desktopFocusChains.find(desktop); | 69 | auto it = m_desktopFocusChains.constFind(desktop); | ||
70 | if (it == m_desktopFocusChains.constEnd()) { | 70 | if (it == m_desktopFocusChains.constEnd()) { | ||
71 | return NULL; | 71 | return NULL; | ||
72 | } | 72 | } | ||
73 | const auto &chain = it.value(); | 73 | const auto &chain = it.value(); | ||
74 | for (int i = chain.size() - 1; i >= 0; --i) { | 74 | for (int i = chain.size() - 1; i >= 0; --i) { | ||
75 | auto tmp = chain.at(i); | 75 | auto tmp = chain.at(i); | ||
76 | // TODO: move the check into Client | 76 | // TODO: move the check into Client | ||
77 | if (tmp->isShown(false) && tmp->isOnCurrentActivity() | 77 | if (tmp->isShown(false) && tmp->isOnCurrentActivity() | ||
Show All 9 Lines | 86 | { | |||
87 | if (!client->wantsTabFocus()) { | 87 | if (!client->wantsTabFocus()) { | ||
88 | // Doesn't want tab focus, remove | 88 | // Doesn't want tab focus, remove | ||
89 | remove(client); | 89 | remove(client); | ||
90 | return; | 90 | return; | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | if (client->isOnAllDesktops()) { | 93 | if (client->isOnAllDesktops()) { | ||
94 | // Now on all desktops, add it to focus chains it is not already in | 94 | // Now on all desktops, add it to focus chains it is not already in | ||
95 | for (DesktopChains::iterator it = m_desktopFocusChains.begin(); | 95 | for (auto it = m_desktopFocusChains.begin(); | ||
96 | it != m_desktopFocusChains.end(); | 96 | it != m_desktopFocusChains.end(); | ||
97 | ++it) { | 97 | ++it) { | ||
98 | auto &chain = it.value(); | 98 | auto &chain = it.value(); | ||
99 | // Making first/last works only on current desktop, don't affect all desktops | 99 | // Making first/last works only on current desktop, don't affect all desktops | ||
100 | if (it.key() == m_currentDesktop | 100 | if (it.key() == m_currentDesktop | ||
101 | && (change == MakeFirst || change == MakeLast)) { | 101 | && (change == MakeFirst || change == MakeLast)) { | ||
102 | if (change == MakeFirst) { | 102 | if (change == MakeFirst) { | ||
103 | makeFirstInChain(client, chain); | 103 | makeFirstInChain(client, chain); | ||
104 | } else { | 104 | } else { | ||
105 | makeLastInChain(client, chain); | 105 | makeLastInChain(client, chain); | ||
106 | } | 106 | } | ||
107 | } else { | 107 | } else { | ||
108 | insertClientIntoChain(client, chain); | 108 | insertClientIntoChain(client, chain); | ||
109 | } | 109 | } | ||
110 | } | 110 | } | ||
111 | } else { | 111 | } else { | ||
112 | // Now only on desktop, remove it anywhere else | 112 | // Now only on desktop, remove it anywhere else | ||
113 | for (DesktopChains::iterator it = m_desktopFocusChains.begin(); | 113 | for (auto it = m_desktopFocusChains.begin(); | ||
114 | it != m_desktopFocusChains.end(); | 114 | it != m_desktopFocusChains.end(); | ||
115 | ++it) { | 115 | ++it) { | ||
116 | auto &chain = it.value(); | 116 | auto &chain = it.value(); | ||
117 | if (client->isOnDesktop(it.key())) { | 117 | if (client->isOnDesktop(it.key())) { | ||
118 | updateClientInChain(client, change, chain); | 118 | updateClientInChain(client, change, chain); | ||
119 | } else { | 119 | } else { | ||
120 | chain.removeAll(client); | 120 | chain.removeAll(client); | ||
121 | } | 121 | } | ||
122 | } | 122 | } | ||
123 | } | 123 | } | ||
124 | 124 | | |||
125 | // add for most recently used chain | 125 | // add for most recently used chain | ||
126 | updateClientInChain(client, change, m_mostRecentlyUsed); | 126 | updateClientInChain(client, change, m_mostRecentlyUsed); | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | void FocusChain::updateClientInChain(AbstractClient *client, FocusChain::Change change, QList< AbstractClient * >& chain) | 129 | void FocusChain::updateClientInChain(AbstractClient *client, FocusChain::Change change, Chain &chain) | ||
130 | { | 130 | { | ||
131 | if (change == MakeFirst) { | 131 | if (change == MakeFirst) { | ||
132 | makeFirstInChain(client, chain); | 132 | makeFirstInChain(client, chain); | ||
133 | } else if (change == MakeLast) { | 133 | } else if (change == MakeLast) { | ||
134 | makeLastInChain(client, chain); | 134 | makeLastInChain(client, chain); | ||
135 | } else { | 135 | } else { | ||
136 | insertClientIntoChain(client, chain); | 136 | insertClientIntoChain(client, chain); | ||
137 | } | 137 | } | ||
138 | } | 138 | } | ||
139 | 139 | | |||
140 | void FocusChain::insertClientIntoChain(AbstractClient *client, QList< AbstractClient * >& chain) | 140 | void FocusChain::insertClientIntoChain(AbstractClient *client, Chain &chain) | ||
141 | { | 141 | { | ||
142 | if (chain.contains(client)) { | 142 | if (chain.contains(client)) { | ||
143 | return; | 143 | return; | ||
144 | } | 144 | } | ||
145 | if (m_activeClient && m_activeClient != client && | 145 | if (m_activeClient && m_activeClient != client && | ||
146 | !chain.empty() && chain.last() == m_activeClient) { | 146 | !chain.empty() && chain.last() == m_activeClient) { | ||
147 | // Add it after the active client | 147 | // Add it after the active client | ||
148 | chain.insert(chain.size() - 1, client); | 148 | chain.insert(chain.size() - 1, client); | ||
149 | } else { | 149 | } else { | ||
150 | // Otherwise add as the first one | 150 | // Otherwise add as the first one | ||
151 | chain.append(client); | 151 | chain.append(client); | ||
152 | } | 152 | } | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | void FocusChain::moveAfterClient(AbstractClient *client, AbstractClient *reference) | 155 | void FocusChain::moveAfterClient(AbstractClient *client, AbstractClient *reference) | ||
156 | { | 156 | { | ||
157 | if (!client->wantsTabFocus()) { | 157 | if (!client->wantsTabFocus()) { | ||
158 | return; | 158 | return; | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | for (DesktopChains::iterator it = m_desktopFocusChains.begin(); | 161 | for (auto it = m_desktopFocusChains.begin(); | ||
162 | it != m_desktopFocusChains.end(); | 162 | it != m_desktopFocusChains.end(); | ||
163 | ++it) { | 163 | ++it) { | ||
164 | if (!client->isOnDesktop(it.key())) { | 164 | if (!client->isOnDesktop(it.key())) { | ||
165 | continue; | 165 | continue; | ||
166 | } | 166 | } | ||
167 | moveAfterClientInChain(client, reference, it.value()); | 167 | moveAfterClientInChain(client, reference, it.value()); | ||
168 | } | 168 | } | ||
169 | moveAfterClientInChain(client, reference, m_mostRecentlyUsed); | 169 | moveAfterClientInChain(client, reference, m_mostRecentlyUsed); | ||
170 | } | 170 | } | ||
171 | 171 | | |||
172 | void FocusChain::moveAfterClientInChain(AbstractClient *client, AbstractClient *reference, QList<AbstractClient *> &chain) | 172 | void FocusChain::moveAfterClientInChain(AbstractClient *client, AbstractClient *reference, Chain &chain) | ||
173 | { | 173 | { | ||
174 | if (!chain.contains(reference)) { | 174 | if (!chain.contains(reference)) { | ||
175 | return; | 175 | return; | ||
176 | } | 176 | } | ||
177 | if (AbstractClient::belongToSameApplication(reference, client)) { | 177 | if (AbstractClient::belongToSameApplication(reference, client)) { | ||
178 | chain.removeAll(client); | 178 | chain.removeAll(client); | ||
179 | chain.insert(chain.indexOf(reference), client); | 179 | chain.insert(chain.indexOf(reference), client); | ||
180 | } else { | 180 | } else { | ||
Show All 35 Lines | |||||
216 | { | 216 | { | ||
217 | return c != prev && | 217 | return c != prev && | ||
218 | c->isShown(false) && c->isOnCurrentDesktop() && c->isOnCurrentActivity() && | 218 | c->isShown(false) && c->isOnCurrentDesktop() && c->isOnCurrentActivity() && | ||
219 | (!m_separateScreenFocus || c->isOnScreen(prev ? prev->screen() : screens()->current())); | 219 | (!m_separateScreenFocus || c->isOnScreen(prev ? prev->screen() : screens()->current())); | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | AbstractClient *FocusChain::nextForDesktop(AbstractClient *reference, uint desktop) const | 222 | AbstractClient *FocusChain::nextForDesktop(AbstractClient *reference, uint desktop) const | ||
223 | { | 223 | { | ||
224 | DesktopChains::const_iterator it = m_desktopFocusChains.find(desktop); | 224 | auto it = m_desktopFocusChains.constFind(desktop); | ||
225 | if (it == m_desktopFocusChains.end()) { | 225 | if (it == m_desktopFocusChains.constEnd()) { | ||
226 | return NULL; | 226 | return NULL; | ||
227 | } | 227 | } | ||
228 | const auto &chain = it.value(); | 228 | const auto &chain = it.value(); | ||
229 | for (int i = chain.size() - 1; i >= 0; --i) { | 229 | for (int i = chain.size() - 1; i >= 0; --i) { | ||
230 | auto client = chain.at(i); | 230 | auto client = chain.at(i); | ||
231 | if (isUsableFocusCandidate(client, reference)) { | 231 | if (isUsableFocusCandidate(client, reference)) { | ||
232 | return client; | 232 | return client; | ||
233 | } | 233 | } | ||
234 | } | 234 | } | ||
235 | return NULL; | 235 | return NULL; | ||
236 | } | 236 | } | ||
237 | 237 | | |||
238 | void FocusChain::makeFirstInChain(AbstractClient *client, QList< AbstractClient * >& chain) | 238 | void FocusChain::makeFirstInChain(AbstractClient *client, Chain &chain) | ||
239 | { | 239 | { | ||
240 | chain.removeAll(client); | 240 | chain.removeAll(client); | ||
241 | if (client->isMinimized()) { // add it before the first minimized ... | 241 | if (client->isMinimized()) { // add it before the first minimized ... | ||
242 | for (int i = chain.count()-1; i >= 0; --i) { | 242 | for (int i = chain.count()-1; i >= 0; --i) { | ||
243 | if (chain.at(i)->isMinimized()) { | 243 | if (chain.at(i)->isMinimized()) { | ||
244 | chain.insert(i+1, client); | 244 | chain.insert(i+1, client); | ||
245 | return; | 245 | return; | ||
246 | } | 246 | } | ||
247 | } | 247 | } | ||
248 | chain.prepend(client); // ... or at end of chain | 248 | chain.prepend(client); // ... or at end of chain | ||
249 | } else { | 249 | } else { | ||
250 | chain.append(client); | 250 | chain.append(client); | ||
251 | } | 251 | } | ||
252 | } | 252 | } | ||
253 | 253 | | |||
254 | void FocusChain::makeLastInChain(AbstractClient *client, QList< AbstractClient * >& chain) | 254 | void FocusChain::makeLastInChain(AbstractClient *client, Chain &chain) | ||
255 | { | 255 | { | ||
256 | chain.removeAll(client); | 256 | chain.removeAll(client); | ||
257 | chain.prepend(client); | 257 | chain.prepend(client); | ||
258 | } | 258 | } | ||
259 | 259 | | |||
260 | bool FocusChain::contains(AbstractClient *client, uint desktop) const | 260 | bool FocusChain::contains(AbstractClient *client, uint desktop) const | ||
261 | { | 261 | { | ||
262 | DesktopChains::const_iterator it = m_desktopFocusChains.find(desktop); | 262 | auto it = m_desktopFocusChains.constFind(desktop); | ||
263 | if (it == m_desktopFocusChains.end()) { | 263 | if (it == m_desktopFocusChains.constEnd()) { | ||
264 | return false; | 264 | return false; | ||
265 | } | 265 | } | ||
266 | return it.value().contains(client); | 266 | return it.value().contains(client); | ||
267 | } | 267 | } | ||
268 | 268 | | |||
269 | } // namespace | 269 | } // namespace |