From 07e1df1c50ef796b8c7a67519fd0212d74445c9a Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Tue, 11 Jul 2017 22:59:54 +0200 Subject: [PATCH] Fix non-virtual monitor support --- flameshot.pro | 6 +++-- src/capture/capturewidget.cpp | 21 ++++------------- src/capture/capturewidget.h | 1 - src/capture/screengrabber.cpp | 44 +++++++++++++++++++++++++++++++++++ src/capture/screengrabber.h | 35 ++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 src/capture/screengrabber.cpp create mode 100644 src/capture/screengrabber.h diff --git a/flameshot.pro b/flameshot.pro index 70f15b6a..6b179986 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -52,7 +52,8 @@ SOURCES += src/main.cpp\ src/config/clickablelabel.cpp \ src/config/filenameeditor.cpp \ src/utils/filenamehandler.cpp \ - src/config/strftimechooserwidget.cpp + src/config/strftimechooserwidget.cpp \ + src/capture/screengrabber.cpp HEADERS += \ src/controller.h \ @@ -71,7 +72,8 @@ HEADERS += \ src/config/clickablelabel.h \ src/config/filenameeditor.h \ src/utils/filenamehandler.h \ - src/config/strftimechooserwidget.h + src/config/strftimechooserwidget.h \ + src/capture/screengrabber.h RESOURCES += \ graphics.qrc diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp index 45340b0f..0dd106a0 100644 --- a/src/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -26,10 +26,10 @@ #include "capturewidget.h" #include "button.h" #include "src/capture/colorpicker.h" -#include -#include +#include "src/capture/screengrabber.h" #include #include +#include #include #include #include @@ -39,7 +39,6 @@ #include #include #include -#include // CaptureWidget is the main component used to capture the screen. It contains an // are of selection with its respective buttons. @@ -81,8 +80,9 @@ CaptureWidget::CaptureWidget(bool enableSaveWindow, QWidget *parent) : initShortcuts(); // init content - createCapture(); - QSize size = m_screenshot->getScreenshot().size(); + QPixmap fullScreenshot(ScreenGrabber().grabEntireDesktop()); + m_screenshot = new Screenshot(fullScreenshot, this); + QSize size = fullScreenshot.size(); // we need to increase by 1 the size to reach to the end of the screen setGeometry(0 ,0 , size.width()+1, size.height()+1); @@ -563,17 +563,6 @@ void CaptureWidget::enterButton() { m_onButton = true; } -void CaptureWidget::createCapture() { - QScreen *screen = QGuiApplication::primaryScreen(); - if (const QWindow *window = windowHandle()) - screen = window->screen(); - if (!screen){ - close(); - return; - } - m_screenshot = new Screenshot(screen->grabWindow(0), this); -} - void CaptureWidget::initShortcuts() { new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close())); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(saveScreenshot())); diff --git a/src/capture/capturewidget.h b/src/capture/capturewidget.h index b3686c85..0af362f9 100644 --- a/src/capture/capturewidget.h +++ b/src/capture/capturewidget.h @@ -107,7 +107,6 @@ protected: QVector m_Handles; private: - void createCapture(); void uploadScreenshot(); void initShortcuts(); void updateHandles(); diff --git a/src/capture/screengrabber.cpp b/src/capture/screengrabber.cpp new file mode 100644 index 00000000..236f99d2 --- /dev/null +++ b/src/capture/screengrabber.cpp @@ -0,0 +1,44 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#include "screengrabber.h" +#include +#include +#include +#include +#include + +ScreenGrabber::ScreenGrabber(QObject *parent) : QObject(parent) { + +} + +QPixmap ScreenGrabber::grabEntireDesktop() { + QRect geometry; + for (QScreen *screen : QGuiApplication::screens()) { + geometry = geometry.united(screen->geometry()); + } + + QPixmap p(QApplication::primaryScreen()->grabWindow( + QApplication::desktop()->winId(), + geometry.x(), + geometry.y(), + geometry.width(), + geometry.height()) + ); + p.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio()); + return p; +} diff --git a/src/capture/screengrabber.h b/src/capture/screengrabber.h new file mode 100644 index 00000000..41140001 --- /dev/null +++ b/src/capture/screengrabber.h @@ -0,0 +1,35 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Flameshot. If not, see . + +#ifndef SCREENGRABBER_H +#define SCREENGRABBER_H + +#include + +class ScreenGrabber : public QObject +{ + Q_OBJECT +public: + explicit ScreenGrabber(QObject *parent = nullptr); + QPixmap grabEntireDesktop(); + +signals: + +public slots: +}; + +#endif // SCREENGRABBER_H