-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
74 lines (60 loc) · 2.32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlEngine>
#include <QQmlContext>
#include <QScreen>
#include <QDebug>
static QQuickView *addView(QScreen *screen, int screenIdx)
{
qDebug("Creating new QQuickView for screen %p", screen);
QQuickView *v = new QQuickView;
v->setScreen(screen);
v->setGeometry(QRect(screen->availableGeometry().topLeft(), QSize(128, 128)));
qDebug() << "Initial QQuickView geometry is" << v->geometry();
v->setResizeMode(QQuickView::SizeRootObjectToView);
v->rootContext()->setContextProperty("screenIdx", screenIdx);
v->rootContext()->setContextProperty("screenGeom", screen->geometry());
v->rootContext()->setContextProperty("screenAvailGeom", screen->availableGeometry());
v->rootContext()->setContextProperty("screenVirtGeom", screen->virtualGeometry());
v->rootContext()->setContextProperty("screenAvailVirtGeom", screen->availableVirtualGeometry());
v->rootContext()->setContextProperty("screenPhysSizeMm", screen->physicalSize());
v->rootContext()->setContextProperty("screenRefresh", screen->refreshRate());
v->setSource(QUrl("qrc:/screen.qml"));
QObject::connect(v->engine(), &QQmlEngine::quit, qGuiApp, &QCoreApplication::quit);
return v;
}
int main(int argc, char **argv)
{
qputenv("QT_LOGGING_RULES", "qt.qpa.*=true");
qputenv("QSG_INFO", "1");
QGuiApplication app(argc, argv);
QList<QScreen *> screens = app.screens();
qDebug("Application sees %d screens", int(screens.count()));
qDebug() << screens;
QVector<QQuickView *> views;
for (int i = 0; i < screens.count(); ++i) {
QQuickView *v = addView(screens[i], i);
views.append(v);
v->showFullScreen();
}
QObject::connect(&app, &QGuiApplication::screenAdded, &app, [&](QScreen *screen) {
QQuickView *v = addView(screen, views.count());
views.append(v);
for (auto *view : views)
{
view->showFullScreen();
}
});
QObject::connect(&app, &QGuiApplication::screenRemoved, &app, [&](QScreen *screen) {
for (QQuickView *v : views) {
if (v->screen() == screen) {
v->close();
views.removeOne(v);
v->deleteLater();
}
}
});
int r = app.exec();
qDeleteAll(views);
return r;
}