-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (67 loc) · 2.02 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
75
#ifndef DEBUG_MODE
#include <SessionLockQt/command.h>
#include <SessionLockQt/shell.h>
#include <SessionLockQt/window.h>
#endif
#include <QGuiApplication>
#include <QIcon>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QWindow>
#include <cstdlib>
using namespace Qt::StringLiterals;
int
main(int argc, char *argv[])
{
#ifndef DEBUG_MODE
ExtSessionLockV1Qt::Shell::useExtSessionLock();
#endif
QGuiApplication::setOrganizationName("waycrate");
QGuiApplication::setApplicationName("WayCrateDM");
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("Material");
QIcon::setThemeName("breeze");
auto screens = QGuiApplication::screens();
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/WayCrateDM/qml/main.qml"_s);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
for (auto screen : screens) {
engine.load(url);
if (QWindow *window = qobject_cast<QWindow *>(engine.rootObjects().last())) {
#ifndef DEBUG_MODE
ExtSessionLockV1Qt::Window::registerWindowFromQtScreen(window, screen);
#endif
window->show();
} else {
qDebug() << "Cannot get window";
return 0;
}
}
QObject::connect(&app, &QGuiApplication::screenAdded, &app, [&engine, url](auto screen) {
engine.load(url);
if (QWindow *window = qobject_cast<QWindow *>(engine.rootObjects().last())) {
#ifndef DEBUG_MODE
ExtSessionLockV1Qt::Window::registerWindowFromQtScreen(window, screen);
#endif
window->show();
} else {
qDebug() << "Cannot get window";
exit(0);
}
#ifndef DEBUG_MODE
ExtSessionLockV1Qt::Command::instance()->LockScreen();
#endif
});
#ifndef DEBUG_MODE
ExtSessionLockV1Qt::Command::instance()->LockScreen();
#endif
return app.exec();
}