oshelper: wait for hidden window before taking screenshot on macOS

Also improve error message and add a missing include.
This commit is contained in:
selsta committed 2026-07-19 20:43:32 +02:00
1 parent 26b69025d5
commit 62d0a59ccb
1 file changed
+12 -1
+12 -1
View File
@@ -28,6 +28,7 @@
#include "oshelper.h"
#include <algorithm>
#include <unordered_set>
#include <QCoreApplication>
@@ -45,6 +46,8 @@
#include <QByteArray>
#include <QRandomGenerator>
#ifdef Q_OS_MAC
#include <QEventLoop>
#include <QThread>
#include "qt/macoshelper.h"
#endif
#ifdef Q_OS_WIN
@@ -74,6 +77,14 @@ QPixmap screenshot()
window->hide();
}
}
#if defined(Q_OS_MAC)
// Let Qt submit the native hide operations before blocking the GUI thread.
QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
// Give WindowServer time to finish removing the window.
QThread::msleep(100);
#endif
const auto unhide = sg::make_scope_guard([&hidden]() {
for (QWindow *window : hidden)
{
@@ -144,7 +155,7 @@ QList<QString> OSHelper::grabQrCodesFromScreen() const
}
catch (const std::exception &e)
{
qWarning() << e.what();
qWarning() << "QR screen capture: decoder exception:" << e.what();
}
return codes;