Skip to content

Commit

Permalink
Capture single screen when chosen.
Browse files Browse the repository at this point in the history
  • Loading branch information
karliss committed Oct 9, 2021
1 parent e255f94 commit 3a156dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/utils/screengrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
#endif
}

QPixmap ScreenGrabber::grabScreen(bool& ok)
{
auto current = QGuiAppCurrentScreen().currentScreen();
int number = 0;
for (QScreen* const screen : QGuiApplication::screens()) {
if (screen == current) {
return grabScreen(number, ok);
}
number++;
}
return grabScreen(-1, ok);
}

QPixmap ScreenGrabber::grabScreen(int screenNumber, bool& ok)
{
QPixmap p;
Expand Down
1 change: 1 addition & 0 deletions src/utils/screengrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ScreenGrabber : public QObject
explicit ScreenGrabber(QObject* parent = nullptr);
QPixmap grabEntireDesktop(bool& ok);
QPixmap grabScreen(int screenNumber, bool& ok);
QPixmap grabScreen(bool& ok);

private:
DesktopInfo m_info;
Expand Down
12 changes: 6 additions & 6 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors

// Based on Lightscreen areadialog.cpp, Copyright 2017 Christian Kaiser
Expand Down Expand Up @@ -127,7 +127,11 @@ CaptureWidget::CaptureWidget(uint id,
if (windowMode != CaptureWindowMode::DebugNonFullScreen) {
// Grab Screenshot
bool ok = true;
m_context.screenshot = ScreenGrabber().grabEntireDesktop(ok);
if (m_captureCurrentScreen) {
m_context.screenshot = ScreenGrabber().grabScreen(ok);
} else {
m_context.screenshot = ScreenGrabber().grabEntireDesktop(ok);
}
if (!ok) {
SystemNotification().sendMessage(tr("Unable to capture screen"));
this->close();
Expand Down Expand Up @@ -692,10 +696,6 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
m_buttonHandler->show();
}
}
} else if (m_middleClickDrag) {
m_viewOffset = (m_initialOffset + -(e->pos() - m_viewDragStartPoint));
updateViewTransform();
repaint();
}
updateCursor();
}
Expand Down

0 comments on commit 3a156dd

Please sign in to comment.