Add registerGlobalShortcut method to kwineffects

Implemented in KWin core to forward to new global shortcut system. This
method should be extended/changed once we go to Qt5/KF5 to make the usage
easier (no more KAction).

Each global shortcut in the effects makes use of this new method.
This commit is contained in:
Martin Gräßlin 2013-07-10 12:26:50 +02:00
parent d1d3401b9f
commit b57885a1bf
16 changed files with 46 additions and 0 deletions

View file

@ -820,6 +820,11 @@ void EffectsHandlerImpl::stopMouseInterception(Effect *effect)
}
}
void EffectsHandlerImpl::registerGlobalShortcut(const QKeySequence &shortcut, QAction *action)
{
input()->registerShortcut(shortcut, action);
}
void* EffectsHandlerImpl::getProxy(QString name)
{
// All effects start with "kwin4_effect_", prepend it to the name

View file

@ -118,6 +118,7 @@ public:
// not performing XGrabPointer
void startMouseInterception(Effect *effect, Qt::CursorShape shape) override;
void stopMouseInterception(Effect *effect) override;
void registerGlobalShortcut(const QKeySequence &shortcut, QAction *action) override;
void* getProxy(QString name) override;
void startMousePolling() override;
void stopMousePolling() override;

View file

@ -201,17 +201,20 @@ void CubeEffect::reconfigure(ReconfigureFlags)
cubeAction->setText(i18n("Desktop Cube"));
KGlobalAccel::self()->setDefaultShortcut(cubeAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F11);
KGlobalAccel::self()->setShortcut(cubeAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F11);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F11, cubeAction);
cubeShortcut = KGlobalAccel::self()->shortcut(cubeAction);
QAction* cylinderAction = new QAction(this);
cylinderAction->setObjectName(QStringLiteral("Cylinder"));
cylinderAction->setText(i18n("Desktop Cylinder"));
KGlobalAccel::self()->setShortcut(cylinderAction, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), cylinderAction);
cylinderShortcut = KGlobalAccel::self()->shortcut(cylinderAction);
QAction* sphereAction = new QAction(this);
sphereAction->setObjectName(QStringLiteral("Sphere"));
sphereAction->setText(i18n("Desktop Sphere"));
KGlobalAccel::self()->setShortcut(sphereAction, QList<QKeySequence>());
sphereShortcut = KGlobalAccel::self()->shortcut(sphereAction);
effects->registerGlobalShortcut(QKeySequence(), sphereAction);
connect(cubeAction, SIGNAL(triggered(bool)), this, SLOT(toggleCube()));
connect(cylinderAction, SIGNAL(triggered(bool)), this, SLOT(toggleCylinder()));
connect(sphereAction, SIGNAL(triggered(bool)), this, SLOT(toggleSphere()));

View file

@ -70,6 +70,7 @@ DesktopGridEffect::DesktopGridEffect()
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F8);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F8);
shortcut = KGlobalAccel::self()->shortcut(a);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F8, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggle()));
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &DesktopGridEffect::globalShortcutChanged);
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));

View file

@ -58,11 +58,13 @@ FlipSwitchEffect::FlipSwitchEffect()
flipSwitchCurrentAction->setText(i18n("Toggle Flip Switch (Current desktop)"));
KGlobalAccel::self()->setShortcut(flipSwitchCurrentAction, QList<QKeySequence>());
m_shortcutCurrent = KGlobalAccel::self()->shortcut(flipSwitchCurrentAction);
effects->registerGlobalShortcut(QKeySequence(), flipSwitchCurrentAction);
connect(flipSwitchCurrentAction, SIGNAL(triggered(bool)), this, SLOT(toggleActiveCurrent()));
QAction* flipSwitchAllAction = new QAction(this);
flipSwitchAllAction->setObjectName(QStringLiteral("FlipSwitchAll"));
flipSwitchAllAction->setText(i18n("Toggle Flip Switch (All desktops)"));
KGlobalAccel::self()->setShortcut(flipSwitchAllAction, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), flipSwitchAllAction);
m_shortcutAll = KGlobalAccel::self()->shortcut(flipSwitchAllAction);
connect(flipSwitchAllAction, SIGNAL(triggered(bool)), this, SLOT(toggleActiveAllDesktops()));
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &FlipSwitchEffect::globalShortcutChanged);

View file

@ -44,6 +44,7 @@ InvertEffect::InvertEffect()
a->setText(i18n("Toggle Invert Effect"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::META + Qt::Key_I);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::META + Qt::Key_I);
effects->registerGlobalShortcut(Qt::CTRL + Qt::META + Qt::Key_I, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleScreenInversion()));
QAction* b = new QAction(this);
@ -51,6 +52,7 @@ InvertEffect::InvertEffect()
b->setText(i18n("Toggle Invert Effect on Window"));
KGlobalAccel::self()->setDefaultShortcut(b, QList<QKeySequence>() << Qt::CTRL + Qt::META + Qt::Key_U);
KGlobalAccel::self()->setShortcut(b, QList<QKeySequence>() << Qt::CTRL + Qt::META + Qt::Key_U);
effects->registerGlobalShortcut(Qt::CTRL + Qt::META + Qt::Key_U, b);
connect(b, SIGNAL(triggered(bool)), this, SLOT(toggleWindow()));
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));

View file

@ -53,14 +53,17 @@ LookingGlassEffect::LookingGlassEffect()
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a);
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a);
a = KStandardAction::actualSize(this, SLOT(toggle()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a);
connect(effects, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)),
this, SLOT(slotMouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)));

View file

@ -54,14 +54,17 @@ MagnifierEffect::MagnifierEffect()
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a);
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a);
a = KStandardAction::actualSize(this, SLOT(toggle()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a);
connect(effects, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)),
this, SLOT(slotMouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)));

View file

@ -50,6 +50,7 @@ MouseClickEffect::MouseClickEffect()
a->setText(i18n("Toggle Effect"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Asterisk);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Asterisk);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Asterisk, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleEnabled()));
reconfigure(ReconfigureAll);

View file

@ -50,12 +50,14 @@ MouseMarkEffect::MouseMarkEffect()
a->setText(i18n("Clear All Mouse Marks"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::SHIFT + Qt::META + Qt::Key_F11);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::SHIFT + Qt::META + Qt::Key_F11);
effects->registerGlobalShortcut(Qt::SHIFT + Qt::META + Qt::Key_F11, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(clear()));
a = new QAction(this);
a->setObjectName(QStringLiteral("ClearLastMouseMark"));
a->setText(i18n("Clear Last Mouse Mark"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::SHIFT + Qt::META + Qt::Key_F12);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::SHIFT + Qt::META + Qt::Key_F12);
effects->registerGlobalShortcut(Qt::SHIFT + Qt::META + Qt::Key_F12, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(clearLast()));
connect(effects, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)),

View file

@ -71,6 +71,7 @@ PresentWindowsEffect::PresentWindowsEffect()
KGlobalAccel::self()->setDefaultShortcut(exposeAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F9);
KGlobalAccel::self()->setShortcut(exposeAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F9);
shortcut = KGlobalAccel::self()->shortcut(exposeAction);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F9, exposeAction);
connect(exposeAction, SIGNAL(triggered(bool)), this, SLOT(toggleActive()));
QAction* exposeAllAction = new QAction(this);
exposeAllAction->setObjectName(QStringLiteral("ExposeAll"));
@ -78,12 +79,14 @@ PresentWindowsEffect::PresentWindowsEffect()
KGlobalAccel::self()->setDefaultShortcut(exposeAllAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F10);
KGlobalAccel::self()->setShortcut(exposeAllAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F10);
shortcutAll = KGlobalAccel::self()->shortcut(exposeAllAction);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F10, exposeAllAction);
connect(exposeAllAction, SIGNAL(triggered(bool)), this, SLOT(toggleActiveAllDesktops()));
QAction* exposeClassAction = new QAction(this);
exposeClassAction->setObjectName(QStringLiteral("ExposeClass"));
exposeClassAction->setText(i18n("Toggle Present Windows (Window class)"));
KGlobalAccel::self()->setDefaultShortcut(exposeClassAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F7);
KGlobalAccel::self()->setShortcut(exposeClassAction, QList<QKeySequence>() << Qt::CTRL + Qt::Key_F7);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F7, exposeClassAction);
connect(exposeClassAction, SIGNAL(triggered(bool)), this, SLOT(toggleActiveClass()));
shortcutClass = KGlobalAccel::self()->shortcut(exposeClassAction);
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &PresentWindowsEffect::globalShortcutChanged);

View file

@ -37,6 +37,7 @@ ThumbnailAsideEffect::ThumbnailAsideEffect()
a->setText(i18n("Toggle Thumbnail for Current Window"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::CTRL + Qt::Key_T);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::CTRL + Qt::Key_T);
effects->registerGlobalShortcut(Qt::META + Qt::CTRL + Qt::Key_T, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleCurrentThumbnail()));
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));

View file

@ -60,6 +60,7 @@ TrackMouseEffect::TrackMouseEffect()
m_action->setText(i18n("Track mouse"));
KGlobalAccel::self()->setDefaultShortcut(m_action, QList<QKeySequence>());
KGlobalAccel::self()->setShortcut(m_action, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), m_action);
connect(m_action, SIGNAL(triggered(bool)), this, SLOT(toggle()));

View file

@ -63,6 +63,7 @@ WindowGeometry::WindowGeometry()
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::SHIFT + Qt::Key_F11);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::CTRL + Qt::SHIFT + Qt::Key_F11);
effects->registerGlobalShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_F11, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggle()));

View file

@ -67,20 +67,24 @@ ZoomEffect::ZoomEffect()
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Equal);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a);
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Minus);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a);
a = KStandardAction::actualSize(this, SLOT(actualSize()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_0);
effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a);
a = new QAction(this);
a->setObjectName(QStringLiteral("MoveZoomLeft"));
a->setText(i18n("Move Zoomed Area to Left"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Left);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Left);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Left, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveZoomLeft()));
a = new QAction(this);
@ -88,6 +92,7 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area to Right"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Right);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Right);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Right, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveZoomRight()));
a = new QAction(this);
@ -95,6 +100,7 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area Upwards"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Up);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Up);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Up, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveZoomUp()));
a = new QAction(this);
@ -102,6 +108,7 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area Downwards"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Down);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_Down);
effects->registerGlobalShortcut(Qt::META + Qt::Key_Down, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveZoomDown()));
// TODO: these two actions don't belong into the effect. They need to be moved into KWin core
@ -110,6 +117,7 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Mouse to Focus"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F5);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F5);
effects->registerGlobalShortcut(Qt::META + Qt::Key_F5, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveMouseToFocus()));
a = new QAction(this);
@ -117,6 +125,7 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Mouse to Center"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F6);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_F6);
effects->registerGlobalShortcut(Qt::META + Qt::Key_F6, a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(moveMouseToCenter()));
timeline.setDuration(350);

View file

@ -735,6 +735,14 @@ public:
**/
virtual void stopMouseInterception(Effect *effect) = 0;
/**
* @brief Registers a global shortcut with the provided @p action.
*
* @param shortcut The global shortcut which should trigger the action
* @param action The action which gets triggered when the shortcut matches
*/
virtual void registerGlobalShortcut(const QKeySequence &shortcut, QAction *action) = 0;
/**
* Retrieve the proxy class for an effect if it has one. Will return NULL if
* the effect isn't loaded or doesn't have a proxy class.