18 for (
auto it = m_desktopFocusChains.begin();
19 it != m_desktopFocusChains.end();
21 it.value().removeAll(window);
23 m_mostRecentlyUsed.removeAll(window);
28 m_desktopFocusChains.insert(desktop, Chain());
33 if (m_currentDesktop == desktop) {
34 m_currentDesktop =
nullptr;
36 m_desktopFocusChains.remove(desktop);
46 auto it = m_desktopFocusChains.constFind(desktop);
47 if (it == m_desktopFocusChains.constEnd()) {
50 const auto &chain = it.value();
51 for (
int i = chain.size() - 1; i >= 0; --i) {
52 auto tmp = chain.at(i);
54 if (!tmp->isShade() && tmp->isShown() && tmp->isOnCurrentActivity()
55 && (!m_separateScreenFocus || tmp->output() == output)) {
72 for (
auto it = m_desktopFocusChains.begin();
73 it != m_desktopFocusChains.end();
75 auto &chain = it.value();
77 if (it.key() == m_currentDesktop
80 makeFirstInChain(window, chain);
82 makeLastInChain(window, chain);
85 insertWindowIntoChain(window, chain);
90 for (
auto it = m_desktopFocusChains.begin();
91 it != m_desktopFocusChains.end();
93 auto &chain = it.value();
95 updateWindowInChain(window, change, chain);
97 chain.removeAll(window);
103 updateWindowInChain(window, change, m_mostRecentlyUsed);
109 makeFirstInChain(window, chain);
111 makeLastInChain(window, chain);
113 insertWindowIntoChain(window, chain);
117void FocusChain::insertWindowIntoChain(
Window *window, Chain &chain)
119 Q_ASSERT(!window->isDeleted());
120 if (chain.contains(window)) {
123 if (m_activeWindow && m_activeWindow != window && !chain.empty() && chain.last() == m_activeWindow) {
125 chain.insert(chain.size() - 1, window);
128 chain.append(window);
139 for (
auto it = m_desktopFocusChains.begin();
140 it != m_desktopFocusChains.end();
145 moveAfterWindowInChain(window, reference, it.value());
147 moveAfterWindowInChain(window, reference, m_mostRecentlyUsed);
150void FocusChain::moveAfterWindowInChain(
Window *window,
Window *reference, Chain &chain)
153 if (!chain.contains(reference)) {
157 chain.removeAll(window);
158 chain.insert(chain.indexOf(reference), window);
160 chain.removeAll(window);
161 for (
int i = chain.size() - 1; i >= 0; --i) {
163 chain.insert(i, window);
172 if (m_mostRecentlyUsed.isEmpty()) {
175 return m_mostRecentlyUsed.first();
180 if (m_mostRecentlyUsed.isEmpty()) {
183 const int index = m_mostRecentlyUsed.indexOf(reference);
185 return m_mostRecentlyUsed.first();
188 return m_mostRecentlyUsed.last();
190 return m_mostRecentlyUsed.at(index - 1);
201 auto it = m_desktopFocusChains.constFind(desktop);
202 if (it == m_desktopFocusChains.constEnd()) {
205 const auto &chain = it.value();
206 for (
int i = chain.size() - 1; i >= 0; --i) {
207 auto window = chain.at(i);
215void FocusChain::makeFirstInChain(
Window *window, Chain &chain)
218 chain.removeAll(window);
219 chain.append(window);
222void FocusChain::makeLastInChain(
Window *window, Chain &chain)
224 Q_ASSERT(!window->isDeleted());
225 chain.removeAll(window);
226 chain.prepend(window);
231 auto it = m_desktopFocusChains.constFind(desktop);
232 if (it == m_desktopFocusChains.constEnd()) {
235 return it.value().contains(window);
240#include "moc_focuschain.cpp"
Window * getForActivation(VirtualDesktop *desktop) const
Finds the best Window to become the new active Window in the focus chain for the given virtual deskto...
void removeDesktop(VirtualDesktop *desktop)
void moveAfterWindow(Window *window, Window *reference)
Moves window behind the reference Window in all focus chains.
void remove(KWin::Window *window)
Removes window from all focus chains.
void update(Window *window, Change change)
Updates the position of the window according to the requested change in the focus chain.
void addDesktop(VirtualDesktop *desktop)
Window * nextForDesktop(Window *reference, VirtualDesktop *desktop) const
Queries the focus chain for desktop for the next Window in relation to the given reference Window.
bool contains(Window *window) const
Checks whether the most recently used focus chain contains the given window.
bool isUsableFocusCandidate(Window *window, Window *prev) const
Window * firstMostRecentlyUsed() const
Returns the first Window in the most recently used focus chain. First Window in this case means reall...
Window * nextMostRecentlyUsed(Window *reference) const
Queries the most recently used focus chain for the next Window after the given reference Window.
bool wantsTabFocus() const
bool isOnCurrentActivity() const
static bool belongToSameApplication(const Window *c1, const Window *c2, SameApplicationChecks checks=SameApplicationChecks())
bool isOnAllDesktops() const
bool isOnCurrentDesktop() const
bool isOnDesktop(VirtualDesktop *desktop) const
bool isOnOutput(Output *output) const
Output * activeOutput() const