2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2012-07-21 09:25:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
|
2012-07-21 09:25:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2012-07-21 09:25:17 +00:00
|
|
|
#include "mock_tabboxhandler.h"
|
|
|
|
#include "mock_tabboxclient.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2014-06-10 09:14:59 +00:00
|
|
|
MockTabBoxHandler::MockTabBoxHandler(QObject *parent)
|
|
|
|
: TabBoxHandler(parent)
|
2012-07-21 09:25:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MockTabBoxHandler::~MockTabBoxHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockTabBoxHandler::grabbedKeyEvent(QKeyEvent *event) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::activeClient() const
|
2012-07-21 09:25:17 +00:00
|
|
|
{
|
2012-08-19 17:32:56 +00:00
|
|
|
return m_activeClient;
|
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
void MockTabBoxHandler::setActiveClient(const std::weak_ptr<TabBox::TabBoxClient> &client)
|
2012-08-19 17:32:56 +00:00
|
|
|
{
|
|
|
|
m_activeClient = client;
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const
|
2012-07-21 09:25:17 +00:00
|
|
|
{
|
2023-03-20 13:05:29 +00:00
|
|
|
QList<std::shared_ptr<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
|
2012-07-21 09:25:17 +00:00
|
|
|
for (; it != m_windows.constEnd(); ++it) {
|
2022-08-01 21:29:02 +00:00
|
|
|
if ((*it).get() == client) {
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>(*it);
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>();
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const
|
2012-07-21 09:25:17 +00:00
|
|
|
{
|
2023-03-20 13:05:29 +00:00
|
|
|
QList<std::shared_ptr<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
|
2012-07-21 09:25:17 +00:00
|
|
|
for (; it != m_windows.constEnd(); ++it) {
|
2022-08-01 21:29:02 +00:00
|
|
|
if ((*it).get() == client) {
|
2012-07-21 09:25:17 +00:00
|
|
|
++it;
|
|
|
|
if (it == m_windows.constEnd()) {
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>(m_windows.first());
|
2012-07-21 09:25:17 +00:00
|
|
|
} else {
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>(*it);
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 18:55:07 +00:00
|
|
|
if (!m_windows.isEmpty()) {
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>(m_windows.last());
|
2012-09-05 18:55:07 +00:00
|
|
|
}
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>();
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::firstClientFocusChain() const
|
2012-08-19 17:32:56 +00:00
|
|
|
{
|
|
|
|
if (m_windows.isEmpty()) {
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>();
|
2012-08-19 17:32:56 +00:00
|
|
|
}
|
|
|
|
return m_windows.first();
|
|
|
|
}
|
|
|
|
|
2012-09-05 18:55:07 +00:00
|
|
|
bool MockTabBoxHandler::isInFocusChain(TabBox::TabBoxClient *client) const
|
|
|
|
{
|
|
|
|
if (!client) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-20 13:05:29 +00:00
|
|
|
QList<std::shared_ptr<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
|
2012-09-05 18:55:07 +00:00
|
|
|
for (; it != m_windows.constEnd(); ++it) {
|
2022-08-01 21:29:02 +00:00
|
|
|
if ((*it).get() == client) {
|
2012-09-05 18:55:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-20 13:05:29 +00:00
|
|
|
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::createMockWindow(const QString &caption)
|
2012-07-21 09:25:17 +00:00
|
|
|
{
|
2023-03-20 13:05:29 +00:00
|
|
|
std::shared_ptr<TabBox::TabBoxClient> client(new MockTabBoxClient(caption));
|
2012-07-21 09:25:17 +00:00
|
|
|
m_windows.append(client);
|
2012-08-19 17:32:56 +00:00
|
|
|
m_activeClient = client;
|
2023-03-20 13:05:29 +00:00
|
|
|
return std::weak_ptr<TabBox::TabBoxClient>(client);
|
2012-07-21 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MockTabBoxHandler::closeWindow(TabBox::TabBoxClient *client)
|
|
|
|
{
|
2023-03-20 13:05:29 +00:00
|
|
|
QList<std::shared_ptr<TabBox::TabBoxClient>>::iterator it = m_windows.begin();
|
2012-07-21 09:25:17 +00:00
|
|
|
for (; it != m_windows.end(); ++it) {
|
2022-08-01 21:29:02 +00:00
|
|
|
if ((*it).get() == client) {
|
2012-07-21 09:25:17 +00:00
|
|
|
m_windows.erase(it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|