Skip to content

Commit b70429a

Browse files
serebryakov02serebryakov02
andauthored
Fix screen capture ignoring GUI last-region setting (#4789)
* Fix screen capture ignoring GUI last-region setting * Fix clang-format for empty constructor * Restore saved region for GUI captures --------- Co-authored-by: serebryakov02 <nik04ta01@gmail.com>
1 parent 25b977a commit b70429a

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/core/capturerequest.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
33

44
#include "capturerequest.h"
5-
#include "config/cacheutils.h"
6-
#include "utils/confighandler.h"
75

8-
#include <QApplication>
9-
#include <QClipboard>
10-
#include <QDateTime>
116
#include <stdexcept>
127
#include <utility>
138

@@ -21,14 +16,7 @@ CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode,
2116
, m_data(std::move(data))
2217
, m_selectedMonitor(-1)
2318
, m_hasSelectedMonitor(false)
24-
{
25-
26-
ConfigHandler config;
27-
if (m_mode == CaptureRequest::CaptureMode::GRAPHICAL_MODE &&
28-
config.saveLastRegion()) {
29-
setInitialSelection(getLastRegion());
30-
}
31-
}
19+
{}
3220

3321
CaptureRequest::CaptureMode CaptureRequest::captureMode() const
3422
{

src/core/flameshot.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ constexpr const char* visibleInDockProperty = "_visibleInDock";
4242
#include <CoreGraphics/CoreGraphics.h>
4343
#endif
4444

45+
#include "config/cacheutils.h"
4546
#include "config/configresolver.h"
4647
#include "config/configwindow.h"
4748
#include "core/qguiappcurrentscreen.h"
@@ -125,6 +126,13 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
125126
return nullptr;
126127
}
127128

129+
CaptureRequest request = req;
130+
if (request.captureMode() == CaptureRequest::GRAPHICAL_MODE &&
131+
request.initialSelection().isNull() &&
132+
ConfigHandler().saveLastRegion()) {
133+
request.setInitialSelection(getLastRegion());
134+
}
135+
128136
#if defined(Q_OS_MACOS)
129137
// This is required on MacOS because of Mission Control. If you'll switch to
130138
// another Desktop you cannot take a new screenshot from the tray, you have
@@ -157,7 +165,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
157165
return nullptr;
158166
}
159167

160-
m_captureWindow = new CaptureWidget(req);
168+
m_captureWindow = new CaptureWidget(request);
161169

162170
#ifdef Q_OS_WIN
163171
m_captureWindow->show();

src/utils/screengrabber.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok, int preSelectedMonitor)
255255
ok = false;
256256
return QPixmap();
257257
}
258+
m_selectedMonitor = QGuiApplication::screens().indexOf(currentScreen);
259+
if (m_selectedMonitor < 0) {
260+
AbstractLogger::error() << tr("Unable to get current screen");
261+
ok = false;
262+
return QPixmap();
263+
}
258264
const QRect geom = currentScreen->geometry();
259265
screenshot = currentScreen->grabWindow(
260266
wid, geom.x(), geom.y(), geom.width(), geom.height());

0 commit comments

Comments
 (0)