2009-09-13 11:36:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
// own
|
|
|
|
#include "tabboxhandler.h"
|
2013-09-10 07:33:07 +00:00
|
|
|
#include <kwinglobals.h>
|
2013-09-10 09:03:28 +00:00
|
|
|
#include "xcbutils.h"
|
2009-09-13 11:36:45 +00:00
|
|
|
// tabbox
|
|
|
|
#include "clientmodel.h"
|
|
|
|
#include "desktopmodel.h"
|
|
|
|
#include "tabboxconfig.h"
|
2013-12-10 06:14:44 +00:00
|
|
|
#include "thumbnailitem.h"
|
2014-03-03 12:42:13 +00:00
|
|
|
#include "scripting/scripting.h"
|
2013-12-10 06:14:44 +00:00
|
|
|
#include "switcheritem.h"
|
2009-09-13 11:36:45 +00:00
|
|
|
// Qt
|
2013-12-10 06:14:44 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDesktopWidget>
|
2009-09-13 11:36:45 +00:00
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QModelIndex>
|
2014-03-29 08:05:08 +00:00
|
|
|
#include <QStandardPaths>
|
2012-05-03 23:08:28 +00:00
|
|
|
#include <QTimer>
|
2013-12-10 06:14:44 +00:00
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQuickWindow>
|
2009-09-13 11:36:45 +00:00
|
|
|
#include <QX11Info>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
// KDE
|
2013-12-10 06:14:44 +00:00
|
|
|
#include <KLocalizedString>
|
2013-07-26 17:58:42 +00:00
|
|
|
#include <KProcess>
|
2013-12-10 06:14:44 +00:00
|
|
|
#include <KServiceTypeTrader>
|
2010-10-17 19:49:07 +00:00
|
|
|
#include <KWindowSystem>
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace TabBox
|
|
|
|
{
|
|
|
|
|
|
|
|
class TabBoxHandlerPrivate
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TabBoxHandlerPrivate(TabBoxHandler *q);
|
|
|
|
|
|
|
|
~TabBoxHandlerPrivate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the current highlight window state
|
|
|
|
*/
|
|
|
|
void updateHighlightWindows();
|
|
|
|
/**
|
|
|
|
* Ends window highlighting
|
|
|
|
*/
|
|
|
|
void endHighlightWindows(bool abort = false);
|
|
|
|
|
2013-12-10 06:14:44 +00:00
|
|
|
void show();
|
|
|
|
QQuickWindow *window() const;
|
|
|
|
SwitcherItem *switcherItem() const;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
ClientModel* clientModel() const;
|
|
|
|
DesktopModel* desktopModel() const;
|
|
|
|
|
|
|
|
TabBoxHandler *q; // public pointer
|
|
|
|
// members
|
|
|
|
TabBoxConfig config;
|
2014-03-03 12:42:13 +00:00
|
|
|
QScopedPointer<QQmlContext> m_qmlContext;
|
2013-12-10 06:14:44 +00:00
|
|
|
QScopedPointer<QQmlComponent> m_qmlComponent;
|
|
|
|
QObject *m_mainItem;
|
|
|
|
QMap<QString, QObject*> m_clientTabBoxes;
|
|
|
|
QMap<QString, QObject*> m_desktopTabBoxes;
|
2011-07-09 09:12:00 +00:00
|
|
|
ClientModel* m_clientModel;
|
|
|
|
DesktopModel* m_desktopModel;
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex index;
|
|
|
|
/**
|
|
|
|
* Indicates if the tabbox is shown.
|
|
|
|
*/
|
|
|
|
bool isShown;
|
|
|
|
TabBoxClient *lastRaisedClient, *lastRaisedClientSucc;
|
2013-09-10 11:29:06 +00:00
|
|
|
Xcb::Atom m_highlightWindowsAtom;
|
2013-12-10 06:14:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QObject *createSwitcherItem(bool desktopMode);
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q)
|
2014-03-03 12:42:13 +00:00
|
|
|
: m_qmlContext()
|
2013-12-10 06:14:44 +00:00
|
|
|
, m_qmlComponent()
|
|
|
|
, m_mainItem(nullptr)
|
2013-09-10 11:29:06 +00:00
|
|
|
, m_highlightWindowsAtom(QByteArrayLiteral("_KDE_WINDOW_HIGHLIGHT"))
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-10-17 19:49:07 +00:00
|
|
|
this->q = q;
|
2009-09-13 12:15:04 +00:00
|
|
|
isShown = false;
|
2014-02-24 15:42:43 +00:00
|
|
|
lastRaisedClient = nullptr;
|
|
|
|
lastRaisedClientSucc = nullptr;
|
2009-09-13 11:36:45 +00:00
|
|
|
config = TabBoxConfig();
|
2011-07-09 09:12:00 +00:00
|
|
|
m_clientModel = new ClientModel(q);
|
|
|
|
m_desktopModel = new DesktopModel(q);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxHandlerPrivate::~TabBoxHandlerPrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-05-27 08:08:36 +00:00
|
|
|
for (auto it = m_clientTabBoxes.constBegin(); it != m_clientTabBoxes.constEnd(); ++it) {
|
2013-12-10 06:14:44 +00:00
|
|
|
delete it.value();
|
|
|
|
}
|
2014-05-27 08:08:36 +00:00
|
|
|
for (auto it = m_desktopTabBoxes.constBegin(); it != m_desktopTabBoxes.constEnd(); ++it) {
|
2013-12-10 06:14:44 +00:00
|
|
|
delete it.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickWindow *TabBoxHandlerPrivate::window() const
|
|
|
|
{
|
|
|
|
if (!m_mainItem) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (QQuickWindow *w = qobject_cast<QQuickWindow*>(m_mainItem)) {
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
return m_mainItem->findChild<QQuickWindow*>();
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:14:59 +00:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2013-12-10 06:14:44 +00:00
|
|
|
SwitcherItem *TabBoxHandlerPrivate::switcherItem() const
|
|
|
|
{
|
|
|
|
if (!m_mainItem) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (SwitcherItem *i = qobject_cast<SwitcherItem*>(m_mainItem)) {
|
|
|
|
return i;
|
|
|
|
} else if (QQuickWindow *w = qobject_cast<QQuickWindow*>(m_mainItem)) {
|
|
|
|
return w->contentItem()->findChild<SwitcherItem*>();
|
|
|
|
}
|
|
|
|
return m_mainItem->findChild<SwitcherItem*>();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2014-06-10 09:14:59 +00:00
|
|
|
#endif
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
ClientModel* TabBoxHandlerPrivate::clientModel() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-09 09:12:00 +00:00
|
|
|
return m_clientModel;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
DesktopModel* TabBoxHandlerPrivate::desktopModel() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-09 09:12:00 +00:00
|
|
|
return m_desktopModel;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
void TabBoxHandlerPrivate::updateHighlightWindows()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isShown || config.tabBoxMode() != TabBoxConfig::ClientTabBox)
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
2010-10-17 19:49:07 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
TabBoxClient *currentClient = q->client(index);
|
2013-12-10 06:14:44 +00:00
|
|
|
QWindow *w = window();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2013-04-12 18:15:31 +00:00
|
|
|
if (q->isKWinCompositing()) {
|
2012-04-10 23:19:15 +00:00
|
|
|
if (lastRaisedClient)
|
2013-12-10 06:14:44 +00:00
|
|
|
q->elevateClient(lastRaisedClient, w ? w->winId() : 0, false);
|
2012-04-10 23:19:15 +00:00
|
|
|
lastRaisedClient = currentClient;
|
|
|
|
if (currentClient)
|
2013-12-10 06:14:44 +00:00
|
|
|
q->elevateClient(currentClient, w ? w->winId() : 0, true);
|
2012-04-10 23:19:15 +00:00
|
|
|
} else {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (lastRaisedClient) {
|
|
|
|
if (lastRaisedClientSucc)
|
|
|
|
q->restack(lastRaisedClient, lastRaisedClientSucc);
|
|
|
|
// TODO lastRaisedClient->setMinimized( lastRaisedClientWasMinimized );
|
|
|
|
}
|
|
|
|
|
2010-10-17 19:49:07 +00:00
|
|
|
lastRaisedClient = currentClient;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (lastRaisedClient) {
|
2010-10-17 19:49:07 +00:00
|
|
|
// TODO if ( (lastRaisedClientWasMinimized = lastRaisedClient->isMinimized()) )
|
|
|
|
// lastRaisedClient->setMinimized( false );
|
|
|
|
TabBoxClientList order = q->stackingOrder();
|
2012-05-20 13:52:24 +00:00
|
|
|
int succIdx = order.count() + 1;
|
|
|
|
for (int i=0; i<order.count(); ++i) {
|
|
|
|
if (order.at(i).data() == lastRaisedClient) {
|
|
|
|
succIdx = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 15:42:43 +00:00
|
|
|
lastRaisedClientSucc = (succIdx < order.count()) ? order.at(succIdx).data() : nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
q->raiseClient(lastRaisedClient);
|
2010-10-17 19:49:07 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-17 19:49:07 +00:00
|
|
|
|
2013-09-10 11:29:06 +00:00
|
|
|
xcb_window_t wId;
|
|
|
|
QVector< xcb_window_t > data;
|
2011-10-30 15:07:14 +00:00
|
|
|
if (config.isShowTabBox() && w) {
|
|
|
|
wId = w->winId();
|
2010-10-17 19:49:07 +00:00
|
|
|
data.resize(2);
|
|
|
|
data[ 1 ] = wId;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-10-17 19:49:07 +00:00
|
|
|
wId = QX11Info::appRootWindow();
|
|
|
|
data.resize(1);
|
|
|
|
}
|
|
|
|
data[ 0 ] = currentClient ? currentClient->window() : 0L;
|
2013-09-10 11:29:06 +00:00
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, wId, m_highlightWindowsAtom,
|
|
|
|
m_highlightWindowsAtom, 32, data.size(), data.constData());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandlerPrivate::endHighlightWindows(bool abort)
|
|
|
|
{
|
2012-04-10 23:19:15 +00:00
|
|
|
TabBoxClient *currentClient = q->client(index);
|
2013-12-10 06:14:44 +00:00
|
|
|
QWindow *w = window();
|
2012-04-10 23:19:15 +00:00
|
|
|
if (currentClient)
|
2013-12-10 06:14:44 +00:00
|
|
|
q->elevateClient(currentClient, w ? w->winId() : 0, false);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (abort && lastRaisedClient && lastRaisedClientSucc)
|
|
|
|
q->restack(lastRaisedClient, lastRaisedClientSucc);
|
2014-02-24 15:42:43 +00:00
|
|
|
lastRaisedClient = nullptr;
|
|
|
|
lastRaisedClientSucc = nullptr;
|
2009-09-13 11:36:45 +00:00
|
|
|
// highlight windows
|
2013-12-10 06:14:44 +00:00
|
|
|
xcb_delete_property(connection(), config.isShowTabBox() && w ? w->winId() : rootWindow(), m_highlightWindowsAtom);
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:14:59 +00:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2013-12-10 06:14:44 +00:00
|
|
|
QObject *TabBoxHandlerPrivate::createSwitcherItem(bool desktopMode)
|
|
|
|
{
|
|
|
|
auto findSwitcher = [this, desktopMode] {
|
|
|
|
QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(config.layoutName());
|
|
|
|
const QString type = desktopMode ? QStringLiteral("KWin/DesktopSwitcher") : QStringLiteral("KWin/WindowSwitcher");
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query(type, constraint);
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
// load default
|
|
|
|
constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(QStringLiteral("informative"));
|
|
|
|
offers = KServiceTypeTrader::self()->query(type, constraint);
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
qDebug() << "could not find default window switcher layout";
|
|
|
|
return KService::Ptr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return offers.first();
|
|
|
|
};
|
|
|
|
KService::Ptr service = findSwitcher();
|
|
|
|
if (!service) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (service->property(QStringLiteral("X-Plasma-API")).toString() != QStringLiteral("declarativeappletscript")) {
|
|
|
|
qDebug() << "Window Switcher Layout is no declarativeappletscript";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto findScriptFile = [desktopMode, service] {
|
|
|
|
const QString pluginName = service->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString();
|
|
|
|
const QString scriptName = service->property(QStringLiteral("X-Plasma-MainScript")).toString();
|
|
|
|
const QString type = desktopMode ? QStringLiteral("/desktoptabbox/") : QStringLiteral("/tabbox/");
|
|
|
|
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME) + type + pluginName + QStringLiteral("/contents/") + scriptName);
|
|
|
|
};
|
|
|
|
const QString file = findScriptFile();
|
|
|
|
if (file.isNull()) {
|
|
|
|
qDebug() << "Could not find QML file for window switcher";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
m_qmlComponent->loadUrl(QUrl::fromLocalFile(file));
|
|
|
|
if (m_qmlComponent->isError()) {
|
|
|
|
qDebug() << "Component failed to load: " << m_qmlComponent->errors();
|
|
|
|
QStringList args;
|
|
|
|
args << QStringLiteral("--passivepopup") << i18n("The Window Switcher installation is broken, resources are missing.\n"
|
|
|
|
"Contact your distribution about this.") << QStringLiteral("20");
|
|
|
|
KProcess::startDetached(QStringLiteral("kdialog"), args);
|
|
|
|
} else {
|
2014-03-03 12:42:13 +00:00
|
|
|
QObject *object = m_qmlComponent->create(m_qmlContext.data());
|
2013-12-10 06:14:44 +00:00
|
|
|
if (desktopMode) {
|
|
|
|
m_desktopTabBoxes.insert(config.layoutName(), object);
|
|
|
|
} else {
|
|
|
|
m_clientTabBoxes.insert(config.layoutName(), object);
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-10 09:14:59 +00:00
|
|
|
#endif
|
2013-12-10 06:14:44 +00:00
|
|
|
|
|
|
|
void TabBoxHandlerPrivate::show()
|
|
|
|
{
|
2014-06-10 09:14:59 +00:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2014-03-03 12:42:13 +00:00
|
|
|
if (m_qmlContext.isNull()) {
|
2013-12-10 06:14:44 +00:00
|
|
|
qmlRegisterType<SwitcherItem>("org.kde.kwin", 2, 0, "Switcher");
|
2014-03-03 12:42:13 +00:00
|
|
|
m_qmlContext.reset(new QQmlContext(Scripting::self()->qmlEngine()));
|
2013-12-10 06:14:44 +00:00
|
|
|
}
|
|
|
|
if (m_qmlComponent.isNull()) {
|
2014-03-03 12:42:13 +00:00
|
|
|
m_qmlComponent.reset(new QQmlComponent(Scripting::self()->qmlEngine()));
|
2013-12-10 06:14:44 +00:00
|
|
|
}
|
|
|
|
const bool desktopMode = (config.tabBoxMode() == TabBoxConfig::DesktopTabBox);
|
|
|
|
auto findMainItem = [this](const QMap<QString, QObject *> &tabBoxes) -> QObject* {
|
|
|
|
auto it = tabBoxes.constFind(config.layoutName());
|
|
|
|
if (it != tabBoxes.constEnd()) {
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
m_mainItem = nullptr;
|
|
|
|
m_mainItem = desktopMode ? findMainItem(m_desktopTabBoxes) : findMainItem(m_clientTabBoxes);
|
|
|
|
if (!m_mainItem) {
|
|
|
|
m_mainItem = createSwitcherItem(desktopMode);
|
|
|
|
if (!m_mainItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (SwitcherItem *item = switcherItem()) {
|
|
|
|
if (!item->model()) {
|
|
|
|
QAbstractItemModel *model = nullptr;
|
|
|
|
if (desktopMode) {
|
|
|
|
model = desktopModel();
|
|
|
|
} else {
|
|
|
|
model = clientModel();
|
|
|
|
}
|
|
|
|
item->setModel(model);
|
|
|
|
}
|
|
|
|
item->setAllDesktops(config.clientDesktopMode() == TabBoxConfig::AllDesktopsClients);
|
|
|
|
item->setCurrentIndex(index.row());
|
|
|
|
// everything is prepared, so let's make the whole thing visible
|
|
|
|
item->setVisible(true);
|
|
|
|
}
|
2014-06-10 09:14:59 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
/***********************************************
|
|
|
|
* TabBoxHandler
|
|
|
|
***********************************************/
|
|
|
|
|
2014-05-27 08:10:07 +00:00
|
|
|
TabBoxHandler::TabBoxHandler(QObject *parent)
|
|
|
|
: QObject(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
KWin::TabBox::tabBox = this;
|
2011-01-30 14:34:42 +00:00
|
|
|
d = new TabBoxHandlerPrivate(this);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxHandler::~TabBoxHandler()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
delete d;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
const KWin::TabBox::TabBoxConfig& TabBoxHandler::config() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
return d->config;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandler::setConfig(const TabBoxConfig& config)
|
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
d->config = config;
|
|
|
|
emit configChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
void TabBoxHandler::show()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
d->isShown = true;
|
2014-02-24 15:42:43 +00:00
|
|
|
d->lastRaisedClient = nullptr;
|
|
|
|
d->lastRaisedClientSucc = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (d->config.isShowTabBox()) {
|
2013-12-10 06:14:44 +00:00
|
|
|
d->show();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (d->config.isHighlightWindows()) {
|
2013-09-10 09:03:28 +00:00
|
|
|
Xcb::sync();
|
2012-05-03 23:08:28 +00:00
|
|
|
// TODO this should be
|
|
|
|
// QMetaObject::invokeMethod(this, "updateHighlightWindows", Qt::QueuedConnection);
|
|
|
|
// but we somehow need to cross > 1 event cycle (likely because of queued invocation in the effects)
|
|
|
|
// to ensure the EffectWindow is present when updateHighlightWindows, thus elevating the window/tabbox
|
|
|
|
QTimer::singleShot(1, this, SLOT(updateHighlightWindows()));
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2012-05-03 23:08:28 +00:00
|
|
|
void TabBoxHandler::updateHighlightWindows()
|
|
|
|
{
|
|
|
|
d->updateHighlightWindows();
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandler::hide(bool abort)
|
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
d->isShown = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (d->config.isHighlightWindows()) {
|
|
|
|
d->endHighlightWindows(abort);
|
|
|
|
}
|
2014-06-10 09:14:59 +00:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2013-12-10 06:14:44 +00:00
|
|
|
if (SwitcherItem *item = d->switcherItem()) {
|
|
|
|
item->setVisible(false);
|
|
|
|
}
|
2014-06-10 09:14:59 +00:00
|
|
|
#endif
|
2013-12-10 06:14:44 +00:00
|
|
|
if (QQuickWindow *w = d->window()) {
|
|
|
|
w->hide();
|
|
|
|
w->destroy();
|
|
|
|
}
|
|
|
|
d->m_mainItem = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex TabBoxHandler::nextPrev(bool forward) const
|
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
QModelIndex ret;
|
|
|
|
QAbstractItemModel* model;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(d->config.tabBoxMode()) {
|
|
|
|
case TabBoxConfig::ClientTabBox:
|
|
|
|
model = d->clientModel();
|
|
|
|
break;
|
|
|
|
case TabBoxConfig::DesktopTabBox:
|
|
|
|
model = d->desktopModel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return d->index;
|
|
|
|
}
|
|
|
|
if (forward) {
|
2009-09-13 11:36:45 +00:00
|
|
|
int column = d->index.column() + 1;
|
|
|
|
int row = d->index.row();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (column == model->columnCount()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
column = 0;
|
|
|
|
row++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (row == model->rowCount())
|
2009-09-13 11:36:45 +00:00
|
|
|
row = 0;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
ret = model->index(row, column);
|
|
|
|
if (!ret.isValid())
|
|
|
|
ret = model->index(0, 0);
|
|
|
|
} else {
|
2009-09-13 11:36:45 +00:00
|
|
|
int column = d->index.column() - 1;
|
|
|
|
int row = d->index.row();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (column < 0) {
|
2009-09-13 11:36:45 +00:00
|
|
|
column = model->columnCount() - 1;
|
|
|
|
row--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (row < 0)
|
2009-09-13 11:36:45 +00:00
|
|
|
row = model->rowCount() - 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
ret = model->index(row, column);
|
|
|
|
if (!ret.isValid()) {
|
2009-10-29 17:02:54 +00:00
|
|
|
row = model->rowCount() - 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = model->columnCount() - 1; i >= 0; i--) {
|
|
|
|
ret = model->index(row, i);
|
|
|
|
if (ret.isValid())
|
2009-10-29 17:02:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (ret.isValid())
|
2009-09-13 11:36:45 +00:00
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
return d->index;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex TabBoxHandler::desktopIndex(int desktop) const
|
|
|
|
{
|
|
|
|
if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox)
|
2009-09-13 11:36:45 +00:00
|
|
|
return QModelIndex();
|
2011-01-30 14:34:42 +00:00
|
|
|
return d->desktopModel()->desktopIndex(desktop);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
QList< int > TabBoxHandler::desktopList() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox)
|
2009-09-13 11:36:45 +00:00
|
|
|
return QList< int >();
|
|
|
|
return d->desktopModel()->desktopList();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int TabBoxHandler::desktop(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
if (!index.isValid() || (d->config.tabBoxMode() != TabBoxConfig::DesktopTabBox))
|
2009-09-13 11:36:45 +00:00
|
|
|
return -1;
|
2011-01-30 14:34:42 +00:00
|
|
|
QVariant ret = d->desktopModel()->data(index, DesktopModel::DesktopRole);
|
|
|
|
if (ret.isValid())
|
2009-09-13 11:36:45 +00:00
|
|
|
return ret.toInt();
|
|
|
|
else
|
|
|
|
return -1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandler::setCurrentIndex(const QModelIndex& index)
|
|
|
|
{
|
2011-10-31 13:34:37 +00:00
|
|
|
if (d->index == index) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-04 18:27:02 +00:00
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
d->index = index;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (d->config.tabBoxMode() == TabBoxConfig::ClientTabBox) {
|
|
|
|
if (d->config.isHighlightWindows()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
d->updateHighlightWindows();
|
|
|
|
}
|
|
|
|
}
|
2011-12-02 09:48:04 +00:00
|
|
|
emit selectedIndexChanged();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-10-31 13:34:37 +00:00
|
|
|
const QModelIndex& TabBoxHandler::currentIndex() const
|
|
|
|
{
|
|
|
|
return d->index;
|
|
|
|
}
|
|
|
|
|
2012-03-20 19:01:46 +00:00
|
|
|
void TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2014-06-02 15:21:53 +00:00
|
|
|
if (!d->m_mainItem || !d->window()) {
|
2013-12-10 06:14:44 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2014-06-02 15:21:53 +00:00
|
|
|
const QList<QQuickItem*> items = d->window()->contentItem()->findChildren<QQuickItem*>(QString(), Qt::FindDirectChildrenOnly);
|
|
|
|
for (QQuickItem *item : items) {
|
|
|
|
d->window()->sendEvent(item, event);
|
|
|
|
if (event->isAccepted()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool TabBoxHandler::containsPos(const QPoint& pos) const
|
|
|
|
{
|
2013-12-10 06:14:44 +00:00
|
|
|
if (!d->m_mainItem) {
|
2011-07-09 09:12:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-10 06:14:44 +00:00
|
|
|
QWindow *w = d->window();
|
|
|
|
if (w) {
|
|
|
|
return w->geometry().contains(pos);
|
|
|
|
}
|
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2012-05-20 13:52:24 +00:00
|
|
|
QModelIndex TabBoxHandler::index(QWeakPointer<KWin::TabBox::TabBoxClient> client) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return d->clientModel()->index(client);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxClientList TabBoxHandler::clientList() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (d->config.tabBoxMode() != TabBoxConfig::ClientTabBox)
|
2009-09-13 11:36:45 +00:00
|
|
|
return TabBoxClientList();
|
|
|
|
return d->clientModel()->clientList();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
TabBoxClient* TabBoxHandler::client(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
if ((!index.isValid()) ||
|
2012-03-17 09:31:15 +00:00
|
|
|
(d->config.tabBoxMode() != TabBoxConfig::ClientTabBox))
|
2014-02-24 15:42:43 +00:00
|
|
|
return nullptr;
|
2009-09-13 11:36:45 +00:00
|
|
|
TabBoxClient* c = static_cast< TabBoxClient* >(
|
2011-01-30 14:34:42 +00:00
|
|
|
d->clientModel()->data(index, ClientModel::ClientRole).value<void *>());
|
2009-09-13 11:36:45 +00:00
|
|
|
return c;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandler::createModel(bool partialReset)
|
|
|
|
{
|
|
|
|
switch(d->config.tabBoxMode()) {
|
2012-05-20 13:52:24 +00:00
|
|
|
case TabBoxConfig::ClientTabBox: {
|
2011-01-30 14:34:42 +00:00
|
|
|
d->clientModel()->createClientList(partialReset);
|
2012-05-20 13:52:24 +00:00
|
|
|
// TODO: C++11 use lambda function
|
|
|
|
bool lastRaised = false;
|
|
|
|
bool lastRaisedSucc = false;
|
2012-12-29 06:51:05 +00:00
|
|
|
foreach (const QWeakPointer<TabBoxClient> &clientPointer, stackingOrder()) {
|
2012-05-20 13:52:24 +00:00
|
|
|
QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef();
|
|
|
|
if (!client) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (client.data() == d->lastRaisedClient) {
|
|
|
|
lastRaised = true;
|
|
|
|
}
|
|
|
|
if (client.data() == d->lastRaisedClientSucc) {
|
|
|
|
lastRaisedSucc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d->lastRaisedClient && !lastRaised)
|
2014-02-24 15:42:43 +00:00
|
|
|
d->lastRaisedClient = nullptr;
|
2012-05-20 13:52:24 +00:00
|
|
|
if (d->lastRaisedClientSucc && !lastRaisedSucc)
|
2014-02-24 15:42:43 +00:00
|
|
|
d->lastRaisedClientSucc = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
2012-05-20 13:52:24 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
case TabBoxConfig::DesktopTabBox:
|
|
|
|
d->desktopModel()->createDesktopList();
|
|
|
|
break;
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
QModelIndex TabBoxHandler::first() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
QAbstractItemModel* model;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(d->config.tabBoxMode()) {
|
|
|
|
case TabBoxConfig::ClientTabBox:
|
|
|
|
model = d->clientModel();
|
|
|
|
break;
|
|
|
|
case TabBoxConfig::DesktopTabBox:
|
|
|
|
model = d->desktopModel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QModelIndex();
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return model->index(0, 0);
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2014-02-24 15:42:43 +00:00
|
|
|
TabBoxHandler* tabBox = nullptr;
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxClient::TabBoxClient()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxClient::~TabBoxClient()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
} // namespace TabBox
|
|
|
|
} // namespace KWin
|