2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2012-11-20 16:26:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2012-11-20 16:26:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2012-11-20 16:26:50 +00:00
|
|
|
#ifndef KWIN_FOCUS_CHAIN_H
|
|
|
|
#define KWIN_FOCUS_CHAIN_H
|
2013-04-05 07:41:25 +00:00
|
|
|
// KWin
|
|
|
|
#include <kwinglobals.h>
|
|
|
|
// Qt
|
2012-11-20 16:26:50 +00:00
|
|
|
#include <QHash>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QObject>
|
2012-11-20 16:26:50 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
// forward declarations
|
2022-04-22 17:39:12 +00:00
|
|
|
class Window;
|
2022-04-14 12:33:28 +00:00
|
|
|
class Output;
|
2021-08-16 12:07:43 +00:00
|
|
|
class VirtualDesktop;
|
2012-11-20 16:26:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Singleton class to handle the various focus chains.
|
|
|
|
*
|
|
|
|
* A focus chain is a list of Clients containing information on which Client should be activated.
|
|
|
|
*
|
|
|
|
* Internally this FocusChain holds multiple independent chains. There is one chain of most recently
|
|
|
|
* used Clients which is primarily used by TabBox to build up the list of Clients for navigation.
|
|
|
|
* The chains are organized as a normal QList of Clients with the most recently used Client being the
|
|
|
|
* last item of the list, that is a LIFO like structure.
|
|
|
|
*
|
|
|
|
* In addition there is one chain for each virtual desktop which is used to determine which Client
|
|
|
|
* should get activated when the user switches to another virtual desktop.
|
|
|
|
*
|
|
|
|
* Furthermore this class contains various helper methods for the two different kind of chains.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2012-11-20 16:26:50 +00:00
|
|
|
class FocusChain : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum Change {
|
|
|
|
MakeFirst,
|
|
|
|
MakeLast,
|
2020-10-20 20:05:33 +00:00
|
|
|
Update,
|
|
|
|
MakeFirstMinimized = MakeFirst
|
2012-11-20 16:26:50 +00:00
|
|
|
};
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~FocusChain() override;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Updates the position of the @p client according to the requested @p change in the
|
|
|
|
* focus chain.
|
|
|
|
*
|
|
|
|
* This method affects both the most recently used focus chain and the per virtual desktop focus
|
|
|
|
* chain.
|
|
|
|
*
|
|
|
|
* In case the client does no longer want to get focus, it is removed from all chains. In case
|
|
|
|
* the client is on all virtual desktops it is ensured that it is present in each of the virtual
|
|
|
|
* desktops focus chain. In case it's on exactly one virtual desktop it is ensured that it is only
|
|
|
|
* in the focus chain for that virtual desktop.
|
|
|
|
*
|
|
|
|
* Depending on @p change the Client is inserted at different positions in the focus chain. In case
|
|
|
|
* of @c MakeFirst it is moved to the first position of the chain, in case of
|
|
|
|
* @c MakeLast it is moved to the last position of the chain. In all other cases it
|
|
|
|
* depends on whether the @p client is the currently active Client. If it is the active Client it
|
|
|
|
* becomes the first Client in the chain, otherwise it is inserted at the second position that is
|
|
|
|
* directly after the currently active Client.
|
|
|
|
*
|
|
|
|
* @param client The Client which should be moved inside the chains.
|
|
|
|
* @param change Where to move the Client
|
|
|
|
* @return void
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
void update(Window *client, Change change);
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Moves @p client behind the @p reference Client in all focus chains.
|
|
|
|
*
|
|
|
|
* @param client The Client to move in the chains
|
|
|
|
* @param reference The Client behind which the @p client should be moved
|
|
|
|
* @return void
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
void moveAfterClient(Window *client, Window *reference);
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Finds the best Client to become the new active Client in the focus chain for the given
|
|
|
|
* virtual @p desktop.
|
|
|
|
*
|
|
|
|
* In case that separate screen focus is used only Clients on the current screen are considered.
|
|
|
|
* If no Client for activation is found @c null is returned.
|
|
|
|
*
|
|
|
|
* @param desktop The virtual desktop to look for a Client for activation
|
2019-09-24 08:48:08 +00:00
|
|
|
* @return :X11Client *The Client which could be activated or @c null if there is none.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *getForActivation(VirtualDesktop *desktop) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Finds the best Client to become the new active Client in the focus chain for the given
|
|
|
|
* virtual @p desktop on the given @p screen.
|
|
|
|
*
|
|
|
|
* This method makes only sense to use if separate screen focus is used. If separate screen focus
|
|
|
|
* is disabled the @p screen is ignored.
|
|
|
|
* If no Client for activation is found @c null is returned.
|
|
|
|
*
|
|
|
|
* @param desktop The virtual desktop to look for a Client for activation
|
2021-08-28 14:48:12 +00:00
|
|
|
* @param output The screen to constrain the search on with separate screen focus
|
2019-09-24 08:48:08 +00:00
|
|
|
* @return :X11Client *The Client which could be activated or @c null if there is none.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *getForActivation(VirtualDesktop *desktop, Output *output) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Checks whether the most recently used focus chain contains the given @p client.
|
|
|
|
*
|
|
|
|
* Does not consider the per-desktop focus chains.
|
|
|
|
* @param client The Client to look for.
|
|
|
|
* @return bool @c true if the most recently used focus chain contains @p client, @c false otherwise.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
bool contains(Window *client) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Checks whether the focus chain for the given @p desktop contains the given @p client.
|
|
|
|
*
|
|
|
|
* Does not consider the most recently used focus chain.
|
|
|
|
*
|
|
|
|
* @param client The Client to look for.
|
|
|
|
* @param desktop The virtual desktop whose focus chain should be used
|
|
|
|
* @return bool @c true if the focus chain for @p desktop contains @p client, @c false otherwise.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
bool contains(Window *client, VirtualDesktop *desktop) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Queries the most recently used focus chain for the next Client after the given
|
|
|
|
* @p reference Client.
|
|
|
|
*
|
|
|
|
* The navigation wraps around the borders of the chain. That is if the @p reference Client is
|
|
|
|
* the last item of the focus chain, the first Client will be returned.
|
|
|
|
*
|
|
|
|
* If the @p reference Client cannot be found in the focus chain, the first element of the focus
|
|
|
|
* chain is returned.
|
|
|
|
*
|
|
|
|
* @param reference The start point in the focus chain to search
|
2019-09-24 08:48:08 +00:00
|
|
|
* @return :X11Client *The relatively next Client in the most recently used chain.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *nextMostRecentlyUsed(Window *reference) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Queries the focus chain for @p desktop for the next Client in relation to the given
|
|
|
|
* @p reference Client.
|
|
|
|
*
|
|
|
|
* The method finds the first usable Client which is not the @p reference Client. If no Client
|
|
|
|
* can be found @c null is returned
|
|
|
|
*
|
|
|
|
* @param reference The reference Client which should not be returned
|
|
|
|
* @param desktop The virtual desktop whose focus chain should be used
|
2019-09-24 08:48:08 +00:00
|
|
|
* @return :X11Client *The next usable Client or @c null if none can be found.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *nextForDesktop(Window *reference, VirtualDesktop *desktop) const;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns the first Client in the most recently used focus chain. First Client in this
|
|
|
|
* case means really the first Client in the chain and not the most recently used Client.
|
|
|
|
*
|
2019-09-24 08:48:08 +00:00
|
|
|
* @return :X11Client *The first Client in the most recently used chain.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *firstMostRecentlyUsed() const;
|
2012-11-20 16:26:50 +00:00
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
bool isUsableFocusCandidate(Window *c, Window *prev) const;
|
2021-05-13 17:07:01 +00:00
|
|
|
|
2013-07-22 14:07:39 +00:00
|
|
|
public Q_SLOTS:
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Removes @p client from all focus chains.
|
|
|
|
*
|
|
|
|
* @param client The Client to remove from all focus chains.
|
|
|
|
* @return void
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
void remove(KWin::Window *client);
|
2012-11-20 16:26:50 +00:00
|
|
|
void setSeparateScreenFocus(bool enabled);
|
2022-04-22 17:39:12 +00:00
|
|
|
void setActiveClient(KWin::Window *client);
|
2021-08-16 12:07:43 +00:00
|
|
|
void setCurrentDesktop(VirtualDesktop *desktop);
|
|
|
|
void addDesktop(VirtualDesktop *desktop);
|
|
|
|
void removeDesktop(VirtualDesktop *desktop);
|
2012-11-20 16:26:50 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-22 17:39:12 +00:00
|
|
|
using Chain = QList<Window *>;
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Makes @p client the first Client in the given focus @p chain.
|
|
|
|
*
|
|
|
|
* This means the existing position of @p client is dropped and @p client is appended to the
|
|
|
|
* @p chain which makes it the first item.
|
|
|
|
*
|
|
|
|
* @param client The Client to become the first in @p chain
|
|
|
|
* @param chain The focus chain to operate on
|
|
|
|
* @return void
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
void makeFirstInChain(Window *client, Chain &chain);
|
2012-11-20 16:26:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Makes @p client the last Client in the given focus @p chain.
|
|
|
|
*
|
|
|
|
* This means the existing position of @p client is dropped and @p client is prepended to the
|
|
|
|
* @p chain which makes it the last item.
|
|
|
|
*
|
|
|
|
* @param client The Client to become the last in @p chain
|
|
|
|
* @param chain The focus chain to operate on
|
|
|
|
* @return void
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2022-04-22 17:39:12 +00:00
|
|
|
void makeLastInChain(Window *client, Chain &chain);
|
|
|
|
void moveAfterClientInChain(Window *client, Window *reference, Chain &chain);
|
|
|
|
void updateClientInChain(Window *client, Change change, Chain &chain);
|
|
|
|
void insertClientIntoChain(Window *client, Chain &chain);
|
2018-07-27 19:43:09 +00:00
|
|
|
Chain m_mostRecentlyUsed;
|
2021-08-16 12:07:43 +00:00
|
|
|
QHash<VirtualDesktop *, Chain> m_desktopFocusChains;
|
2012-11-20 16:26:50 +00:00
|
|
|
bool m_separateScreenFocus;
|
2022-04-22 17:39:12 +00:00
|
|
|
Window *m_activeClient;
|
2021-08-16 12:07:43 +00:00
|
|
|
VirtualDesktop *m_currentDesktop = nullptr;
|
2012-11-20 16:26:50 +00:00
|
|
|
|
2013-04-05 07:41:25 +00:00
|
|
|
KWIN_SINGLETON_VARIABLE(FocusChain, s_manager)
|
2012-11-20 16:26:50 +00:00
|
|
|
};
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
inline bool FocusChain::contains(Window *client) const
|
2012-11-20 16:26:50 +00:00
|
|
|
{
|
|
|
|
return m_mostRecentlyUsed.contains(client);
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
inline void FocusChain::setSeparateScreenFocus(bool enabled)
|
2012-11-20 16:26:50 +00:00
|
|
|
{
|
|
|
|
m_separateScreenFocus = enabled;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
inline void FocusChain::setActiveClient(Window *client)
|
2012-11-20 16:26:50 +00:00
|
|
|
{
|
|
|
|
m_activeClient = client;
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
inline void FocusChain::setCurrentDesktop(VirtualDesktop *desktop)
|
2012-11-20 16:26:50 +00:00
|
|
|
{
|
2021-08-16 12:07:43 +00:00
|
|
|
m_currentDesktop = desktop;
|
2012-11-20 16:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // KWIN_FOCUS_CHAIN_H
|