Remove KGlobalAccel bits from Platform

With the addition of KGlobalAccel::globalShortcutActiveChanged(),
there's a way to monitor all triggered actions without adding any
boilerplate code.

This change removes the KGlobalAccel bits from the Platform class. This
reduces the amount of boilerplate code; currently we need to be careful
about ensuring that Platform::setupActionForKGlobalAccel() is called.
Another reason behind this change is to simplify the api of Platform and
remove things that don't have anything to do with outputs.
This commit is contained in:
Vlad Zahorodnii 2022-10-24 17:37:57 +03:00
parent abf24cec4a
commit daa351a398
31 changed files with 18 additions and 135 deletions

View file

@ -142,7 +142,6 @@ void GlobalShortcutsTest::testNonLatinLayout()
KGlobalAccel::self()->stealShortcutSystemwide(seq);
KGlobalAccel::self()->setShortcut(action.get(), {seq}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(seq, action.get());
quint32 timestamp = 0;
Test::keyboardKeyPressed(modifierKey, timestamp++);
@ -164,7 +163,6 @@ void GlobalShortcutsTest::testConsumedShift()
action->setObjectName(QStringLiteral("globalshortcuts-test-consumed-shift"));
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::Key_Percent}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(Qt::Key_Percent, action.get());
// press shift+5
quint32 timestamp = 0;
@ -188,7 +186,6 @@ void GlobalShortcutsTest::testRepeatedTrigger()
action->setObjectName(QStringLiteral("globalshortcuts-test-consumed-shift"));
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::Key_Percent}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(Qt::Key_Percent, action.get());
// we need to configure the key repeat first. It is only enabled on libinput
waylandServer()->seat()->keyboard()->setRepeatInfo(25, 300);
@ -248,7 +245,6 @@ void GlobalShortcutsTest::testMetaShiftW()
action->setObjectName(QStringLiteral("globalshortcuts-test-meta-shift-w"));
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::META | Qt::SHIFT | Qt::Key_W}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(Qt::META | Qt::SHIFT | Qt::Key_W, action.get());
// press meta+shift+w
quint32 timestamp = 0;
@ -273,7 +269,6 @@ void GlobalShortcutsTest::testComponseKey()
action->setObjectName(QStringLiteral("globalshortcuts-accent"));
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::NoModifier}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(Qt::NoModifier, action.get());
// press & release `
quint32 timestamp = 0;

View file

@ -174,7 +174,6 @@ void NoGlobalShortcutsTest::testKGlobalAccel()
action->setObjectName(QStringLiteral("globalshortcuts-test-meta-shift-w"));
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::META | Qt::SHIFT | Qt::Key_W}, KGlobalAccel::NoAutoloading);
input()->registerShortcut(Qt::META | Qt::SHIFT | Qt::Key_W, action.get());
// press meta+shift+w
quint32 timestamp = 0;

View file

@ -19,12 +19,6 @@ namespace KWin
InputRedirection *InputRedirection::s_self = nullptr;
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
{
Q_UNUSED(shortcut)
Q_UNUSED(action)
}
void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action)
{
Q_UNUSED(modifiers)

View file

@ -44,7 +44,6 @@
#include <KConfigGroup>
#include <KCrash>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <QOpenGLContext>
@ -368,23 +367,6 @@ void X11StandalonePlatform::startInteractivePositionSelection(std::function<void
m_windowSelector->start(callback);
}
void X11StandalonePlatform::setupActionForGlobalAccel(QAction *action)
{
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutActiveChanged, kwinApp(), [action](QAction *triggeredAction, bool active) {
Q_UNUSED(active)
if (triggeredAction != action)
return;
QVariant timestamp = action->property("org.kde.kglobalaccel.activationTimestamp");
bool ok = false;
const quint32 t = timestamp.toULongLong(&ok);
if (ok) {
kwinApp()->setX11Time(t);
}
});
}
std::unique_ptr<OverlayWindow> X11StandalonePlatform::createOverlayWindow()
{
return std::make_unique<OverlayWindowX11>();

View file

@ -50,8 +50,6 @@ public:
PlatformCursorImage cursorImage() const override;
void setupActionForGlobalAccel(QAction *action) override;
std::unique_ptr<OverlayWindow> createOverlayWindow() override;
std::unique_ptr<OutlineVisual> createOutline(Outline *outline) override;

View file

@ -209,11 +209,6 @@ void Platform::startInteractivePositionSelection(std::function<void(const QPoint
input()->startInteractivePositionSelection(callback);
}
void Platform::setupActionForGlobalAccel(QAction *action)
{
Q_UNUSED(action)
}
std::unique_ptr<OverlayWindow> Platform::createOverlayWindow()
{
return nullptr;

View file

@ -19,8 +19,6 @@
#include <memory>
#include <optional>
class QAction;
namespace KWin
{
@ -182,22 +180,6 @@ public:
*/
virtual void startInteractivePositionSelection(std::function<void(const QPoint &)> callback);
/**
* Platform specific preparation for an @p action which is used for KGlobalAccel.
*
* A platform might need to do preparation for an @p action before
* it can be used with KGlobalAccel.
*
* Code using KGlobalAccel should invoke this method for the @p action
* prior to setting up any shortcuts and connections.
*
* The default implementation does nothing.
*
* @param action The action which will be used with KGlobalAccel.
* @since 5.10
*/
virtual void setupActionForGlobalAccel(QAction *action);
/**
* Returns a PlatformCursorImage. By default this is created by softwareCursor and
* softwareCursorHotspot. An implementing subclass can use this to provide a better

View file

@ -801,11 +801,6 @@ bool EffectsHandlerImpl::tabletPadRingEvent(int number, int position, bool isFin
return false;
}
void EffectsHandlerImpl::registerGlobalShortcut(const QKeySequence &shortcut, QAction *action)
{
input()->registerShortcut(shortcut, action);
}
void EffectsHandlerImpl::registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action)
{
input()->registerPointerShortcut(modifiers, pointerButtons, action);

View file

@ -101,7 +101,6 @@ public:
void startMouseInterception(Effect *effect, Qt::CursorShape shape) override;
void stopMouseInterception(Effect *effect) override;
bool isMouseInterception() const;
void registerGlobalShortcut(const QKeySequence &shortcut, QAction *action) override;
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action) override;
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action) override;
void registerRealtimeTouchpadSwipeShortcut(SwipeDirection dir, uint fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback) override;

View file

@ -36,7 +36,6 @@ DesktopGridEffect::DesktopGridEffect()
KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, QList<QKeySequence>() << (Qt::META | Qt::Key_F8));
KGlobalAccel::self()->setShortcut(m_toggleAction, QList<QKeySequence>() << (Qt::META | Qt::Key_F8));
m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction);
effects->registerGlobalShortcut(Qt::META | Qt::Key_F8, m_toggleAction);
connect(m_toggleAction, &QAction::triggered, this, [this]() {
if (isRunning()) {
deactivate(animationDuration());

View file

@ -42,7 +42,6 @@ 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, &QAction::triggered, this, &InvertEffect::toggleScreenInversion);
QAction *b = new QAction(this);
@ -50,7 +49,6 @@ 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, &QAction::triggered, this, &InvertEffect::toggleWindow);
connect(effects, &EffectsHandler::windowClosed, this, &InvertEffect::slotWindowClosed);

View file

@ -38,17 +38,14 @@ MagnifierEffect::MagnifierEffect()
a = KStandardAction::zoomIn(this, &MagnifierEffect::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, &MagnifierEffect::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, &MagnifierEffect::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, &EffectsHandler::mouseChanged, this, &MagnifierEffect::slotMouseChanged);
connect(effects, &EffectsHandler::windowDamaged, this, &MagnifierEffect::slotWindowDamaged);

View file

@ -34,7 +34,6 @@ MouseClickEffect::MouseClickEffect()
a->setText(i18n("Toggle Mouse Click 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, &QAction::triggered, this, &MouseClickEffect::toggleEnabled);
reconfigure(ReconfigureAll);

View file

@ -36,14 +36,12 @@ 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, &QAction::triggered, this, &MouseMarkEffect::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, &QAction::triggered, this, &MouseMarkEffect::clearLast);
connect(effects, &EffectsHandler::mouseChanged, this, &MouseMarkEffect::slotMouseChanged);

View file

@ -32,7 +32,6 @@ OverviewEffect::OverviewEffect()
KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, {defaultToggleShortcut});
KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut});
m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction);
effects->registerGlobalShortcut({defaultToggleShortcut}, m_toggleAction);
m_realtimeToggleAction = new QAction(this);
connect(m_realtimeToggleAction, &QAction::triggered, this, [this]() {

View file

@ -38,7 +38,6 @@ ShowPaintEffect::ShowPaintEffect()
toggleAction->setText(i18n("Toggle Show Paint"));
KGlobalAccel::self()->setDefaultShortcut(toggleAction, {});
KGlobalAccel::self()->setShortcut(toggleAction, {});
effects->registerGlobalShortcut({}, toggleAction);
connect(toggleAction, &QAction::triggered, this, &ShowPaintEffect::toggle);
}

View file

@ -29,7 +29,6 @@ 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, &QAction::triggered, this, &ThumbnailAsideEffect::toggleCurrentThumbnail);
connect(effects, &EffectsHandler::windowClosed, this, &ThumbnailAsideEffect::slotWindowClosed);

View file

@ -44,7 +44,6 @@ 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, &QAction::triggered, this, &TrackMouseEffect::toggle);

View file

@ -46,7 +46,6 @@ WindowViewEffect::WindowViewEffect()
KGlobalAccel::self()->setDefaultShortcut(m_exposeAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F9));
KGlobalAccel::self()->setShortcut(m_exposeAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F9));
m_shortcut = KGlobalAccel::self()->shortcut(m_exposeAction);
effects->registerGlobalShortcut(Qt::CTRL | Qt::Key_F9, m_exposeAction);
connect(m_exposeAction, &QAction::triggered, this, [this]() {
toggleMode(ModeCurrentDesktop);
});
@ -56,7 +55,6 @@ WindowViewEffect::WindowViewEffect()
KGlobalAccel::self()->setDefaultShortcut(m_exposeAllAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F10) << Qt::Key_LaunchC);
KGlobalAccel::self()->setShortcut(m_exposeAllAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F10) << Qt::Key_LaunchC);
m_shortcutAll = KGlobalAccel::self()->shortcut(m_exposeAllAction);
effects->registerGlobalShortcut(Qt::CTRL | Qt::Key_F10, m_exposeAllAction);
connect(m_exposeAllAction, &QAction::triggered, this, [this]() {
toggleMode(ModeAllDesktops);
});
@ -66,7 +64,6 @@ WindowViewEffect::WindowViewEffect()
KGlobalAccel::self()->setDefaultShortcut(m_exposeClassAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F7));
KGlobalAccel::self()->setShortcut(m_exposeClassAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F7));
m_shortcutClass = KGlobalAccel::self()->shortcut(m_exposeClassAction);
effects->registerGlobalShortcut(Qt::CTRL | Qt::Key_F7, m_exposeClassAction);
connect(m_exposeClassAction, &QAction::triggered, this, [this]() {
toggleMode(ModeWindowClass);
});
@ -76,7 +73,6 @@ WindowViewEffect::WindowViewEffect()
KGlobalAccel::self()->setDefaultShortcut(m_exposeClassCurrentDesktopAction, QList<QKeySequence>()); // no default shortcut
KGlobalAccel::self()->setShortcut(m_exposeClassCurrentDesktopAction, QList<QKeySequence>());
m_shortcutClassCurrentDesktop = KGlobalAccel::self()->shortcut(m_exposeClassCurrentDesktopAction);
effects->registerGlobalShortcut(QKeySequence{}, m_exposeClassCurrentDesktopAction);
connect(m_exposeClassCurrentDesktopAction, &QAction::triggered, this, [this]() {
toggleMode(ModeWindowClassCurrentDesktop);
});

View file

@ -49,26 +49,22 @@ ZoomEffect::ZoomEffect()
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Plus));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Plus) << (Qt::META | Qt::Key_Equal));
effects->registerGlobalShortcut(Qt::META | Qt::Key_Equal, a);
effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisDown, 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);
effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisUp, 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>());
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), a);
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomLeft);
a = new QAction(this);
@ -76,7 +72,6 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area to Right"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), a);
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomRight);
a = new QAction(this);
@ -84,7 +79,6 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area Upwards"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), a);
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomUp);
a = new QAction(this);
@ -92,7 +86,6 @@ ZoomEffect::ZoomEffect()
a->setText(i18n("Move Zoomed Area Downwards"));
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
effects->registerGlobalShortcut(QKeySequence(), a);
connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomDown);
// TODO: these two actions don't belong into the effect. They need to be moved into KWin core
@ -101,7 +94,6 @@ 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, &QAction::triggered, this, &ZoomEffect::moveMouseToFocus);
a = new QAction(this);
@ -109,7 +101,6 @@ 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, &QAction::triggered, this, &ZoomEffect::moveMouseToCenter);
timeline.setDuration(350);

View file

@ -3146,11 +3146,6 @@ void InputRedirection::setupTouchpadShortcuts()
KGlobalAccel::self()->setShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn});
KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff});
KGlobalAccel::self()->setShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff});
#ifndef KWIN_BUILD_TESTING
registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction);
registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction);
registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction);
#endif
connect(touchpadToggleAction, &QAction::triggered, this, &InputRedirection::toggleTouchpads);
connect(touchpadOnAction, &QAction::triggered, this, &InputRedirection::enableTouchpads);
connect(touchpadOffAction, &QAction::triggered, this, &InputRedirection::disableTouchpads);
@ -3292,12 +3287,6 @@ Qt::KeyboardModifiers InputRedirection::modifiersRelevantForGlobalShortcuts() co
return m_keyboard->modifiersRelevantForGlobalShortcuts();
}
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
{
Q_UNUSED(shortcut)
kwinApp()->platform()->setupActionForGlobalAccel(action);
}
void InputRedirection::registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action)
{
m_shortcuts->registerPointerShortcut(action, modifiers, pointerButtons);

View file

@ -123,17 +123,6 @@ public:
Qt::KeyboardModifiers keyboardModifiers() const;
Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const;
void registerShortcut(const QKeySequence &shortcut, QAction *action);
/**
* @overload
*
* Like registerShortcut, but also connects QAction::triggered to the @p slot on @p receiver.
* It's recommended to use this method as it ensures that the X11 timestamp is updated prior
* to the @p slot being invoked. If not using this overload it's required to ensure that
* registerShortcut is called before connecting to QAction's triggered signal.
*/
template<typename T, typename Slot>
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, Slot slot);
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
void registerTouchpadSwipeShortcut(SwipeDirection direction, uint fingerCount, QAction *action);
@ -542,13 +531,6 @@ inline QList<InputDevice *> InputRedirection::devices() const
return m_inputDevices;
}
template<typename T, typename Slot>
inline void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, Slot slot)
{
registerShortcut(shortcut, action);
connect(action, &QAction::triggered, receiver, slot);
}
} // namespace KWin
Q_DECLARE_METATYPE(KWin::InputRedirection::KeyboardKeyState)

View file

@ -7,11 +7,9 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "keyboard_layout.h"
#include "core/platform.h"
#include "input_event.h"
#include "keyboard_input.h"
#include "keyboard_layout_switching.h"
#include "main.h"
#include <KGlobalAccel>
#include <KLocalizedString>
@ -48,7 +46,6 @@ void KeyboardLayout::init()
KGlobalAccel::self()->setDefaultShortcut(switchKeyboardAction, QList<QKeySequence>({sequence}));
KGlobalAccel::self()->setShortcut(switchKeyboardAction, QList<QKeySequence>({sequence}));
kwinApp()->platform()->setupActionForGlobalAccel(switchKeyboardAction);
connect(switchKeyboardAction, &QAction::triggered, this, &KeyboardLayout::switchToNextLayout);
QDBusConnection::sessionBus().connect(QString(),

View file

@ -890,13 +890,6 @@ 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;
/**
* @brief Registers a global pointer shortcut with the provided @p action.
*

View file

@ -22,10 +22,12 @@
#include <KConfigGroup>
#include <KCrash>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <KSelectionOwner>
#include <KSignalHandler>
#include <QAction>
#include <QComboBox>
#include <QCommandLineParser>
#include <QDialog>
@ -240,6 +242,17 @@ void ApplicationX11::performStartup()
}
}
// Update the timestamp if a global shortcut is pressed or released. Needed
// to ensure that kwin can grab the keyboard.
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutActiveChanged, this, [this](QAction *triggeredAction) {
QVariant timestamp = triggeredAction->property("org.kde.kglobalaccel.activationTimestamp");
bool ok = false;
const quint32 t = timestamp.toULongLong(&ok);
if (ok) {
kwinApp()->setX11Time(t);
}
});
createInput();
createWorkspace();
createColorManager();

View file

@ -97,7 +97,7 @@ NightColorManager::NightColorManager()
toggleAction->setObjectName(QStringLiteral("Toggle Night Color"));
toggleAction->setText(i18n("Toggle Night Color"));
KGlobalAccel::setGlobalShortcut(toggleAction, QList<QKeySequence>());
input()->registerShortcut(QKeySequence(), toggleAction, this, &NightColorManager::toggle);
connect(toggleAction, &QAction::triggered, this, &NightColorManager::toggle);
connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset);

View file

@ -655,7 +655,6 @@ void ScriptedEffect::registerShortcut(const QString &objectName, const QString &
action->setText(text);
const QKeySequence shortcut = QKeySequence(keySequence);
KGlobalAccel::self()->setShortcut(action, QList<QKeySequence>() << shortcut);
input()->registerShortcut(shortcut, action);
connect(action, &QAction::triggered, this, [this, action, callback]() {
QJSValue actionObject = m_engine->newQObject(action);
QQmlEngine::setObjectOwnership(action, QQmlEngine::CppOwnership);

View file

@ -385,7 +385,6 @@ bool KWin::Script::registerShortcut(const QString &objectName, const QString &te
const QKeySequence shortcut = keySequence;
KGlobalAccel::self()->setShortcut(action, {shortcut});
input()->registerShortcut(shortcut, action);
connect(action, &QAction::triggered, this, [this, action, callback]() {
QJSValue(callback).call({m_engine->toScriptValue(action)});
@ -639,7 +638,6 @@ bool KWin::JSEngineGlobalMethodsWrapper::registerShortcut(const QString &name, c
a->setText(text);
const QKeySequence shortcut = QKeySequence(keys);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{shortcut});
KWin::input()->registerShortcut(shortcut, a);
connect(a, &QAction::triggered, this, [=]() mutable {
QJSValueList arguments;

View file

@ -513,7 +513,7 @@ void TabBox::key(const KLazyLocalizedString &actionName, Slot slot, const QKeySe
a->setObjectName(QString::fromUtf8(actionName.untranslatedText()));
a->setText(actionName.toString());
KGlobalAccel::self()->setGlobalShortcut(a, QList<QKeySequence>() << shortcut);
input()->registerShortcut(shortcut, a, this, slot);
connect(a, &QAction::triggered, this, slot);
auto cuts = KGlobalAccel::self()->shortcut(a);
globalShortcutChanged(a, cuts.isEmpty() ? QKeySequence() : cuts.first());
}

View file

@ -972,7 +972,7 @@ void Workspace::initShortcut(const QString &actionName, const QString &descripti
a->setText(description);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << shortcut);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << shortcut);
input()->registerShortcut(shortcut, a, receiver, slot);
connect(a, &QAction::triggered, receiver, slot);
}
/**
@ -1183,7 +1183,6 @@ void Workspace::windowShortcutUpdated(Window *window)
if (!window->shortcut().isEmpty()) {
if (action == nullptr) { // new shortcut
action = new QAction(this);
kwinApp()->platform()->setupActionForGlobalAccel(action);
action->setProperty("componentName", QStringLiteral(KWIN_NAME));
action->setObjectName(key);
action->setText(i18n("Activate Window (%1)", window->caption()));

View file

@ -909,7 +909,7 @@ QAction *VirtualDesktopManager::addAction(const QString &name, const KLocalizedS
a->setText(label.subs(value).toString());
a->setData(value);
KGlobalAccel::setGlobalShortcut(a, key);
input()->registerShortcut(key, a, this, slot);
connect(a, &QAction::triggered, this, slot);
return a;
}
@ -920,7 +920,7 @@ QAction *VirtualDesktopManager::addAction(const QString &name, const QString &la
a->setObjectName(name);
a->setText(label);
KGlobalAccel::setGlobalShortcut(a, QKeySequence());
input()->registerShortcut(QKeySequence(), a, this, slot);
connect(a, &QAction::triggered, this, slot);
return a;
}