diff --git a/src/Main.cpp b/src/Main.cpp --- a/src/Main.cpp +++ b/src/Main.cpp @@ -68,15 +68,19 @@ {{QStringLiteral("m"), QStringLiteral("current")}, i18n("Capture the current monitor")}, {{QStringLiteral("a"), QStringLiteral("activewindow")}, i18n("Capture the active window")}, {{QStringLiteral("u"), QStringLiteral("windowundercursor")}, i18n("Capture the window currently under the cursor, including parents of pop-up menus")}, - {{QStringLiteral("t"), QStringLiteral("transientonly")}, i18n("Capture the window currently under the cursor, excluding parents of pop-up menus")}, + // A non-working option... commented out until it's fixed or decided upon to be removed + //{{QStringLiteral("t"), QStringLiteral("transientonly")}, i18n("Capture the window currently under the cursor, excluding parents of pop-up menus")}, {{QStringLiteral("r"), QStringLiteral("region")}, i18n("Capture a rectangular region of the screen")}, - {{QStringLiteral("g"), QStringLiteral("gui")}, i18n("Start in GUI mode (default)")}, - {{QStringLiteral("b"), QStringLiteral("background")}, i18n("Take a screenshot and exit without showing the GUI")}, - {{QStringLiteral("s"), QStringLiteral("dbus")}, i18n("Start in DBus-Activation mode")}, - {{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("w"), QStringLiteral("onclick")}, i18n("Wait for a click before taking screenshot. Invalidates delay")} + // Parser option to start in GUI mode removed as redundant, as that's the default mode + {{QStringLiteral("n"), QStringLiteral("nonotify")}, i18n("Take a screenshot and save it with an automatic filename, with no notification or GUI.")}, + {{QStringLiteral("o"), QStringLiteral("output")}, i18n("Take a screenshot and save it to the specified filename."), QStringLiteral("filename")}, + // "delay" input changed to seconds instead of milliseconds (more user-friendly) + {{QStringLiteral("d"), QStringLiteral("delay")}, i18n("Delay before automatically taking the shot (in seconds)"), QStringLiteral("delaySeconds")}, + // Commented-out "wait for mouse click" becuase it's not implemented. + // see line 37 of ImageGrabber.cpp - manually returns false to a check for mouse click supported + //{{QStringLiteral("w"), QStringLiteral("onclick")}, i18n("Wait for a mouse click before taking screenshot.")}, + // DBus option moved to bottom of help output, since it's the most obscure + {{QStringLiteral("s"),QStringLiteral("dbus")}, i18n("Start in DBus-Activation mode")}, }); parser.process(app); @@ -93,8 +97,9 @@ grabMode = ImageGrabber::RectangularRegion; } else if (parser.isSet(QStringLiteral("windowundercursor"))) { grabMode = ImageGrabber::TransientWithParent; - } else if (parser.isSet(QStringLiteral("transientonly"))) { - grabMode = ImageGrabber::WindowUnderCursor; + // comment out another non-working option + //} else if (parser.isSet(QStringLiteral("transientonly"))) { + // grabMode = ImageGrabber::WindowUnderCursor; } // are we running in background or dbus mode? @@ -104,40 +109,34 @@ qint64 delayMsec = 0; QString fileName = QString(); - if (parser.isSet(QStringLiteral("background"))) { - startMode = SpectacleCore::BackgroundMode; - } else if (parser.isSet(QStringLiteral("dbus"))) { - startMode = SpectacleCore::DBusMode; - } - switch (startMode) { - case SpectacleCore::BackgroundMode: - if (parser.isSet(QStringLiteral("nonotify"))) { - notify = false; - } + // BackgroundMode varieties... - if (parser.isSet(QStringLiteral("output"))) { - fileName = parser.value(QStringLiteral("output")); + if (parser.isSet(QStringLiteral("dbus"))) { + startMode = SpectacleCore::DBusMode; + app.setQuitOnLastWindowClosed(false); + } else if (parser.isSet(QStringLiteral("nonotify"))) { + startMode = SpectacleCore::BackgroundMode; + notify = false; + } else if (parser.isSet(QStringLiteral("output"))) { + startMode = SpectacleCore::BackgroundMode; + fileName = parser.value(QStringLiteral("output")); + notify = false; + } else if (parser.isSet(QStringLiteral("delay"))) { + bool ok; + startMode = SpectacleCore::BackgroundMode; + // Human-friendly seconds back to computer-friendly milliseconds + delayMsec = (parser.value(QStringLiteral("delay")).toLongLong(&ok) * 1000); + // ok variable automatically set by string->int conversion (handy!) + if (!ok) { + QTextStream(stdout) << i18n("ERROR: Invalid value for ") << "\n" << endl; + app.exit(); } + }; - if (parser.isSet(QStringLiteral("delay"))) { - bool ok = false; - qint64 delayValue = parser.value(QStringLiteral("delay")).toLongLong(&ok); - if (ok) { - delayMsec = delayValue; - } - } - if (parser.isSet(QStringLiteral("onclick"))) { - delayMsec = -1; - } - case SpectacleCore::DBusMode: - app.setQuitOnLastWindowClosed(false); - case SpectacleCore::GuiMode: - break; - } - // release the kraken + // (re)release the kraken (with a version number update) SpectacleCore core(startMode, grabMode, fileName, delayMsec, notify); QObject::connect(&core, &SpectacleCore::allDone, qApp, &QApplication::quit); diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -35,6 +35,11 @@ #include #include +#include // std::this_thread::sleep_for +#include // std::chrono::seconds + + + #include "Config.h" #include "PlatformBackends/DummyImageGrabber.h" #ifdef XCB_FOUND @@ -183,6 +188,9 @@ switch (mStartMode) { case BackgroundMode: case DBusMode: + + + { if (mNotify) { connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); @@ -254,12 +262,22 @@ notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); notify->setUrls({savedAt}); + // TODO: Have others test with and without this delay-for-delay (maybe it's my machine?) + // Threads seem to need a moment to catch up before firing the notification. + // Notification dependable when execution paused during debugging, but + // inconsistent when running straight through. Very quirky. + // Also cannot change workspaces during delay or the notification fails. Quirky! + if (mStartMode == BackgroundMode && mNotify) { + std::this_thread::sleep_for (std::chrono::seconds(2)); + } + connect(notify, &KNotification::action1Activated, this, [this, savedAt] { new KRun(savedAt, nullptr); QTimer::singleShot(250, this, &SpectacleCore::allDone); }); connect(notify, &QObject::destroyed, this, &SpectacleCore::allDone); + notify->sendEvent(); }