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 mClipboard; }; #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), + mClipboard(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 (mClipboard) { + mExportManager->doCopyToClipboard(); + } 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.