diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -41,7 +41,7 @@ public: - explicit KSMainWindow(bool onClickAvailable, QWidget *parent = nullptr); + explicit KSMainWindow(const QVector& supportedModes, bool onClickAvailable, QWidget *parent = nullptr); ~KSMainWindow() Q_DECL_OVERRIDE; private: diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -49,9 +49,9 @@ static const int DEFAULT_WINDOW_WIDTH = 840; static const int MAXIMUM_WINDOW_WIDTH = 1000; -KSMainWindow::KSMainWindow(bool onClickAvailable, QWidget *parent) : +KSMainWindow::KSMainWindow(const QVector& supportedModes, bool onClickAvailable, QWidget *parent) : QDialog(parent), - mKSWidget(new KSWidget(this)), + mKSWidget(new KSWidget(supportedModes, this)), mDivider(new QFrame(this)), mDialogButtonBox(new QDialogButtonBox(this)), mConfigureButton(new QToolButton(this)), @@ -99,9 +99,9 @@ uint32_t value = 1; xcb_change_property(xcbConn, XCB_PROP_MODE_REPLACE, winId(), atom->atom, XCB_ATOM_CARDINAL, 32, 1, &value); } + done: #endif - done: QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } diff --git a/src/Gui/KSWidget.h b/src/Gui/KSWidget.h --- a/src/Gui/KSWidget.h +++ b/src/Gui/KSWidget.h @@ -43,7 +43,7 @@ public: - explicit KSWidget(QWidget *parent = nullptr); + explicit KSWidget(const QVector& supportedModes, QWidget *parent = nullptr); int imagePaddingWidth() const; diff --git a/src/Gui/KSWidget.cpp b/src/Gui/KSWidget.cpp --- a/src/Gui/KSWidget.cpp +++ b/src/Gui/KSWidget.cpp @@ -36,7 +36,7 @@ #include -KSWidget::KSWidget(QWidget *parent) : +KSWidget::KSWidget(const QVector& supportedModes, QWidget *parent) : QWidget(parent) { // get a handle to the configuration manager @@ -54,11 +54,16 @@ mCaptureModeLabel = new QLabel(i18n("Capture Mode"), this); mCaptureArea = new QComboBox(this); - mCaptureArea->insertItem(1, i18n("Full Screen (All Monitors)"), ImageGrabber::FullScreen); - mCaptureArea->insertItem(2, i18n("Current Screen"), ImageGrabber::CurrentScreen); - mCaptureArea->insertItem(3, i18n("Active Window"), ImageGrabber::ActiveWindow); - mCaptureArea->insertItem(4, i18n("Window Under Cursor"), ImageGrabber::WindowUnderCursor); - mCaptureArea->insertItem(5, i18n("Rectangular Region"), ImageGrabber::RectangularRegion); + if (supportedModes.contains(ImageGrabber::FullScreen)) + mCaptureArea->insertItem(1, i18n("Full Screen (All Monitors)"), ImageGrabber::FullScreen); + if (supportedModes.contains(ImageGrabber::CurrentScreen)) + mCaptureArea->insertItem(2, i18n("Current Screen"), ImageGrabber::CurrentScreen); + if (supportedModes.contains(ImageGrabber::ActiveWindow)) + mCaptureArea->insertItem(3, i18n("Active Window"), ImageGrabber::ActiveWindow); + if (supportedModes.contains(ImageGrabber::WindowUnderCursor)) + mCaptureArea->insertItem(4, i18n("Window Under Cursor"), ImageGrabber::WindowUnderCursor); + if (supportedModes.contains(ImageGrabber::RectangularRegion)) + mCaptureArea->insertItem(5, i18n("Rectangular Region"), ImageGrabber::RectangularRegion); mCaptureArea->setMinimumWidth(240); connect(mCaptureArea, static_cast(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); @@ -156,7 +161,8 @@ mCaptureOnClick->setChecked (configManager->onClickChecked()); mCaptureTransientOnly->setChecked (configManager->captureTransientWindowOnlyChecked()); mQuitAfterSaveOrCopy->setChecked (configManager->quitAfterSaveOrCopyChecked()); - mCaptureArea->setCurrentIndex (configManager->captureMode()); + if (configManager->captureMode()>=0) + mCaptureArea->setCurrentIndex (configManager->captureMode()); mDelayMsec->setValue (configManager->captureDelay()); // done diff --git a/src/PlatformBackends/DummyImageGrabber.h b/src/PlatformBackends/DummyImageGrabber.h --- a/src/PlatformBackends/DummyImageGrabber.h +++ b/src/PlatformBackends/DummyImageGrabber.h @@ -34,6 +34,7 @@ explicit DummyImageGrabber(QObject *parent = nullptr); ~DummyImageGrabber() Q_DECL_OVERRIDE; + QVector supportedModes() const override { return {FullScreen, CurrentScreen, ActiveWindow, WindowUnderCursor, TransientWithParent, RectangularRegion}; } bool onClickGrabSupported() const Q_DECL_OVERRIDE; protected: diff --git a/src/PlatformBackends/ImageGrabber.h b/src/PlatformBackends/ImageGrabber.h --- a/src/PlatformBackends/ImageGrabber.h +++ b/src/PlatformBackends/ImageGrabber.h @@ -60,6 +60,7 @@ bool captureDecorations() const; GrabMode grabMode() const; + virtual QVector supportedModes() const = 0; virtual bool onClickGrabSupported() const; void setCapturePointer(const bool newCapturePointer); diff --git a/src/PlatformBackends/KWinWaylandImageGrabber.h b/src/PlatformBackends/KWinWaylandImageGrabber.h --- a/src/PlatformBackends/KWinWaylandImageGrabber.h +++ b/src/PlatformBackends/KWinWaylandImageGrabber.h @@ -30,6 +30,7 @@ explicit KWinWaylandImageGrabber(QObject * parent = nullptr); ~KWinWaylandImageGrabber() Q_DECL_OVERRIDE; + QVector supportedModes() const override { return {FullScreen, CurrentScreen, /*ActiveWindow, */WindowUnderCursor, TransientWithParent/*, RectangularRegion*/}; } bool onClickGrabSupported() const Q_DECL_OVERRIDE; protected: diff --git a/src/PlatformBackends/X11ImageGrabber.h b/src/PlatformBackends/X11ImageGrabber.h --- a/src/PlatformBackends/X11ImageGrabber.h +++ b/src/PlatformBackends/X11ImageGrabber.h @@ -50,6 +50,7 @@ explicit X11ImageGrabber(QObject * parent = nullptr); ~X11ImageGrabber() Q_DECL_OVERRIDE; + QVector supportedModes() const override { return {FullScreen, CurrentScreen, ActiveWindow, WindowUnderCursor, TransientWithParent, RectangularRegion}; } bool onClickGrabSupported() const Q_DECL_OVERRIDE; protected: diff --git a/src/SpectacleConfig.cpp b/src/SpectacleConfig.cpp --- a/src/SpectacleConfig.cpp +++ b/src/SpectacleConfig.cpp @@ -193,7 +193,7 @@ int SpectacleConfig::captureMode() const { - return mGuiConfig.readEntry(QStringLiteral("captureModeIndex"), 0); + return std::max(0, mGuiConfig.readEntry(QStringLiteral("captureModeIndex"), 0)); } void SpectacleConfig::setCaptureMode(int index) diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -304,7 +304,7 @@ void SpectacleCore::initGui() { if (!isGuiInited) { - mMainWindow = new KSMainWindow(mImageGrabber->onClickGrabSupported()); + mMainWindow = new KSMainWindow(mImageGrabber->supportedModes(), mImageGrabber->onClickGrabSupported()); connect(mMainWindow, &KSMainWindow::newScreenshotRequest, this, &SpectacleCore::takeNewScreenshot); connect(mMainWindow, &KSMainWindow::dragAndDropRequest, this, &SpectacleCore::doStartDragAndDrop);