KWin
Loading...
Searching...
No Matches
focuschain.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10// KWin
11#include "effect/globals.h"
12// Qt
13#include <QHash>
14#include <QObject>
15
16namespace KWin
17{
18// forward declarations
19class Window;
20class Output;
21class VirtualDesktop;
22
38class FocusChain : public QObject
39{
40 Q_OBJECT
41public:
48 explicit FocusChain() = default;
49
73 void update(Window *window, Change change);
81 void moveAfterWindow(Window *window, Window *reference);
92 Window *getForActivation(VirtualDesktop *desktop) const;
105 Window *getForActivation(VirtualDesktop *desktop, Output *output) const;
106
114 bool contains(Window *window) const;
124 bool contains(Window *window, VirtualDesktop *desktop) const;
138 Window *nextMostRecentlyUsed(Window *reference) const;
150 Window *nextForDesktop(Window *reference, VirtualDesktop *desktop) const;
158
159 bool isUsableFocusCandidate(Window *window, Window *prev) const;
160
161public Q_SLOTS:
168 void remove(KWin::Window *window);
169 void setSeparateScreenFocus(bool enabled);
170 void setActiveWindow(KWin::Window *window);
171 void setCurrentDesktop(VirtualDesktop *desktop);
172 void addDesktop(VirtualDesktop *desktop);
173 void removeDesktop(VirtualDesktop *desktop);
174
175private:
176 using Chain = QList<Window *>;
187 void makeFirstInChain(Window *window, Chain &chain);
198 void makeLastInChain(Window *window, Chain &chain);
199 void moveAfterWindowInChain(Window *window, Window *reference, Chain &chain);
200 void updateWindowInChain(Window *window, Change change, Chain &chain);
201 void insertWindowIntoChain(Window *window, Chain &chain);
202 Chain m_mostRecentlyUsed;
203 QHash<VirtualDesktop *, Chain> m_desktopFocusChains;
204 bool m_separateScreenFocus = false;
205 Window *m_activeWindow = nullptr;
206 VirtualDesktop *m_currentDesktop = nullptr;
207};
208
209inline bool FocusChain::contains(Window *window) const
210{
211 return m_mostRecentlyUsed.contains(window);
212}
213
214inline void FocusChain::setSeparateScreenFocus(bool enabled)
215{
216 m_separateScreenFocus = enabled;
217}
218
220{
221 m_activeWindow = window;
222}
223
225{
226 m_currentDesktop = desktop;
227}
228
229} // namespace
Singleton class to handle the various focus chains.
Definition focuschain.h:39
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)
void setCurrentDesktop(VirtualDesktop *desktop)
Definition focuschain.h:224
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.
Definition focuschain.h:209
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...
FocusChain()=default
Window * nextMostRecentlyUsed(Window *reference) const
Queries the most recently used focus chain for the next Window after the given reference Window.
void setActiveWindow(KWin::Window *window)
Definition focuschain.h:219
void setSeparateScreenFocus(bool enabled)
Definition focuschain.h:214