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.
This commit is contained in:
Martin Gräßlin 2011-08-21 10:44:09 +02:00
parent 245f84d835
commit d2c7123dc6
3 changed files with 52 additions and 2 deletions

View file

@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Qt
#include <QAction>
#include <QX11Info>
#include <QtDBus/QDBusConnection>
// KDE
#include <KActionCollection>
#include <KConfig>
@ -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() |

View file

@ -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;

View file

@ -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())