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
28 changes: 12 additions & 16 deletions src/utils/screengrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void ScreenGrabber::freeDesktopPortal(bool& ok, QPixmap& res)
}
#endif
}

QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
{
ok = true;
Expand Down Expand Up @@ -210,24 +211,16 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
// multi-monitor setups where screens have different positions/heights.
// This fixes the dual monitor offset bug and handles edge cases where
// the desktop bounding box includes virtual space.
QScreen* primaryScreen = QGuiApplication::primaryScreen();
QRect r = primaryScreen->geometry();
QPixmap desktop(geometry.size());
desktop.fill(Qt::black); // Fill with black background

QPainter painter(&desktop);
for (QScreen* screen : QGuiApplication::screens()) {
QRect screenGeom = screen->geometry();
QPixmap screenCapture = screen->grabWindow(
wid, 0, 0, screenGeom.width(), screenGeom.height());

// Calculate position relative to desktop top-left
QPoint relativePos = screenGeom.topLeft() - geometry.topLeft();
painter.drawPixmap(relativePos, screenCapture);
}
painter.end();

// Set device pixel ratio based on the primary screen
desktop.setDevicePixelRatio(
QApplication::primaryScreen()->devicePixelRatio());
desktop =
primaryScreen->grabWindow(wid,
-r.x() / primaryScreen->devicePixelRatio(),
-r.y() / primaryScreen->devicePixelRatio(),
geometry.width(),
geometry.height());
return desktop;
#endif
}
Expand Down Expand Up @@ -281,6 +274,9 @@ QRect ScreenGrabber::desktopGeometry()
// Qt6 fix: Don't divide by devicePixelRatio for multi-monitor setups
// This was causing coordinate offset issues in dual monitor
// configurations
// But it still has a screen position in real pixels, not logical ones
qreal dpr = screen->devicePixelRatio();
scrRect.moveTo(QPointF(scrRect.x() / dpr, scrRect.y() / dpr).toPoint());
geometry = geometry.united(scrRect);
}
return geometry;
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/capture/buttonhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ size_t ButtonHandler::size() const

// updatePosition updates the position of the buttons around the
// selection area. Ignores the sides blocked by the end of the screen.
// When the selection is too small it works on a virtual selection with
// When the selection is too small, it works on a virtual selection with
// the original in the center.
void ButtonHandler::updatePosition(const QRect& selection)
{
Expand Down Expand Up @@ -122,7 +122,7 @@ void ButtonHandler::updatePosition(const QRect& selection)
horizontalPoints(center, addCounter, true);
moveButtonsToPoints(positions, elemIndicator);
}
// Add buttons at the right side of the selection
// Add buttons to the right side of the selection
if (!m_blockedRight && elemIndicator < vecLength) {
int addCounter = buttonsPerCol;
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
Expand All @@ -146,7 +146,7 @@ void ButtonHandler::updatePosition(const QRect& selection)
horizontalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator);
}
// Add buttons at the left side of the selection
// Add buttons to the left side of the selection
if (!m_blockedLeft && elemIndicator < vecLength) {
int addCounter = buttonsPerCol;
addCounter = qBound(0, addCounter, vecLength - elemIndicator);
Expand Down
30 changes: 23 additions & 7 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
#include "abstractlogger.h"
#include "copytool.h"
#include "src/config/cacheutils.h"
#include "src/config/generalconf.h"
#include "src/core/flameshot.h"
#include "src/core/qguiappcurrentscreen.h"
#include "src/tools/toolfactory.h"
#include "src/utils/colorutils.h"
#include "src/utils/screengrabber.h"
#include "src/utils/screenshotsaver.h"
#include "src/utils/systemnotification.h"
Expand All @@ -32,9 +29,7 @@
#include <QApplication>
#include <QCheckBox>
#include <QDateTime>
#include <QDebug>
#include <QFontMetrics>
#include <QLabel>
#include <QMessageBox>
#include <QPaintEvent>
#include <QPainter>
Expand Down Expand Up @@ -150,6 +145,7 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
move(currentScreen->geometry().x(), currentScreen->geometry().y());
resize(currentScreen->size());
// LINUX
#else
// Call cmake with -DFLAMESHOT_DEBUG_CAPTURE=ON to enable easier debugging
#if !defined(FLAMESHOT_DEBUG_CAPTURE)
Expand All @@ -161,6 +157,18 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
move(desktopGeom.topLeft());
resize(desktopGeom.size());
#endif
// Need to move to the top left screen
QPoint topLeft(0, INT_MAX);
for (QScreen* const screen : QGuiApplication::screens()) {
qreal dpr = screen->devicePixelRatio();
QPoint topLeftScreen = screen->geometry().topLeft() / dpr;
if (topLeftScreen.x() == 0) {
if (topLeftScreen.y() < topLeft.y()) {
topLeft.setY(topLeftScreen.y());
}
}
}
move(topLeft);
#endif
}
QVector<QRect> areas;
Expand All @@ -182,6 +190,7 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
r.moveTo(0, 0);
areas.append(r);
#else
// LINUX & WINDOWS
for (QScreen* const screen : QGuiApplication::screens()) {
QRect r = screen->geometry();
r.moveTo(r.x() / screen->devicePixelRatio(),
Expand Down Expand Up @@ -259,8 +268,15 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
OverlayMessage::instance()->update();
});

OverlayMessage::init(this,
QGuiAppCurrentScreen().currentScreen()->geometry());
// Qt6 has only sizes in logical values, position is in physical values.
// Move Help message to the logical pixel with devicePixelRatio.
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
QRect currentScreenGeometry = currentScreen->geometry();
qreal currentScreenDpr = currentScreen->devicePixelRatio();
currentScreenGeometry.moveTo(
int(currentScreenGeometry.x() / currentScreenDpr),
int(currentScreenGeometry.y() / currentScreenDpr));
OverlayMessage::init(this, currentScreenGeometry);

if (m_config.showHelp()) {
initHelpMessage();
Expand Down
Loading