kwin/tabbox/tests/mock_tabboxhandler.cpp
Martin Gräßlin a4fed7188c Use the first client as entrance to the focus chain if no active window
The recently used mode of TabBox uses the active window as the entrance
into the focus chain. If there is no active window it does not find any
Clients. To solve this issue the ClientModel now uses the first entry
of the focus chain in case there is no active window.

BUG: 305449
FIXED-IN: 4.9.1
REVIEW: 106088
2012-08-26 20:07:52 +02:00

105 lines
3.2 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "mock_tabboxhandler.h"
#include "mock_tabboxclient.h"
namespace KWin
{
MockTabBoxHandler::MockTabBoxHandler()
: TabBoxHandler()
{
}
MockTabBoxHandler::~MockTabBoxHandler()
{
}
void MockTabBoxHandler::grabbedKeyEvent(QKeyEvent *event) const
{
Q_UNUSED(event)
}
QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::activeClient() const
{
return m_activeClient;
}
void MockTabBoxHandler::setActiveClient(const QWeakPointer< TabBox::TabBoxClient >& client)
{
m_activeClient = client;
}
QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const
{
Q_UNUSED(desktop)
QList< QSharedPointer< TabBox::TabBoxClient > >::const_iterator it = m_windows.constBegin();
for (; it != m_windows.constEnd(); ++it) {
if ((*it).data() == client) {
return QWeakPointer< TabBox::TabBoxClient >(*it);
}
}
return QWeakPointer< TabBox::TabBoxClient >();
}
QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const
{
QList< QSharedPointer< TabBox::TabBoxClient > >::const_iterator it = m_windows.constBegin();
for (; it != m_windows.constEnd(); ++it) {
if ((*it).data() == client) {
++it;
if (it == m_windows.constEnd()) {
return QWeakPointer< TabBox::TabBoxClient >(m_windows.first());
} else {
return QWeakPointer< TabBox::TabBoxClient >(*it);
}
}
}
return QWeakPointer< TabBox::TabBoxClient >();
}
QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::firstClientFocusChain() const
{
if (m_windows.isEmpty()) {
return QWeakPointer<TabBox::TabBoxClient>();
}
return m_windows.first();
}
QWeakPointer< TabBox::TabBoxClient > MockTabBoxHandler::createMockWindow(const QString &caption, WId id)
{
QSharedPointer< TabBox::TabBoxClient > client(new MockTabBoxClient(caption, id));
m_windows.append(client);
m_activeClient = client;
return QWeakPointer< TabBox::TabBoxClient >(client);
}
void MockTabBoxHandler::closeWindow(TabBox::TabBoxClient *client)
{
QList< QSharedPointer< TabBox::TabBoxClient > >::iterator it = m_windows.begin();
for (; it != m_windows.end(); ++it) {
if ((*it).data() == client) {
m_windows.erase(it);
return;
}
}
}
} // namespace KWin