From daa351a39829013404d005369cb76fabfc1384ea Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 24 Oct 2022 17:37:57 +0300 Subject: [PATCH] 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. --- autotests/integration/globalshortcuts_test.cpp | 5 ----- .../integration/no_global_shortcuts_test.cpp | 1 - autotests/test_virtual_desktops.cpp | 6 ------ .../x11/standalone/x11_standalone_platform.cpp | 18 ------------------ .../x11/standalone/x11_standalone_platform.h | 2 -- src/core/platform.cpp | 5 ----- src/core/platform.h | 18 ------------------ src/effects.cpp | 5 ----- src/effects.h | 1 - src/effects/desktopgrid/desktopgrideffect.cpp | 1 - src/effects/invert/invert.cpp | 2 -- src/effects/magnifier/magnifier.cpp | 3 --- src/effects/mouseclick/mouseclick.cpp | 1 - src/effects/mousemark/mousemark.cpp | 2 -- src/effects/overview/overvieweffect.cpp | 1 - src/effects/showpaint/showpaint.cpp | 1 - src/effects/thumbnailaside/thumbnailaside.cpp | 1 - src/effects/trackmouse/trackmouse.cpp | 1 - src/effects/windowview/windowvieweffect.cpp | 4 ---- src/effects/zoom/zoom.cpp | 9 --------- src/input.cpp | 11 ----------- src/input.h | 18 ------------------ src/keyboard_layout.cpp | 3 --- src/libkwineffects/kwineffects.h | 7 ------- src/main_x11.cpp | 13 +++++++++++++ src/plugins/nightcolor/nightcolormanager.cpp | 2 +- src/scripting/scriptedeffect.cpp | 1 - src/scripting/scripting.cpp | 2 -- src/tabbox/tabbox.cpp | 2 +- src/useractions.cpp | 3 +-- src/virtualdesktops.cpp | 4 ++-- 31 files changed, 18 insertions(+), 135 deletions(-) diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index 139562245c..6c70320b31 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -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{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{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{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{Qt::NoModifier}, KGlobalAccel::NoAutoloading); - input()->registerShortcut(Qt::NoModifier, action.get()); // press & release ` quint32 timestamp = 0; diff --git a/autotests/integration/no_global_shortcuts_test.cpp b/autotests/integration/no_global_shortcuts_test.cpp index 0a48ade781..2d35f8a421 100644 --- a/autotests/integration/no_global_shortcuts_test.cpp +++ b/autotests/integration/no_global_shortcuts_test.cpp @@ -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{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; diff --git a/autotests/test_virtual_desktops.cpp b/autotests/test_virtual_desktops.cpp index d5a22acad2..750ff8eb77 100644 --- a/autotests/test_virtual_desktops.cpp +++ b/autotests/test_virtual_desktops.cpp @@ -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) diff --git a/src/backends/x11/standalone/x11_standalone_platform.cpp b/src/backends/x11/standalone/x11_standalone_platform.cpp index 0a1a2235fa..e534f6d985 100644 --- a/src/backends/x11/standalone/x11_standalone_platform.cpp +++ b/src/backends/x11/standalone/x11_standalone_platform.cpp @@ -44,7 +44,6 @@ #include #include -#include #include #include @@ -368,23 +367,6 @@ void X11StandalonePlatform::startInteractivePositionSelection(std::functionstart(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 X11StandalonePlatform::createOverlayWindow() { return std::make_unique(); diff --git a/src/backends/x11/standalone/x11_standalone_platform.h b/src/backends/x11/standalone/x11_standalone_platform.h index 866e949ec7..b83226a445 100644 --- a/src/backends/x11/standalone/x11_standalone_platform.h +++ b/src/backends/x11/standalone/x11_standalone_platform.h @@ -50,8 +50,6 @@ public: PlatformCursorImage cursorImage() const override; - void setupActionForGlobalAccel(QAction *action) override; - std::unique_ptr createOverlayWindow() override; std::unique_ptr createOutline(Outline *outline) override; diff --git a/src/core/platform.cpp b/src/core/platform.cpp index 45a82a0235..cc1046cefb 100644 --- a/src/core/platform.cpp +++ b/src/core/platform.cpp @@ -209,11 +209,6 @@ void Platform::startInteractivePositionSelection(std::functionstartInteractivePositionSelection(callback); } -void Platform::setupActionForGlobalAccel(QAction *action) -{ - Q_UNUSED(action) -} - std::unique_ptr Platform::createOverlayWindow() { return nullptr; diff --git a/src/core/platform.h b/src/core/platform.h index 8899557440..7700b92af0 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -19,8 +19,6 @@ #include #include -class QAction; - namespace KWin { @@ -182,22 +180,6 @@ public: */ virtual void startInteractivePositionSelection(std::function 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 diff --git a/src/effects.cpp b/src/effects.cpp index 17a350958c..1e316f70ac 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -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); diff --git a/src/effects.h b/src/effects.h index 0fc70e4ab8..b0e726701e 100644 --- a/src/effects.h +++ b/src/effects.h @@ -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 progressCallback) override; diff --git a/src/effects/desktopgrid/desktopgrideffect.cpp b/src/effects/desktopgrid/desktopgrideffect.cpp index a80400d41b..d571b5658a 100644 --- a/src/effects/desktopgrid/desktopgrideffect.cpp +++ b/src/effects/desktopgrid/desktopgrideffect.cpp @@ -36,7 +36,6 @@ DesktopGridEffect::DesktopGridEffect() KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, QList() << (Qt::META | Qt::Key_F8)); KGlobalAccel::self()->setShortcut(m_toggleAction, QList() << (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()); diff --git a/src/effects/invert/invert.cpp b/src/effects/invert/invert.cpp index ac71faa713..3b1b310029 100644 --- a/src/effects/invert/invert.cpp +++ b/src/effects/invert/invert.cpp @@ -42,7 +42,6 @@ InvertEffect::InvertEffect() a->setText(i18n("Toggle Invert Effect")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::CTRL | Qt::META | Qt::Key_I)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::CTRL | Qt::META | Qt::Key_U)); KGlobalAccel::self()->setShortcut(b, QList() << (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); diff --git a/src/effects/magnifier/magnifier.cpp b/src/effects/magnifier/magnifier.cpp index e0e3011f43..02ada153a2 100644 --- a/src/effects/magnifier/magnifier.cpp +++ b/src/effects/magnifier/magnifier.cpp @@ -38,17 +38,14 @@ MagnifierEffect::MagnifierEffect() a = KStandardAction::zoomIn(this, &MagnifierEffect::zoomIn, this); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::META | Qt::Key_Equal)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::META | Qt::Key_Minus)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::META | Qt::Key_0)); KGlobalAccel::self()->setShortcut(a, QList() << (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); diff --git a/src/effects/mouseclick/mouseclick.cpp b/src/effects/mouseclick/mouseclick.cpp index 0b0002211f..f86fb01b11 100644 --- a/src/effects/mouseclick/mouseclick.cpp +++ b/src/effects/mouseclick/mouseclick.cpp @@ -34,7 +34,6 @@ MouseClickEffect::MouseClickEffect() a->setText(i18n("Toggle Mouse Click Effect")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::META | Qt::Key_Asterisk)); KGlobalAccel::self()->setShortcut(a, QList() << (Qt::META | Qt::Key_Asterisk)); - effects->registerGlobalShortcut(Qt::META | Qt::Key_Asterisk, a); connect(a, &QAction::triggered, this, &MouseClickEffect::toggleEnabled); reconfigure(ReconfigureAll); diff --git a/src/effects/mousemark/mousemark.cpp b/src/effects/mousemark/mousemark.cpp index d2c1b8f655..18891a2947 100644 --- a/src/effects/mousemark/mousemark.cpp +++ b/src/effects/mousemark/mousemark.cpp @@ -36,14 +36,12 @@ MouseMarkEffect::MouseMarkEffect() a->setText(i18n("Clear All Mouse Marks")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::SHIFT | Qt::META | Qt::Key_F11)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::SHIFT | Qt::META | Qt::Key_F12)); KGlobalAccel::self()->setShortcut(a, QList() << (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); diff --git a/src/effects/overview/overvieweffect.cpp b/src/effects/overview/overvieweffect.cpp index 3e10fb79c1..209d7e9f93 100644 --- a/src/effects/overview/overvieweffect.cpp +++ b/src/effects/overview/overvieweffect.cpp @@ -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]() { diff --git a/src/effects/showpaint/showpaint.cpp b/src/effects/showpaint/showpaint.cpp index ec3a122167..a9c23d29e0 100644 --- a/src/effects/showpaint/showpaint.cpp +++ b/src/effects/showpaint/showpaint.cpp @@ -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); } diff --git a/src/effects/thumbnailaside/thumbnailaside.cpp b/src/effects/thumbnailaside/thumbnailaside.cpp index 1f554951db..c430dcf718 100644 --- a/src/effects/thumbnailaside/thumbnailaside.cpp +++ b/src/effects/thumbnailaside/thumbnailaside.cpp @@ -29,7 +29,6 @@ ThumbnailAsideEffect::ThumbnailAsideEffect() a->setText(i18n("Toggle Thumbnail for Current Window")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::META | Qt::CTRL | Qt::Key_T)); KGlobalAccel::self()->setShortcut(a, QList() << (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); diff --git a/src/effects/trackmouse/trackmouse.cpp b/src/effects/trackmouse/trackmouse.cpp index 9045785cb8..0bdd7fe73c 100644 --- a/src/effects/trackmouse/trackmouse.cpp +++ b/src/effects/trackmouse/trackmouse.cpp @@ -44,7 +44,6 @@ TrackMouseEffect::TrackMouseEffect() m_action->setText(i18n("Track mouse")); KGlobalAccel::self()->setDefaultShortcut(m_action, QList()); KGlobalAccel::self()->setShortcut(m_action, QList()); - effects->registerGlobalShortcut(QKeySequence(), m_action); connect(m_action, &QAction::triggered, this, &TrackMouseEffect::toggle); diff --git a/src/effects/windowview/windowvieweffect.cpp b/src/effects/windowview/windowvieweffect.cpp index 483d655469..020abce468 100644 --- a/src/effects/windowview/windowvieweffect.cpp +++ b/src/effects/windowview/windowvieweffect.cpp @@ -46,7 +46,6 @@ WindowViewEffect::WindowViewEffect() KGlobalAccel::self()->setDefaultShortcut(m_exposeAction, QList() << (Qt::CTRL | Qt::Key_F9)); KGlobalAccel::self()->setShortcut(m_exposeAction, QList() << (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() << (Qt::CTRL | Qt::Key_F10) << Qt::Key_LaunchC); KGlobalAccel::self()->setShortcut(m_exposeAllAction, QList() << (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() << (Qt::CTRL | Qt::Key_F7)); KGlobalAccel::self()->setShortcut(m_exposeClassAction, QList() << (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()); // no default shortcut KGlobalAccel::self()->setShortcut(m_exposeClassCurrentDesktopAction, QList()); m_shortcutClassCurrentDesktop = KGlobalAccel::self()->shortcut(m_exposeClassCurrentDesktopAction); - effects->registerGlobalShortcut(QKeySequence{}, m_exposeClassCurrentDesktopAction); connect(m_exposeClassCurrentDesktopAction, &QAction::triggered, this, [this]() { toggleMode(ModeWindowClassCurrentDesktop); }); diff --git a/src/effects/zoom/zoom.cpp b/src/effects/zoom/zoom.cpp index b266245f17..285a0e582d 100644 --- a/src/effects/zoom/zoom.cpp +++ b/src/effects/zoom/zoom.cpp @@ -49,26 +49,22 @@ ZoomEffect::ZoomEffect() a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this); KGlobalAccel::self()->setDefaultShortcut(a, QList() << (Qt::META | Qt::Key_Plus)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::META | Qt::Key_Minus)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::META | Qt::Key_0)); KGlobalAccel::self()->setShortcut(a, QList() << (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()); KGlobalAccel::self()->setShortcut(a, QList()); - 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()); KGlobalAccel::self()->setShortcut(a, QList()); - 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()); KGlobalAccel::self()->setShortcut(a, QList()); - 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()); KGlobalAccel::self()->setShortcut(a, QList()); - 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() << (Qt::META | Qt::Key_F5)); KGlobalAccel::self()->setShortcut(a, QList() << (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() << (Qt::META | Qt::Key_F6)); KGlobalAccel::self()->setShortcut(a, QList() << (Qt::META | Qt::Key_F6)); - effects->registerGlobalShortcut(Qt::META | Qt::Key_F6, a); connect(a, &QAction::triggered, this, &ZoomEffect::moveMouseToCenter); timeline.setDuration(350); diff --git a/src/input.cpp b/src/input.cpp index 0e364b3c16..973e276209 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -3146,11 +3146,6 @@ void InputRedirection::setupTouchpadShortcuts() KGlobalAccel::self()->setShortcut(touchpadOnAction, QList{Qt::Key_TouchpadOn}); KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList{Qt::Key_TouchpadOff}); KGlobalAccel::self()->setShortcut(touchpadOffAction, QList{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); diff --git a/src/input.h b/src/input.h index 1a9a86f321..735eecb681 100644 --- a/src/input.h +++ b/src/input.h @@ -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 - 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 InputRedirection::devices() const return m_inputDevices; } -template -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) diff --git a/src/keyboard_layout.cpp b/src/keyboard_layout.cpp index 02057da353..1a0e193c01 100644 --- a/src/keyboard_layout.cpp +++ b/src/keyboard_layout.cpp @@ -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 #include @@ -48,7 +46,6 @@ void KeyboardLayout::init() KGlobalAccel::self()->setDefaultShortcut(switchKeyboardAction, QList({sequence})); KGlobalAccel::self()->setShortcut(switchKeyboardAction, QList({sequence})); - kwinApp()->platform()->setupActionForGlobalAccel(switchKeyboardAction); connect(switchKeyboardAction, &QAction::triggered, this, &KeyboardLayout::switchToNextLayout); QDBusConnection::sessionBus().connect(QString(), diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index 7bacf30d56..e92b97d1be 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -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. * diff --git a/src/main_x11.cpp b/src/main_x11.cpp index ddbd2d60e4..5cb226c74f 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -22,10 +22,12 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -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(); diff --git a/src/plugins/nightcolor/nightcolormanager.cpp b/src/plugins/nightcolor/nightcolormanager.cpp index ffa8ee8291..f189c47f7c 100644 --- a/src/plugins/nightcolor/nightcolormanager.cpp +++ b/src/plugins/nightcolor/nightcolormanager.cpp @@ -97,7 +97,7 @@ NightColorManager::NightColorManager() toggleAction->setObjectName(QStringLiteral("Toggle Night Color")); toggleAction->setText(i18n("Toggle Night Color")); KGlobalAccel::setGlobalShortcut(toggleAction, QList()); - input()->registerShortcut(QKeySequence(), toggleAction, this, &NightColorManager::toggle); + connect(toggleAction, &QAction::triggered, this, &NightColorManager::toggle); connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset); diff --git a/src/scripting/scriptedeffect.cpp b/src/scripting/scriptedeffect.cpp index c64d86ff63..ec55b90393 100644 --- a/src/scripting/scriptedeffect.cpp +++ b/src/scripting/scriptedeffect.cpp @@ -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() << shortcut); - input()->registerShortcut(shortcut, action); connect(action, &QAction::triggered, this, [this, action, callback]() { QJSValue actionObject = m_engine->newQObject(action); QQmlEngine::setObjectOwnership(action, QQmlEngine::CppOwnership); diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 10140449c5..79870d8381 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -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{shortcut}); - KWin::input()->registerShortcut(shortcut, a); connect(a, &QAction::triggered, this, [=]() mutable { QJSValueList arguments; diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index 76dd38eeda..48b179e568 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -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() << 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()); } diff --git a/src/useractions.cpp b/src/useractions.cpp index 29fe95da11..f4c910bf74 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -972,7 +972,7 @@ void Workspace::initShortcut(const QString &actionName, const QString &descripti a->setText(description); KGlobalAccel::self()->setDefaultShortcut(a, QList() << shortcut); KGlobalAccel::self()->setShortcut(a, QList() << 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())); diff --git a/src/virtualdesktops.cpp b/src/virtualdesktops.cpp index 919fd310be..251cabfa73 100644 --- a/src/virtualdesktops.cpp +++ b/src/virtualdesktops.cpp @@ -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; }