Index: src/ExportManager.h =================================================================== --- src/ExportManager.h +++ src/ExportManager.h @@ -81,7 +81,7 @@ void doSave(const QUrl &url = QUrl(), bool notify = false); bool doSaveAs(QWidget *parentWindow = nullptr, bool notify = false); - void doCopyToClipboard(); + void doCopyToClipboard(bool notify); void doPrint(QPrinter *printer); private: Index: src/ExportManager.cpp =================================================================== --- src/ExportManager.cpp +++ src/ExportManager.cpp @@ -487,9 +487,13 @@ // misc helpers -void ExportManager::doCopyToClipboard() +void ExportManager::doCopyToClipboard(bool notify) { QApplication::clipboard()->setPixmap(mSavePixmap, QClipboard::Clipboard); + + if (notify) { + emit forceNotify(QUrl()); + } } void ExportManager::doPrint(QPrinter *printer) Index: src/Gui/KSMainWindow.cpp =================================================================== --- src/Gui/KSMainWindow.cpp +++ src/Gui/KSMainWindow.cpp @@ -389,7 +389,8 @@ void KSMainWindow::sendToClipboard() { - ExportManager::instance()->doCopyToClipboard(); + bool notify = false; + ExportManager::instance()->doCopyToClipboard(notify); SpectacleConfig::instance()->quitAfterSaveOrCopyChecked() ? quit() Index: src/Main.cpp =================================================================== --- src/Main.cpp +++ src/Main.cpp @@ -68,6 +68,7 @@ {{QStringLiteral("n"), QStringLiteral("nonotify")}, i18n("In background mode, do not pop up a notification when the screenshot is taken")}, {{QStringLiteral("o"), QStringLiteral("output")}, i18n("In background mode, save image to specified file"), QStringLiteral("fileName")}, {{QStringLiteral("d"), QStringLiteral("delay")}, i18n("In background mode, delay before taking the shot (in milliseconds)"), QStringLiteral("delayMsec")}, + {{QStringLiteral("c"), QStringLiteral("clipboard")}, i18n("In background mode, copy screenshot to clipboard")}, {{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a click before taking screenshot. Invalidates delay")} }); @@ -93,6 +94,7 @@ SpectacleCore::StartMode startMode = SpectacleCore::GuiMode; bool notify = true; + bool copyToClipboard = false; qint64 delayMsec = 0; QString fileName = QString(); @@ -124,6 +126,10 @@ delayMsec = -1; } + if (parser.isSet(QStringLiteral("clipboard"))) { + copyToClipboard = true; + } + app.setQuitOnLastWindowClosed(false); break; @@ -137,7 +143,7 @@ // release the kraken - SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify); + SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify, copyToClipboard); QObject::connect(&core, &SpectacleCore::allDone, qApp, &QApplication::quit); // create the dbus connections Index: src/SpectacleCore.h =================================================================== --- src/SpectacleCore.h +++ src/SpectacleCore.h @@ -42,7 +42,7 @@ }; explicit SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, - qint64 delayMsec, bool notifyOnGrab, QObject *parent = nullptr); + qint64 delayMsec, bool notifyOnGrab, bool copyToClipboard, QObject *parent = nullptr); ~SpectacleCore(); QString filename() const; @@ -81,6 +81,7 @@ ImageGrabber *mImageGrabber; KSMainWindow *mMainWindow; bool isGuiInited; + bool copyToClipboard; }; #endif // KSCORE_H Index: src/SpectacleCore.cpp =================================================================== --- src/SpectacleCore.cpp +++ src/SpectacleCore.cpp @@ -42,14 +42,15 @@ #include SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, - qint64 delayMsec, bool notifyOnGrab, QObject *parent) : + qint64 delayMsec, bool notifyOnGrab, bool copyToClipboard, QObject *parent) : QObject(parent), mExportManager(ExportManager::instance()), mStartMode(startMode), mNotify(notifyOnGrab), mImageGrabber(nullptr), mMainWindow(nullptr), - isGuiInited(false) + isGuiInited(false), + copyToClipboard(copyToClipboard) { KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); KConfigGroup guiConfig(config, "GuiConfig"); @@ -217,9 +218,13 @@ connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); } - QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? + if (copyToClipboard) { + mExportManager->doCopyToClipboard(mNotify); + } else { + QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? mFileNameUrl : QUrl(); - mExportManager->doSave(savePath); + mExportManager->doSave(savePath); + } // if we notify, we emit allDone only if the user either dismissed the notification or pressed // the "Open" button, otherwise the app closes before it can react to it. @@ -278,15 +283,19 @@ const QString &path = savedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); - // a speaking message is prettier than a URL, special case for the default pictures location - if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { + // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location + if (copyToClipboard) { + notify->setText(i18n("A screenshot was saved to your clipboard.")); + } else if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); } else { notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); } - notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); - notify->setUrls({savedAt}); + if (!copyToClipboard) { + notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); + notify->setUrls({savedAt}); + } connect(notify, &KNotification::action1Activated, this, [this, savedAt] { new KRun(savedAt, nullptr);