Changeset View
Changeset View
Standalone View
Standalone View
focuschain.cpp
Show All 23 Lines | |||||
24 | namespace KWin | 24 | namespace KWin | ||
25 | { | 25 | { | ||
26 | 26 | | |||
27 | KWIN_SINGLETON_FACTORY_VARIABLE(FocusChain, s_manager) | 27 | KWIN_SINGLETON_FACTORY_VARIABLE(FocusChain, s_manager) | ||
28 | 28 | | |||
29 | FocusChain::FocusChain(QObject *parent) | 29 | FocusChain::FocusChain(QObject *parent) | ||
30 | : QObject(parent) | 30 | : QObject(parent) | ||
31 | , m_separateScreenFocus(false) | 31 | , m_separateScreenFocus(false) | ||
32 | , m_activeClient(NULL) | 32 | , m_activeClient(nullptr) | ||
33 | , m_currentDesktop(0) | 33 | , m_currentDesktop(0) | ||
34 | { | 34 | { | ||
35 | } | 35 | } | ||
36 | 36 | | |||
37 | FocusChain::~FocusChain() | 37 | FocusChain::~FocusChain() | ||
38 | { | 38 | { | ||
39 | s_manager = NULL; | 39 | s_manager = nullptr; | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | void FocusChain::remove(AbstractClient *client) | 42 | void FocusChain::remove(AbstractClient *client) | ||
43 | { | 43 | { | ||
44 | for (auto 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); | ||
Show All 15 Lines | |||||
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 | auto it = m_desktopFocusChains.constFind(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 nullptr; | ||
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() | ||
78 | && ( !m_separateScreenFocus || tmp->screen() == screen)) { | 78 | && ( !m_separateScreenFocus || tmp->screen() == screen)) { | ||
79 | return tmp; | 79 | return tmp; | ||
80 | } | 80 | } | ||
81 | } | 81 | } | ||
82 | return NULL; | 82 | return nullptr; | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | void FocusChain::update(AbstractClient *client, FocusChain::Change change) | 85 | void FocusChain::update(AbstractClient *client, FocusChain::Change change) | ||
86 | { | 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; | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 182 | for (int i = chain.size() - 1; i >= 0; --i) { | |||
186 | } | 186 | } | ||
187 | } | 187 | } | ||
188 | } | 188 | } | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | AbstractClient *FocusChain::firstMostRecentlyUsed() const | 191 | AbstractClient *FocusChain::firstMostRecentlyUsed() const | ||
192 | { | 192 | { | ||
193 | if (m_mostRecentlyUsed.isEmpty()) { | 193 | if (m_mostRecentlyUsed.isEmpty()) { | ||
194 | return NULL; | 194 | return nullptr; | ||
195 | } | 195 | } | ||
196 | return m_mostRecentlyUsed.first(); | 196 | return m_mostRecentlyUsed.first(); | ||
197 | } | 197 | } | ||
198 | 198 | | |||
199 | AbstractClient *FocusChain::nextMostRecentlyUsed(AbstractClient *reference) const | 199 | AbstractClient *FocusChain::nextMostRecentlyUsed(AbstractClient *reference) const | ||
200 | { | 200 | { | ||
201 | if (m_mostRecentlyUsed.isEmpty()) { | 201 | if (m_mostRecentlyUsed.isEmpty()) { | ||
202 | return NULL; | 202 | return nullptr; | ||
203 | } | 203 | } | ||
204 | const int index = m_mostRecentlyUsed.indexOf(reference); | 204 | const int index = m_mostRecentlyUsed.indexOf(reference); | ||
205 | if (index == -1) { | 205 | if (index == -1) { | ||
206 | return m_mostRecentlyUsed.first(); | 206 | return m_mostRecentlyUsed.first(); | ||
207 | } | 207 | } | ||
208 | if (index == 0) { | 208 | if (index == 0) { | ||
209 | return m_mostRecentlyUsed.last(); | 209 | return m_mostRecentlyUsed.last(); | ||
210 | } | 210 | } | ||
211 | return m_mostRecentlyUsed.at(index - 1); | 211 | return m_mostRecentlyUsed.at(index - 1); | ||
212 | } | 212 | } | ||
213 | 213 | | |||
214 | // copied from activation.cpp | 214 | // copied from activation.cpp | ||
215 | bool FocusChain::isUsableFocusCandidate(AbstractClient *c, AbstractClient *prev) const | 215 | bool FocusChain::isUsableFocusCandidate(AbstractClient *c, AbstractClient *prev) const | ||
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 | auto it = m_desktopFocusChains.constFind(desktop); | 224 | auto it = m_desktopFocusChains.constFind(desktop); | ||
225 | if (it == m_desktopFocusChains.constEnd()) { | 225 | if (it == m_desktopFocusChains.constEnd()) { | ||
226 | return NULL; | 226 | return nullptr; | ||
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 nullptr; | ||
236 | } | 236 | } | ||
237 | 237 | | |||
238 | void FocusChain::makeFirstInChain(AbstractClient *client, Chain &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()) { | ||
Show All 26 Lines |