From fa2241e24a894c35a663bbea305c4936701e6bd8 Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Fri, 4 Mar 2022 22:08:44 +0800 Subject: [PATCH] shell: Follow `ActivateWhenTypingOnDesktop` from KRunner When the option is unchecked, typing on the desktop will not activate KRunner. FEATURE: 318538 FIXED-IN: 5.25 --- shell/CMakeLists.txt | 1 + shell/desktopview.cpp | 16 ++++++++++++++++ shell/desktopview.h | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 137305793..6cf7fc464 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -80,6 +80,7 @@ target_link_libraries(plasmashell Qt::DBus KF5::KIOCore KF5::WindowSystem + KF5::ConfigCore # Activate KRunner on the desktop KF5::Crash KF5::Plasma KF5::PlasmaQuick diff --git a/shell/desktopview.cpp b/shell/desktopview.cpp index a7a34b062..051d4f5a8 100644 --- a/shell/desktopview.cpp +++ b/shell/desktopview.cpp @@ -62,6 +62,18 @@ DesktopView::DesktopView(Plasma::Corona *corona, QScreen *targetScreen) QObject::connect(m_activityController, &KActivities::Controller::activityAdded, this, &DesktopView::candidateContainmentsChanged); QObject::connect(m_activityController, &KActivities::Controller::activityRemoved, this, &DesktopView::candidateContainmentsChanged); + + // KRunner settings + KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); + KConfigGroup configGroup(config, "General"); + m_activateKRunnerWhenTypingOnDesktop = configGroup.readEntry("ActivateWhenTypingOnDesktop", true); + + m_configWatcher = KConfigWatcher::create(config); + connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) { + if (names.contains(QByteArray("ActivateWhenTypingOnDesktop"))) { + m_activateKRunnerWhenTypingOnDesktop = group.readEntry("ActivateWhenTypingOnDesktop", true); + } + }); } DesktopView::~DesktopView() @@ -267,6 +279,10 @@ void DesktopView::keyPressEvent(QKeyEvent *e) return; } + if (!m_activateKRunnerWhenTypingOnDesktop) { + return; + } + // When a key is pressed on desktop when nothing else is active forward the key to krunner if (handleKRunnerTextInput(e)) { e->accept(); diff --git a/shell/desktopview.h b/shell/desktopview.h index bbe2a75a2..d36feff7e 100644 --- a/shell/desktopview.h +++ b/shell/desktopview.h @@ -10,6 +10,8 @@ #include #include +#include + namespace KWayland { namespace Client @@ -96,4 +98,8 @@ private: WindowType m_windowType; KWayland::Client::PlasmaShellSurface *m_shellSurface; QString m_krunnerText; + + // KRunner config + KConfigWatcher::Ptr m_configWatcher; + bool m_activateKRunnerWhenTypingOnDesktop; };