From 3a156dd960408f2f8138bf7292ddfde910c54ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Se=C5=86ko?= Date: Sun, 10 Oct 2021 00:08:27 +0300 Subject: [PATCH] Capture single screen when chosen. --- src/utils/screengrabber.cpp | 13 +++++++++++++ src/utils/screengrabber.h | 1 + src/widgets/capture/capturewidget.cpp | 12 ++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index 7c6c07aba7..ed541ee99f 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -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; diff --git a/src/utils/screengrabber.h b/src/utils/screengrabber.h index 6bcb8aa5a2..4f45b0c937 100644 --- a/src/utils/screengrabber.h +++ b/src/utils/screengrabber.h @@ -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; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 54b5f354b0..0b47526545 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -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 @@ -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(); @@ -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(); }