Skip to content

Commit

Permalink
wip: fix editing pin on single screen on windows
Browse files Browse the repository at this point in the history
Previously windows would always calculate `topLeft` based on looking at the
topmost and leftmost points of any screens. Presumably because it can't rely
on 0,0 being the top left of the desktop? It would be interesting to compare
that to ScreenGrabber.desktopGeometry().

Anyway, when we only want to draw on a single window we either don't need to
go through all that effort or we should be combing the screen geometry with
the desktop geometry somehow. Like `ScreenGrabber.screenGeometry()` is doing.
Although that method is doing it in a wayland only block so I can't see how it
applies to windows...

This commit diff looks a bit messy but what it's doing is moving the windows
specific code into an else block inside #ifdefs.
  • Loading branch information
toofar committed Dec 28, 2023
1 parent 5756008 commit fdfad50
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,20 @@ void CaptureWidget::positionWindow(const CaptureRequest& req)
AbstractLogger::error() << "window top left: x="
<< QStringLiteral("%1").arg(topLeft.x())
<< " y=" << QStringLiteral("%1").arg(topLeft.y());
}
#if defined(Q_OS_WIN)
for (QScreen* const screen : QGuiApplication::screens()) {
QPoint topLeftScreen = screen->geometry().topLeft();
} else {
for (QScreen* const screen : QGuiApplication::screens()) {
QPoint topLeftScreen = screen->geometry().topLeft();

if (topLeftScreen.x() < topLeft.x()) {
topLeft.setX(topLeftScreen.x());
}
if (topLeftScreen.y() < topLeft.y()) {
topLeft.setY(topLeftScreen.y());
if (topLeftScreen.x() < topLeft.x()) {
topLeft.setX(topLeftScreen.x());
}
if (topLeftScreen.y() < topLeft.y()) {
topLeft.setY(topLeftScreen.y());
}
}
}
#endif // defined(Q_OS_WIN)
}
move(topLeft);
resize(pixmap().size());
#endif
Expand Down Expand Up @@ -467,6 +468,23 @@ void CaptureWidget::showxywh()
void CaptureWidget::initHelpMessage()
{
QList<QPair<QString, QString>> keyMap;
auto req = m_context.request;
if (req.initialCaptureScreen() != nullptr) {
auto topLeft = req.initialCaptureScreen()->geometry().topLeft();
keyMap << QPair("Selected Screen Top Left", QStringLiteral("%1x%2").arg(topLeft.x()).arg(topLeft.y()));
for (QScreen* const screen : QGuiApplication::screens()) {
QPoint topLeftScreen = screen->geometry().topLeft();
keyMap << QPair("Some Screen Top Left", QStringLiteral("%1x%2").arg(topLeftScreen.x()).arg(topLeftScreen.y()));

if (topLeftScreen.x() < topLeft.x()) {
topLeft.setX(topLeftScreen.x());
}
if (topLeftScreen.y() < topLeft.y()) {
topLeft.setY(topLeftScreen.y());
}
}
keyMap << QPair("Final Top Left", QStringLiteral("%1x%2").arg(topLeft.x()).arg(topLeft.y()));
}
keyMap << QPair(tr("Mouse"), tr("Select screenshot area"));
using CT = CaptureTool;
for (auto toolType : { CT::TYPE_ACCEPT, CT::TYPE_SAVE, CT::TYPE_COPY }) {
Expand Down

0 comments on commit fdfad50

Please sign in to comment.