Distinguish monitors with identical Qt screen names
This commit is contained in:
1 parent
218249f9a5
commit
3d2f90e8ae
2 files changed
+57
-3
No files matched your search
@@ -7,6 +7,8 @@
|
||||
#include <QScreen>
|
||||
#include <QRandomGenerator>
|
||||
#include <QTransform>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
@@ -33,6 +35,19 @@ namespace {
|
||||
int64_t monotonicUs() { return std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count(); }
|
||||
QString text(const char* value) { return QCoreApplication::translate("ChatGui", value); }
|
||||
#ifdef HAVE_STREAM_CAPTURE
|
||||
/* Имя QScreen не уникально (например, несколько X11 screens); номер различает одинаковые дескрипторы. */
|
||||
QByteArray screenId(QScreen* screen) {
|
||||
int duplicate = 0;
|
||||
for (auto* other : QGuiApplication::screens()) {
|
||||
if (other == screen) break;
|
||||
if (other->name() == screen->name() && other->manufacturer() == screen->manufacturer()
|
||||
&& other->model() == screen->model() && other->serialNumber() == screen->serialNumber()) duplicate++;
|
||||
}
|
||||
return QJsonDocument(QJsonArray{screen->name(), screen->manufacturer(), screen->model(), screen->serialNumber(), duplicate})
|
||||
.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
struct StreamPublishEngine::Impl {
|
||||
struct Audio { int64_t pts = 0, created = 0; uint64_t sequence = 0; unsigned frames = 0; int16_t pcm[1920]{}; };
|
||||
@@ -148,9 +163,10 @@ QList<StreamVideoSource> StreamPublishEngine::sources() {
|
||||
|| qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
|
||||
sources.push_back({StreamVideoSource::Screen, text("Screen (system selection)"), "portal", {}});
|
||||
} else {
|
||||
int number = 0;
|
||||
for (auto* screen : QGuiApplication::screens()) {
|
||||
QSize size = screen->size() * screen->devicePixelRatio();
|
||||
sources.push_back({StreamVideoSource::Screen, screen->name(), screen->name().toUtf8(), {}, size});
|
||||
sources.push_back({StreamVideoSource::Screen, QStringLiteral("%1: %2").arg(++number).arg(screen->name()), screenId(screen), {}, size});
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "desktop screen capability source=%s logical=%dx%d scale=%.3f pixels=%dx%d",
|
||||
qPrintable(screen->name()), screen->size().width(), screen->size().height(), screen->devicePixelRatio(), size.width(), size.height());
|
||||
}
|
||||
@@ -225,7 +241,7 @@ bool StreamPublishEngine::openSource(const StreamPublishConfig& config) {
|
||||
m->screen = std::make_unique<QScreenCapture>();
|
||||
if (config.source.id != "portal") {
|
||||
QScreen* selected = nullptr;
|
||||
for (auto* screen : QGuiApplication::screens()) if (screen->name().toUtf8() == config.source.id) selected = screen;
|
||||
for (auto* screen : QGuiApplication::screens()) if (screenId(screen) == config.source.id) { selected = screen; break; }
|
||||
if (!selected) { DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop screen disappeared"); return false; }
|
||||
m->screen->setScreen(selected);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user