diff --git a/krunner/CMakeLists.txt b/krunner/CMakeLists.txt --- a/krunner/CMakeLists.txt +++ b/krunner/CMakeLists.txt @@ -18,7 +18,6 @@ KF5::Declarative KF5::I18n KF5::PlasmaQuick - KF5::GlobalAccel KF5::DBusAddons KF5::Crash KF5::WaylandClient @@ -28,7 +27,7 @@ install(TARGETS krunner ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${krunner_dbusAppXML} DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} ) -install(FILES krunner.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR}) +install(FILES krunner.desktop DESTINATION ${DATA_INSTALL_DIR}/kglobalaccel) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KRunnerAppDBusInterface") ecm_configure_package_config_file(KRunnerAppDBusInterfaceConfig.cmake.in @@ -38,4 +37,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KRunnerAppDBusInterfaceConfig.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR}) -add_subdirectory(update) \ No newline at end of file +add_subdirectory(update) diff --git a/krunner/krunner.desktop b/krunner/krunner.desktop --- a/krunner/krunner.desktop +++ b/krunner/krunner.desktop @@ -49,4 +49,11 @@ X-DBUS-StartupType=Unique X-DBUS-ServiceName=org.kde.krunner X-KDE-StartupNotify=false -X-KDE-autostart-phase=0 +X-KDE-Shortcuts=Alt+Space,Alt+F2,Search +Actions=RunClipboard + +[Desktop Action RunClipboard] +Exec=krunner -c +Name=Run command on clipboard contents +X-KDE-Shortcuts=Alt+Shift+F2 + diff --git a/krunner/main.cpp b/krunner/main.cpp --- a/krunner/main.cpp +++ b/krunner/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -36,11 +37,10 @@ #include "view.h" -static QCommandLineParser parser; - int main(int argc, char **argv) { qunsetenv("QT_DEVICE_PIXEL_RATIO"); + QCommandLineParser parser; QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); KLocalizedString::setApplicationDomain("krunner"); @@ -58,6 +58,13 @@ app.setQuitOnLastWindowClosed(false); parser.setApplicationDescription(i18n("Run Command interface")); + QCommandLineOption clipboardOption({QStringLiteral("c"), QStringLiteral("clipboard")}, + i18n("Use the clipboard contents as query for KRunner")); + QCommandLineOption daemonOption({QStringLiteral("d"), QStringLiteral("daemon")}, + i18n("Start KRunner in the background, don't show it.")); + parser.addOption(clipboardOption); + parser.addOption(daemonOption); + parser.addPositionalArgument(QStringLiteral("query"), i18n("The query to run, only used if -c is not provided")); parser.addHelpOption(); parser.addVersionOption(); parser.process(app); @@ -85,9 +92,30 @@ QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); View view; - view.setVisible(false); - QObject::connect(&service, &KDBusService::activateRequested, &view, &View::display); + auto updateVisibility = [&view, &parser, &clipboardOption]() { + const QString query = parser.positionalArguments().value(0); + + if (parser.isSet(clipboardOption)) { + view.displayWithClipboardContents(); + } else if (!query.isEmpty()) { + view.query(query); + } else { + view.display(); + } + }; + + if (parser.isSet(daemonOption)) { + view.setVisible(false); + } else { + QTimer::singleShot(100, updateVisibility); + } + + QObject::connect(&service, &KDBusService::activateRequested, &view, [&view, &parser, &clipboardOption, updateVisibility](const QStringList &arguments, const QString &workingDirectory) { + Q_UNUSED(workingDirectory) + parser.parse(arguments); + updateVisibility(); + }); return app.exec(); } diff --git a/krunner/view.cpp b/krunner/view.cpp --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -72,22 +71,6 @@ new AppAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/App"), this); - QAction *a = new QAction(0); - QObject::connect(a, &QAction::triggered, this, &View::displayOrHide); - a->setText(i18n("Run Command")); - a->setObjectName(QStringLiteral("run command")); - a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); - KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space), KGlobalAccel::NoAutoloading); - KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space) << QKeySequence(Qt::ALT + Qt::Key_F2) << Qt::Key_Search); - - a = new QAction(0); - QObject::connect(a, &QAction::triggered, this, &View::displayWithClipboardContents); - a->setText(i18n("Run Command on clipboard contents")); - a->setObjectName(QStringLiteral("run command on clipboard contents")); - a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); - KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); - KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); - m_qmlObj = new KDeclarative::QmlObject(this); m_qmlObj->setInitializationDelayed(true); connect(m_qmlObj, &KDeclarative::QmlObject::finished, this, &View::objectIncubated); @@ -137,6 +120,7 @@ } connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &View::slotFocusWindowChanged); + // QTimer::singleShot(100, this, [this]() {display();}); } View::~View()