Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ GeneralConf::GeneralConf(QWidget* parent)
initAntialiasingPinZoom();
initUndoLimit();
initInsecurePixelate();
#if !defined(Q_OS_MACOS)
initCaptureActiveMonitor();
#endif
#if defined(Q_OS_LINUX)
initUseX11LegacyScreenshot();
#endif
Expand Down Expand Up @@ -127,6 +130,9 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
m_showTray->setChecked(!config.disabledTrayIcon());
#endif
#if !defined(Q_OS_MACOS)
m_captureActiveMonitor->setChecked(config.captureActiveMonitor());
#endif
#if defined(Q_OS_LINUX)
m_useX11LegacyScreenshot->setChecked(config.useX11LegacyScreenshot());
#endif
Expand Down Expand Up @@ -916,6 +922,29 @@ void GeneralConf::setInsecurePixelate(bool checked)
ConfigHandler().setInsecurePixelate(checked);
}

#if !defined(Q_OS_MACOS)
void GeneralConf::initCaptureActiveMonitor()
{
m_captureActiveMonitor = new QCheckBox(
tr("Capture active monitor (skip monitor selection)"), this);
m_captureActiveMonitor->setToolTip(
tr("Automatically capture the monitor where the cursor is located "
"instead of showing the monitor selection dialog. "
"This feature is not supported on Wayland."));
m_scrollAreaLayout->addWidget(m_captureActiveMonitor);

connect(m_captureActiveMonitor,
&QCheckBox::clicked,
this,
&GeneralConf::captureActiveMonitorChanged);
}

void GeneralConf::captureActiveMonitorChanged(bool checked)
{
ConfigHandler().setCaptureActiveMonitor(checked);
}
#endif

#if defined(Q_OS_LINUX)
void GeneralConf::initUseX11LegacyScreenshot()
{
Expand Down
9 changes: 9 additions & 0 deletions src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ private slots:
void setJpegQuality(int v);
void setReverseArrow(bool checked);
void setInsecurePixelate(bool checked);
#if !defined(Q_OS_MACOS)
void captureActiveMonitorChanged(bool checked);
#endif
#if defined(Q_OS_LINUX)
void useX11LegacyScreenshotChanged(bool checked);
#endif
Expand Down Expand Up @@ -102,6 +105,9 @@ private slots:
void initJpegQuality();
void initReverseArrow();
void initInsecurePixelate();
#if !defined(Q_OS_MACOS)
void initCaptureActiveMonitor();
#endif
#if defined(Q_OS_LINUX)
void initUseX11LegacyScreenshot();
#endif
Expand Down Expand Up @@ -153,6 +159,9 @@ private slots:
QSpinBox* m_jpegQuality;
QCheckBox* m_reverseArrow;
QCheckBox* m_insecurePixelate;
#if !defined(Q_OS_MACOS)
QCheckBox* m_captureActiveMonitor;
#endif
#if defined(Q_OS_LINUX)
QCheckBox* m_useX11LegacyScreenshot;
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
// Not visible on settings dialog
OPTION("ignorePrntScrForcesSnipping" ,Bool ( false )),
#endif
#if !defined(Q_OS_MACOS)
// Auto-select the monitor under the cursor instead of showing
// the monitor selection UI. Not supported on Wayland.
OPTION("captureActiveMonitor" ,Bool ( false )),
#endif
#if defined(Q_OS_LINUX)
// Bypass freedesktop portal and use Qt's native X11
// screenshot method. Intended for WMs without xdg-desktop-portal.
Expand Down
3 changes: 3 additions & 0 deletions src/utils/confighandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class ConfigHandler : public QObject
setIgnorePrntScrForcesSnipping,
bool)
#endif
#if !defined(Q_OS_MACOS)
CONFIG_GETTER_SETTER(captureActiveMonitor, setCaptureActiveMonitor, bool)
#endif
#if defined(Q_OS_LINUX)
CONFIG_GETTER_SETTER(useX11LegacyScreenshot,
setUseX11LegacyScreenshot,
Expand Down
20 changes: 20 additions & 0 deletions src/utils/screengrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ QPixmap ScreenGrabber::selectMonitorAndCrop(const QPixmap& fullScreenshot,
return cropToMonitor(fullScreenshot, 0);
}

// Capture Active Monitor: auto-select monitor under cursor
if (ConfigHandler().captureActiveMonitor()) {
if (m_info.waylandDetected()) {
AbstractLogger::error()
<< tr("Capture Active Monitor is not supported on Wayland due to "
"Wayland security model.");
ok = false;
return QPixmap();
}

QGuiAppCurrentScreen screenFinder;
QScreen* cursorScreen = screenFinder.currentScreen();
int monitorIndex = screens.indexOf(cursorScreen);
if (monitorIndex >= 0) {
m_selectedMonitor = monitorIndex;
return cropToMonitor(fullScreenshot, monitorIndex);
}
// Fall through to manual selection if screen lookup fails
}

if (m_monitorSelectionActive) {
AbstractLogger::error()
<< tr("Screenshot already in progress, please wait for the current "
Expand Down
Loading