2009-09-13 11:36:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
|
|
|
|
|
|
|
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"
|
|
|
|
// tabbox
|
|
|
|
#include "clientitemdelegate.h"
|
|
|
|
#include "clientmodel.h"
|
2011-10-30 15:07:14 +00:00
|
|
|
#include "declarative.h"
|
2009-09-13 11:36:45 +00:00
|
|
|
#include "desktopitemdelegate.h"
|
|
|
|
#include "desktopmodel.h"
|
|
|
|
#include "itemlayoutconfig.h"
|
|
|
|
#include "tabboxconfig.h"
|
|
|
|
#include "tabboxview.h"
|
|
|
|
// Qt
|
|
|
|
#include <qdom.h>
|
2011-07-09 08:32:26 +00:00
|
|
|
#include <QtCore/QtConcurrentRun>
|
|
|
|
#include <QtCore/QFutureWatcher>
|
2009-09-13 11:36:45 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
// KDE
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KStandardDirs>
|
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 currently shown outline.
|
|
|
|
*/
|
|
|
|
void updateOutline();
|
|
|
|
/**
|
|
|
|
* Updates the current highlight window state
|
|
|
|
*/
|
|
|
|
void updateHighlightWindows();
|
|
|
|
/**
|
|
|
|
* Ends window highlighting
|
|
|
|
*/
|
|
|
|
void endHighlightWindows(bool abort = false);
|
|
|
|
|
|
|
|
ClientModel* clientModel() const;
|
|
|
|
DesktopModel* desktopModel() const;
|
2011-07-09 09:12:00 +00:00
|
|
|
void createView();
|
2011-01-30 14:34:42 +00:00
|
|
|
void parseConfig(const QString& fileName);
|
|
|
|
|
|
|
|
TabBoxHandler *q; // public pointer
|
|
|
|
// members
|
|
|
|
TabBoxConfig config;
|
|
|
|
TabBoxView* view;
|
2011-10-30 15:07:14 +00:00
|
|
|
DeclarativeView *m_declarativeView;
|
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.
|
|
|
|
* Used to determine if the outline has to be updated, etc.
|
|
|
|
*/
|
|
|
|
bool isShown;
|
|
|
|
QMap< QString, ItemLayoutConfig > tabBoxLayouts;
|
|
|
|
TabBoxClient *lastRaisedClient, *lastRaisedClientSucc;
|
|
|
|
};
|
|
|
|
|
|
|
|
TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q)
|
2011-07-09 09:12:00 +00:00
|
|
|
: view(NULL)
|
2011-10-30 15:07:14 +00:00
|
|
|
, m_declarativeView(NULL)
|
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;
|
2010-10-17 19:49:07 +00:00
|
|
|
lastRaisedClient = 0;
|
|
|
|
lastRaisedClientSucc = 0;
|
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);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// load the layouts
|
2011-07-09 08:32:26 +00:00
|
|
|
QFuture< void> future = QtConcurrent::run(this, &TabBoxHandlerPrivate::parseConfig, KStandardDirs::locate("data", "kwin/DefaultTabBoxLayouts.xml"));
|
|
|
|
QFutureWatcher< void > *watcher = new QFutureWatcher< void >(q);
|
|
|
|
watcher->setFuture(future);
|
|
|
|
q->connect(watcher, SIGNAL(finished()), q, SIGNAL(ready()));
|
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
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
delete view;
|
2011-10-30 15:07:14 +00:00
|
|
|
delete m_declarativeView;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-07-09 09:12:00 +00:00
|
|
|
void TabBoxHandlerPrivate::createView()
|
|
|
|
{
|
|
|
|
view = new TabBoxView(m_clientModel, m_desktopModel);
|
|
|
|
if (tabBoxLayouts.contains(config.layoutName())) {
|
|
|
|
view->clientDelegate()->setConfig(tabBoxLayouts.value(config.layoutName()));
|
|
|
|
view->desktopDelegate()->setConfig(tabBoxLayouts.value(config.layoutName()));
|
|
|
|
} else {
|
|
|
|
view->clientDelegate()->setConfig(tabBoxLayouts.value("Default"));
|
|
|
|
view->desktopDelegate()->setConfig(tabBoxLayouts.value("Desktop"));
|
|
|
|
}
|
|
|
|
if (tabBoxLayouts.contains(config.selectedItemLayoutName())) {
|
|
|
|
view->additionalClientDelegate()->setConfig(tabBoxLayouts.value(config.selectedItemLayoutName()));
|
|
|
|
} else {
|
|
|
|
view->additionalClientDelegate()->setConfig(tabBoxLayouts.value("Text"));
|
|
|
|
}
|
|
|
|
view->desktopDelegate()->setLayouts(tabBoxLayouts);
|
|
|
|
emit q->configChanged();
|
|
|
|
view->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
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::updateOutline()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (config.tabBoxMode() != TabBoxConfig::ClientTabBox)
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
// if ( c == NULL || !m_isShown || !c->isShown( true ) || !c->isOnCurrentDesktop())
|
2011-07-09 09:12:00 +00:00
|
|
|
if (!isShown || clientModel()->data(index, ClientModel::EmptyRole).toBool()) {
|
2011-04-28 09:16:27 +00:00
|
|
|
q->hideOutline();
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-09 09:12:00 +00:00
|
|
|
TabBoxClient* c = static_cast< TabBoxClient* >(m_clientModel->data(index, ClientModel::ClientRole).value<void *>());
|
2011-04-28 09:16:27 +00:00
|
|
|
q->showOutline(QRect(c->x(), c->y(), c->width(), c->height()));
|
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
|
|
|
|
2009-09-13 11:36:45 +00:00
|
|
|
Display *dpy = QX11Info::display();
|
2011-01-30 14:34:42 +00:00
|
|
|
TabBoxClient *currentClient = q->client(index);
|
|
|
|
|
|
|
|
if (!KWindowSystem::compositingActive()) {
|
|
|
|
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();
|
2011-01-30 14:34:42 +00:00
|
|
|
int succIdx = order.indexOf(lastRaisedClient) + 1; // this is likely related to the index parameter?!
|
|
|
|
lastRaisedClientSucc = (succIdx < order.count()) ? order.at(succIdx) : 0;
|
|
|
|
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
|
|
|
|
|
|
|
WId wId;
|
|
|
|
QVector< WId > data;
|
2011-10-30 15:07:14 +00:00
|
|
|
QWidget *w = NULL;
|
|
|
|
if (view && view->isVisible()) {
|
|
|
|
w = view;
|
|
|
|
} else if (m_declarativeView && m_declarativeView->isVisible()) {
|
|
|
|
w = m_declarativeView;
|
|
|
|
}
|
|
|
|
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;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (config.isShowOutline()) {
|
2011-04-28 09:16:27 +00:00
|
|
|
QVector<Window> outlineWindows = q->outlineWindowIds();
|
|
|
|
data.resize(2+outlineWindows.size());
|
|
|
|
for (int i=0; i<outlineWindows.size(); ++i) {
|
|
|
|
data[2+i] = outlineWindows[i];
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_HIGHLIGHT", False);
|
|
|
|
XChangeProperty(dpy, wId, atom, atom, 32, PropModeReplace,
|
|
|
|
reinterpret_cast<unsigned char *>(data.data()), data.size());
|
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)
|
|
|
|
{
|
|
|
|
if (abort && lastRaisedClient && lastRaisedClientSucc)
|
|
|
|
q->restack(lastRaisedClient, lastRaisedClientSucc);
|
2010-10-17 19:49:07 +00:00
|
|
|
lastRaisedClient = 0;
|
|
|
|
lastRaisedClientSucc = 0;
|
2009-09-13 11:36:45 +00:00
|
|
|
// highlight windows
|
|
|
|
Display *dpy = QX11Info::display();
|
|
|
|
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_HIGHLIGHT", False);
|
2011-07-09 09:12:00 +00:00
|
|
|
XDeleteProperty(dpy, config.isShowTabBox() && view ? view->winId() : QX11Info::appRootWindow(), atom);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Based on the implementation of Kopete's
|
|
|
|
* contaclistlayoutmanager.cpp by Nikolaj Hald Nielsen and
|
|
|
|
* Roman Jarosz
|
|
|
|
***********************************************************/
|
2011-01-30 14:34:42 +00:00
|
|
|
void TabBoxHandlerPrivate::parseConfig(const QString& fileName)
|
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
// open the file
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!QFile::exists(fileName)) {
|
|
|
|
kDebug(1212) << "File " << fileName << " does not exist";
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
QDomDocument doc("Layouts");
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
kDebug(1212) << "Error reading file " << fileName;
|
2009-09-13 11:36:45 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (!doc.setContent(&file)) {
|
|
|
|
kDebug(1212) << "Error parsing file " << fileName;
|
2009-09-13 11:36:45 +00:00
|
|
|
file.close();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
file.close();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QDomElement layouts_element = doc.firstChildElement("tabbox_layouts");
|
|
|
|
QDomNodeList layouts = layouts_element.elementsByTagName("layout");
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < layouts.size(); i++) {
|
|
|
|
QDomNode layout = layouts.item(i);
|
2009-09-13 11:36:45 +00:00
|
|
|
ItemLayoutConfig currentLayout;
|
|
|
|
|
|
|
|
// parse top elements
|
|
|
|
QDomElement element = layout.toElement();
|
2011-01-30 14:34:42 +00:00
|
|
|
QString layoutName = element.attribute("name", "");
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const bool highlightIcon = (element.attribute("highlight_selected_icon", "true").compare("true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentLayout.setHighlightSelectedIcons(highlightIcon);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const bool grayscaleIcon = (element.attribute("grayscale_deselected_icon", "false").compare("true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentLayout.setGrayscaleDeselectedIcons(grayscaleIcon);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// rows
|
2011-01-30 14:34:42 +00:00
|
|
|
QDomNodeList rows = element.elementsByTagName("row");
|
|
|
|
for (int j = 0; j < rows.size(); j++) {
|
|
|
|
QDomNode rowNode = rows.item(j);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
ItemLayoutConfigRow row;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QDomNodeList elements = rowNode.toElement().elementsByTagName("element");
|
|
|
|
for (int k = 0; k < elements.size(); k++) {
|
|
|
|
QDomNode elementNode = elements.item(k);
|
2009-09-13 11:36:45 +00:00
|
|
|
QDomElement currentElement = elementNode.toElement();
|
|
|
|
|
|
|
|
ItemLayoutConfigRowElement::ElementType type = ItemLayoutConfigRowElement::ElementType(currentElement.attribute(
|
2011-01-30 14:34:42 +00:00
|
|
|
"type", int(ItemLayoutConfigRowElement::ElementClientName)).toInt());
|
2009-09-13 11:36:45 +00:00
|
|
|
ItemLayoutConfigRowElement currentRowElement;
|
2011-01-30 14:34:42 +00:00
|
|
|
currentRowElement.setType(type);
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
// width - used by all types
|
2011-01-30 14:34:42 +00:00
|
|
|
qreal width = currentElement.attribute("width", "0.0").toDouble();
|
|
|
|
currentRowElement.setWidth(width);
|
|
|
|
switch(type) {
|
|
|
|
case ItemLayoutConfigRowElement::ElementEmpty:
|
|
|
|
row.addElement(currentRowElement);
|
|
|
|
break;
|
|
|
|
case ItemLayoutConfigRowElement::ElementIcon: {
|
|
|
|
qreal iconWidth = currentElement.attribute("icon_size", "16.0").toDouble();
|
|
|
|
currentRowElement.setIconSize(QSizeF(iconWidth, iconWidth));
|
|
|
|
currentRowElement.setRowSpan(currentElement.attribute("row_span", "true").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
row.addElement(currentRowElement);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ItemLayoutConfigRowElement::ElementClientList: {
|
|
|
|
currentRowElement.setStretch(currentElement.attribute("stretch", "false").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentRowElement.setClientListLayoutName(currentElement.attribute("layout_name", ""));
|
|
|
|
QString layoutMode = currentElement.attribute("layout_mode", "horizontal");
|
|
|
|
if (layoutMode.compare("horizontal", Qt::CaseInsensitive) == 0)
|
|
|
|
currentRowElement.setClientListLayoutMode(TabBoxConfig::HorizontalLayout);
|
|
|
|
else if (layoutMode.compare("vertical", Qt::CaseInsensitive) == 0)
|
|
|
|
currentRowElement.setClientListLayoutMode(TabBoxConfig::VerticalLayout);
|
|
|
|
else if (layoutMode.compare("tabular", Qt::CaseInsensitive) == 0)
|
|
|
|
currentRowElement.setClientListLayoutMode(TabBoxConfig::HorizontalVerticalLayout);
|
|
|
|
row.addElement(currentRowElement);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: { // text elements
|
|
|
|
currentRowElement.setStretch(currentElement.attribute("stretch", "false").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentRowElement.setSmallTextSize(currentElement.attribute("small", "false").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentRowElement.setBold(currentElement.attribute("bold", "false").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentRowElement.setItalic(currentElement.attribute("italic", "false").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
currentRowElement.setItalicMinimized(currentElement.attribute("italic_minimized", "true").compare(
|
|
|
|
"true", Qt::CaseInsensitive) == 0);
|
|
|
|
|
|
|
|
currentRowElement.setPrefix(currentElement.attribute("prefix", ""));
|
|
|
|
currentRowElement.setSuffix(currentElement.attribute("suffix", ""));
|
|
|
|
currentRowElement.setPrefixMinimized(currentElement.attribute("prefix_minimized", ""));
|
|
|
|
currentRowElement.setSuffixMinimzed(currentElement.attribute("suffix_minimized", ""));
|
|
|
|
|
|
|
|
QString halign = currentElement.attribute("horizontal_alignment", "left");
|
|
|
|
Qt::Alignment alignment;
|
|
|
|
if (halign.compare("left", Qt::CaseInsensitive) == 0)
|
|
|
|
alignment = Qt::AlignLeft;
|
|
|
|
else if (halign.compare("right", Qt::CaseInsensitive) == 0)
|
|
|
|
alignment = Qt::AlignRight;
|
|
|
|
else
|
|
|
|
alignment = Qt::AlignCenter;
|
|
|
|
QString valign = currentElement.attribute("vertical_alignment", "center");
|
|
|
|
if (valign.compare("top", Qt::CaseInsensitive) == 0)
|
|
|
|
alignment = alignment | Qt::AlignTop;
|
|
|
|
else if (valign.compare("bottom", Qt::CaseInsensitive) == 0)
|
|
|
|
alignment = alignment | Qt::AlignBottom;
|
|
|
|
else
|
|
|
|
alignment = alignment | Qt::AlignVCenter;
|
|
|
|
currentRowElement.setAlignment(alignment);
|
|
|
|
|
|
|
|
row.addElement(currentRowElement);
|
|
|
|
break;
|
|
|
|
}// case default
|
|
|
|
} // switch type
|
|
|
|
} // for loop elements
|
|
|
|
|
|
|
|
currentLayout.addRow(row);
|
|
|
|
} // for loop rows
|
|
|
|
if (!layoutName.isEmpty()) {
|
|
|
|
tabBoxLayouts.insert(layoutName, currentLayout);
|
|
|
|
}
|
|
|
|
} // for loop layouts
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
/***********************************************
|
|
|
|
* TabBoxHandler
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
TabBoxHandler::TabBoxHandler()
|
|
|
|
: QObject()
|
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)
|
|
|
|
{
|
|
|
|
if (config.layoutName() != d->config.layoutName()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
// new item layout config
|
2011-07-09 09:12:00 +00:00
|
|
|
if (d->tabBoxLayouts.contains(config.layoutName()) && d->view) {
|
2011-01-30 14:34:42 +00:00
|
|
|
d->view->clientDelegate()->setConfig(d->tabBoxLayouts.value(config.layoutName()));
|
|
|
|
d->view->desktopDelegate()->setConfig(d->tabBoxLayouts.value(config.layoutName()));
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (config.selectedItemLayoutName() != d->config.selectedItemLayoutName()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
// TODO: desktop layouts
|
2011-07-09 09:12:00 +00:00
|
|
|
if (d->tabBoxLayouts.contains(config.selectedItemLayoutName()) && d->view)
|
2011-01-30 14:34:42 +00:00
|
|
|
d->view->additionalClientDelegate()->setConfig(d->tabBoxLayouts.value(config.selectedItemLayoutName()));
|
|
|
|
}
|
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;
|
2010-10-17 19:49:07 +00:00
|
|
|
d->lastRaisedClient = 0;
|
|
|
|
d->lastRaisedClientSucc = 0;
|
2009-09-13 11:36:45 +00:00
|
|
|
// show the outline
|
2011-01-30 14:34:42 +00:00
|
|
|
if (d->config.isShowOutline()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
d->updateOutline();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (d->config.isShowTabBox()) {
|
2011-10-30 15:07:14 +00:00
|
|
|
if (d->config.tabBoxMode() == TabBoxConfig::ClientTabBox) {
|
|
|
|
// use declarative view
|
|
|
|
if (!d->m_declarativeView) {
|
|
|
|
d->m_declarativeView = new DeclarativeView(d->clientModel());
|
|
|
|
}
|
|
|
|
d->m_declarativeView->show();
|
|
|
|
d->m_declarativeView->setCurrentIndex(d->index);
|
|
|
|
} else {
|
|
|
|
if (!d->view) {
|
|
|
|
d->createView();
|
|
|
|
}
|
|
|
|
d->view->show();
|
|
|
|
d->view->updateGeometry();
|
2011-07-09 09:12:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (d->config.isHighlightWindows()) {
|
2010-10-17 19:49:07 +00:00
|
|
|
d->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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (d->config.isShowOutline()) {
|
2011-04-28 09:16:27 +00:00
|
|
|
hideOutline();
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-07-09 09:12:00 +00:00
|
|
|
if (d->view) {
|
|
|
|
d->view->hide();
|
|
|
|
}
|
2011-10-30 15:07:14 +00:00
|
|
|
if (d->m_declarativeView) {
|
|
|
|
d->m_declarativeView->hide();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
int TabBoxHandler::currentSelectedDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return desktop(d->index);
|
|
|
|
}
|
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;
|
|
|
|
}
|
2011-07-09 09:12:00 +00:00
|
|
|
if (d->view) {
|
|
|
|
d->view->setCurrentIndex(index);
|
|
|
|
}
|
2011-10-30 15:07:14 +00:00
|
|
|
if (d->m_declarativeView) {
|
|
|
|
d->m_declarativeView->setCurrentIndex(index);
|
|
|
|
}
|
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.isShowOutline()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
d->updateOutline();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (d->config.isHighlightWindows()) {
|
2009-09-13 11:36:45 +00:00
|
|
|
d->updateHighlightWindows();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QModelIndex TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) 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;
|
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
int column = d->index.column();
|
|
|
|
int row = d->index.row();
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(event->key()) {
|
|
|
|
case Qt::Key_Left:
|
|
|
|
column--;
|
|
|
|
if (column < 0)
|
|
|
|
column = model->columnCount() - 1;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
column++;
|
|
|
|
if (column >= model->columnCount())
|
|
|
|
column = 0;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
row--;
|
|
|
|
if (row < 0)
|
|
|
|
row = model->rowCount() - 1;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
row++;
|
|
|
|
if (row >= model->rowCount())
|
|
|
|
row = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// do not do anything for any other key
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = model->index(row, column);
|
|
|
|
|
|
|
|
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
|
|
|
bool TabBoxHandler::containsPos(const QPoint& pos) const
|
|
|
|
{
|
2011-10-30 15:07:14 +00:00
|
|
|
QWidget *w = NULL;
|
|
|
|
if (d->view && d->view->isVisible()) {
|
|
|
|
w = d->view;
|
|
|
|
} else if (d->m_declarativeView && d->m_declarativeView->isVisible()) {
|
|
|
|
w = d->m_declarativeView;
|
|
|
|
} else {
|
2011-07-09 09:12:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-30 15:07:14 +00:00
|
|
|
return w->geometry().contains(pos);
|
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::indexAt(const QPoint& pos) const
|
|
|
|
{
|
2011-10-30 15:07:14 +00:00
|
|
|
if (d->view && d->view->isVisible()) {
|
|
|
|
QPoint widgetPos = d->view->mapFromGlobal(pos);
|
|
|
|
return d->view->indexAt(widgetPos);
|
|
|
|
} else if (d->m_declarativeView && d->m_declarativeView->isVisible()) {
|
|
|
|
QPoint widgetPos = d->m_declarativeView->mapFromGlobal(pos);
|
|
|
|
return d->m_declarativeView->indexAt(widgetPos);
|
2011-07-09 09:12:00 +00:00
|
|
|
}
|
2011-10-30 15:07:14 +00:00
|
|
|
return QModelIndex();
|
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::index(KWin::TabBox::TabBoxClient* client) const
|
|
|
|
{
|
|
|
|
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()) ||
|
|
|
|
(d->config.tabBoxMode() != TabBoxConfig::ClientTabBox) ||
|
|
|
|
(d->clientModel()->data(index, ClientModel::EmptyRole).toBool()))
|
2009-09-13 11:36:45 +00:00
|
|
|
return NULL;
|
|
|
|
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()) {
|
|
|
|
case TabBoxConfig::ClientTabBox:
|
|
|
|
d->clientModel()->createClientList(partialReset);
|
2011-02-14 20:17:49 +00:00
|
|
|
if (d->lastRaisedClient && !stackingOrder().contains(d->lastRaisedClient))
|
|
|
|
d->lastRaisedClient = 0;
|
|
|
|
if (d->lastRaisedClientSucc && !stackingOrder().contains(d->lastRaisedClientSucc))
|
|
|
|
d->lastRaisedClientSucc = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
case TabBoxConfig::DesktopTabBox:
|
|
|
|
d->desktopModel()->createDesktopList();
|
|
|
|
break;
|
2009-09-13 11:36:45 +00:00
|
|
|
}
|
2011-07-09 09:12:00 +00:00
|
|
|
if (d->view) {
|
|
|
|
d->view->updateGeometry();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
QWidget* TabBoxHandler::tabBoxView() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-09-13 11:36:45 +00:00
|
|
|
return d->view;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-13 11:36:45 +00:00
|
|
|
|
|
|
|
TabBoxHandler* tabBox = 0;
|
|
|
|
|
|
|
|
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
|