diff --git a/shell/desktopview.h b/shell/desktopview.h --- a/shell/desktopview.h +++ b/shell/desktopview.h @@ -101,12 +101,14 @@ void coronaPackageChanged(const KPackage::Package &package); void ensureWindowType(); void setupWaylandIntegration(); + bool handleKRunnerTextInput(QKeyEvent *e); QPointer m_configView; QPointer m_oldScreen; QPointer m_screenToFollow; WindowType m_windowType; KWayland::Client::PlasmaShellSurface *m_shellSurface; + QString m_krunnerText; }; #endif // DESKTOPVIEW_H diff --git a/shell/desktopview.cpp b/shell/desktopview.cpp --- a/shell/desktopview.cpp +++ b/shell/desktopview.cpp @@ -236,11 +236,41 @@ m_shellSurface = nullptr; break; } + } else if (e->type() == QEvent::FocusOut) { + m_krunnerText.clear(); } return PlasmaQuick::ContainmentView::event(e); } +bool DesktopView::handleKRunnerTextInput(QKeyEvent *e) { + // allow only Shift and GroupSwitch modifiers + if (e->modifiers() & ~Qt::ShiftModifier & ~Qt::GroupSwitchModifier) { + return false; + } + bool krunnerTextChanged = false; + for (QChar ch : e->text()) { + if (!ch.isPrint()) { + continue; + } + if (ch.isSpace() && m_krunnerText.isEmpty()) { + continue; + } + m_krunnerText += ch; + krunnerTextChanged = true; + } + if (krunnerTextChanged) { + const QString interface(QStringLiteral("org.kde.krunner")); + if (!KAuthorized::authorize(QStringLiteral("run_command"))) { + return false; + } + org::kde::krunner::App krunner(interface, QStringLiteral("/App"), QDBusConnection::sessionBus()); + krunner.query(m_krunnerText); + return true; + } + return false; +} + void DesktopView::keyPressEvent(QKeyEvent *e) { ContainmentView::keyPressEvent(e); @@ -256,18 +286,9 @@ } // When a key is pressed on desktop when nothing else is active forward the key to krunner - if (!e->modifiers() || e->modifiers() == Qt::ShiftModifier) { - const QString text = e->text().trimmed(); - if (!text.isEmpty() && text[0].isPrint()) { - const QString interface(QStringLiteral("org.kde.krunner")); - if (!KAuthorized::authorize(QStringLiteral("run_command"))) { - return; - } - org::kde::krunner::App krunner(interface, QStringLiteral("/App"), QDBusConnection::sessionBus()); - krunner.query(text); - e->accept(); - return; - } + if (handleKRunnerTextInput(e)) { + e->accept(); + return; } }