From e858b413a37178f7b5e2faf42a30debcb1aebc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 27 Nov 2011 17:03:35 +0100 Subject: [PATCH] Activate TabBoxClient from mouse click and close TabBox This is useful in combination of non-modal TabBox through DBus and window-strip layout. With DBus the non-modal TabBox can be started and selecting any item on the strip will end TabBox again. --- tabbox/clientmodel.cpp | 10 ++++++++++ tabbox/clientmodel.h | 5 +++++ tabbox/qml/window_strip.qml | 5 +---- tabbox/tabbox.cpp | 16 ++++++++++++++++ tabbox/tabbox.h | 1 + tabbox/tabboxhandler.h | 4 ++++ 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tabbox/clientmodel.cpp b/tabbox/clientmodel.cpp index 541d957b0d..92c748dbb5 100644 --- a/tabbox/clientmodel.cpp +++ b/tabbox/clientmodel.cpp @@ -244,5 +244,15 @@ void ClientModel::close(int i) m_clientList.at(i)->close(); } +void ClientModel::activate(int i) +{ + QModelIndex ind = index(i, 0); + if (!ind.isValid()) { + return; + } + tabBox->setCurrentIndex(ind); + tabBox->activateAndClose(); +} + } // namespace Tabbox } // namespace KWin diff --git a/tabbox/clientmodel.h b/tabbox/clientmodel.h index c091c7c096..450d66515c 100644 --- a/tabbox/clientmodel.h +++ b/tabbox/clientmodel.h @@ -98,6 +98,11 @@ public: public Q_SLOTS: void close(int index); + /** + * Activates the client at @p index and closes the TabBox. + * @param index The row index + **/ + void activate(int index); private: TabBoxClientList m_clientList; diff --git a/tabbox/qml/window_strip.qml b/tabbox/qml/window_strip.qml index f735061db4..3ce0f49cd4 100644 --- a/tabbox/qml/window_strip.qml +++ b/tabbox/qml/window_strip.qml @@ -81,10 +81,7 @@ Item { anchors.centerIn: parent MouseArea { anchors.fill: parent - onClicked: { - thumbnailListView.currentIndex = index - thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); - } + onClicked: thumbnailListView.model.activate(index) } } PlasmaComponents.Label { diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index 3c17fcbccb..eaa6e53a53 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -214,6 +214,22 @@ QVector< Window > TabBoxHandlerImpl::outlineWindowIds() const return Workspace::self()->outline()->windowIds(); } +void TabBoxHandlerImpl::activateAndClose() +{ + Client* c = NULL; + if (TabBoxClientImpl* cl = static_cast< TabBoxClientImpl* >(client(currentIndex()))) { + c = cl->client(); + } + m_tabBox->close(); + if (c) { + Workspace::self()->activateClient(c); + if (c->isShade() && options->shadeHover) + c->setShade(ShadeActivated); + if (c->isDesktop()) + Workspace::self()->setShowingDesktop(!Workspace::self()->showingDesktop()); + } +} + /********************************************************* * TabBoxClientImpl diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index a061203bbe..51a004cac2 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -61,6 +61,7 @@ public: virtual void hideOutline(); virtual void showOutline(const QRect &outline); virtual QVector< Window > outlineWindowIds() const; + virtual void activateAndClose(); private: TabBox* m_tabBox; diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h index 6b67f497c1..1355674461 100644 --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -173,6 +173,10 @@ public: * @return The first desktop window in the stacking order. */ virtual TabBoxClient* desktopClient() const = 0; + /** + * Activates the currently selected client and closes the TabBox. + **/ + virtual void activateAndClose() = 0; /** * @return The currently used TabBoxConfig