From d2c7123dc6065a510792ded36b2cd3eda9717415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 21 Aug 2011 10:44:09 +0200 Subject: [PATCH] TabBox becomes activatable through a DBus interface Therefore TabBox is changed to be controlled without pressing a modifier key. Tab and Backtab are valid keys now which can be used to navigate in the list and return, enter and space can be used to close the box (and select the client). The TabBox is exported as object /TabBox on the kwin interface providing start and close methods and signal when the TabBox got closed. --- tabbox/tabbox.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ tabbox/tabbox.h | 11 +++++++++-- tabbox/tabboxhandler.cpp | 2 ++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index 31080f8ac8..992b377c6d 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -34,6 +34,7 @@ along with this program. If not, see . // Qt #include #include +#include // KDE #include #include @@ -288,6 +289,7 @@ TabBox::TabBox(QObject *parent) , m_displayRefcount(0) , m_desktopGrab(false) , m_tabGrab(false) + , m_noModifierGrab(false) , m_forcedGlobalMouseGrab(false) , m_ready(false) { @@ -323,10 +325,12 @@ TabBox::TabBox(QObject *parent) m_tabBoxMode = TabBoxDesktopMode; // init variables connect(&m_delayedShowTimer, SIGNAL(timeout()), this, SLOT(show())); connect(Workspace::self(), SIGNAL(configChanged()), this, SLOT(reconfigure())); + QDBusConnection::sessionBus().registerObject("/TabBox", this, QDBusConnection::ExportScriptableContents); } TabBox::~TabBox() { + QDBusConnection::sessionBus().unregisterObject("/TabBox"); } void TabBox::handlerReady() @@ -668,6 +672,19 @@ void TabBox::grabbedKeyEvent(QKeyEvent* event) // tabbox has been replaced, check effects return; } + if (m_noModifierGrab) { + if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return || event->key() == Qt::Key_Space) { + Client* c = currentClient(); + close(); + if (c) { + Workspace::self()->activateClient(c); + if (c->isShade() && options->shadeHover) + c->setShade(ShadeActivated); + if (c->isDesktop()) + Workspace::self()->setShowingDesktop(!Workspace::self()->showingDesktop()); + } + } + } setCurrentIndex(m_tabBox->grabbedKeyEvent(event)); } @@ -922,11 +939,27 @@ void TabBox::modalActionsSwitch(bool enabled) action->setEnabled(enabled); } +void TabBox::start() +{ + if (isDisplayed()) { + return; + } + if (!establishTabBoxGrab()) { + return; + } + m_tabGrab = true; + m_noModifierGrab = true; + setMode(TabBoxWindowsMode); + reset(); + show(); +} + bool TabBox::startKDEWalkThroughWindows(TabBoxMode mode) { if (!establishTabBoxGrab()) return false; m_tabGrab = true; + m_noModifierGrab = false; modalActionsSwitch(false); setMode(mode); reset(); @@ -938,6 +971,7 @@ bool TabBox::startWalkThroughDesktops(TabBoxMode mode) if (!establishTabBoxGrab()) return false; m_desktopGrab = true; + m_noModifierGrab = false; modalActionsSwitch(false); setMode(mode); reset(); @@ -1100,11 +1134,15 @@ void TabBox::keyPress(int keyQt) void TabBox::close(bool abort) { + if (!isGrabbed()) { + return; + } removeTabBoxGrab(); hide(abort); modalActionsSwitch(true); m_tabGrab = false; m_desktopGrab = false; + m_noModifierGrab = false; } /*! @@ -1112,6 +1150,9 @@ void TabBox::close(bool abort) */ void TabBox::keyRelease(const XKeyEvent& ev) { + if (m_noModifierGrab) { + return; + } unsigned int mk = ev.state & (KKeyServer::modXShift() | KKeyServer::modXCtrl() | diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 41b9243453..e7018aa225 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -97,6 +97,7 @@ private: class TabBox : public QObject { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kwin") public: TabBox(QObject *parent = NULL); ~TabBox(); @@ -162,12 +163,16 @@ public: int previousDesktopFocusChain(int iDesktop) const; int nextDesktopStatic(int iDesktop) const; int previousDesktopStatic(int iDesktop) const; - void close(bool abort = false); void keyPress(int key); void keyRelease(const XKeyEvent& ev); public slots: void show(); + /** + * Only for DBus Interface to start primary KDE Walk through windows. + **/ + Q_SCRIPTABLE void start(); + Q_SCRIPTABLE void close(bool abort = false); void slotWalkThroughDesktops(); void slotWalkBackThroughDesktops(); void slotWalkThroughDesktopList(); @@ -192,7 +197,7 @@ public slots: signals: void tabBoxAdded(int); - void tabBoxClosed(); + Q_SCRIPTABLE void tabBoxClosed(); void tabBoxUpdated(); void tabBoxKeyEvent(QKeyEvent*); @@ -237,6 +242,8 @@ private: bool m_isShown; bool m_desktopGrab; bool m_tabGrab; + // true if tabbox is in modal mode which does not require holding a modifier + bool m_noModifierGrab; KShortcut m_cutWalkThroughDesktops, m_cutWalkThroughDesktopsReverse; KShortcut m_cutWalkThroughDesktopList, m_cutWalkThroughDesktopListReverse; KShortcut m_cutWalkThroughWindows, m_cutWalkThroughWindowsReverse; diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index a03dd5fe02..ac05d2670e 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -586,11 +586,13 @@ QModelIndex TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) const if (column >= model->columnCount()) column = 0; break; + case Qt::Key_Backtab: case Qt::Key_Up: row--; if (row < 0) row = model->rowCount() - 1; break; + case Qt::Key_Tab: case Qt::Key_Down: row++; if (row >= model->rowCount())