- QGuiApplication a(argc, argv);
- QPlatformNativeInterface *native = qApp->platformNativeInterface();
- struct agl_shell *agl_shell = nullptr;
-
- QCoreApplication::setOrganizationDomain("LinuxFoundation");
- QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
- QCoreApplication::setApplicationName("HomeScreen");
- QCoreApplication::setApplicationVersion("0.7.0");
-
- QCommandLineParser parser;
- parser.addPositionalArgument("port", a.translate("main", "port for binding"));
- parser.addPositionalArgument("secret", a.translate("main", "secret for binding"));
- parser.addHelpOption();
- parser.addVersionOption();
- parser.process(a);
- QStringList positionalArguments = parser.positionalArguments();
-
- int port = 1700;
- QString token = "wm";
- QString graphic_role = "homescreen"; // defined in layers.json in Window Manager
-
- if (positionalArguments.length() == 2) {
- port = positionalArguments.takeFirst().toInt();
- token = positionalArguments.takeFirst();
- }
-
- HMI_DEBUG("HomeScreen","port = %d, token = %s", port, token.toStdString().c_str());
-
- agl_shell = register_agl_shell(native);
- if (!agl_shell) {
- fprintf(stderr, "agl_shell extension is not advertised. "
- "Are you sure that agl-compositor is running?\n");
- exit(EXIT_FAILURE);
- }
-
- std::shared_ptr<struct agl_shell> shell{agl_shell, agl_shell_destroy};
- Shell *aglShell = new Shell(shell, &a);
-
- // import C++ class to QML
- // qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher");
- qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
- qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
- qmlRegisterUncreatableType<ChromeController>("SpeechChrome", 1, 0, "SpeechChromeController",
- QLatin1String("SpeechChromeController is uncreatable."));
-
- ApplicationLauncher *launcher = new ApplicationLauncher();
-
- HomescreenHandler* homescreenHandler = new HomescreenHandler(aglShell);
- homescreenHandler->init(port, token.toStdString().c_str());
-
- QUrl bindingAddress;
- bindingAddress.setScheme(QStringLiteral("ws"));
- bindingAddress.setHost(QStringLiteral("localhost"));
- bindingAddress.setPort(port);
- bindingAddress.setPath(QStringLiteral("/api"));
-
- QUrlQuery query;
- query.addQueryItem(QStringLiteral("token"), token);
- bindingAddress.setQuery(query);
-
- QQmlApplicationEngine engine;
- QQmlContext *context = engine.rootContext();
- context->setContextProperty("bindingAddress", bindingAddress);
-
- context->setContextProperty("homescreenHandler", homescreenHandler);
- context->setContextProperty("launcher", launcher);
- context->setContextProperty("weather", new Weather(bindingAddress));
- context->setContextProperty("bluetooth", new Bluetooth(bindingAddress, context));
- context->setContextProperty("speechChromeController", new ChromeController(bindingAddress, &engine));
- // we add it here even if we don't use it
- context->setContextProperty("shell", aglShell);
-
- /* instead of loading main.qml we load one-by-one each of the QMLs,
- * divided now between several surfaces: panels, background.
- */
- load_agl_shell_app(native, &engine, agl_shell, bindingAddress);
-
- return a.exec();
+ setenv("QT_QPA_PLATFORM", "wayland", 1);
+ setenv("QT_QUICK_CONTROLS_STYLE", "AGL", 1);
+
+ QGuiApplication app(argc, argv);
+ const char *screen_name;
+ bool is_demo_val = false;
+ bool is_embedded_panels = false;
+ int ret = 0;
+ struct shell_data shell_data = { nullptr, nullptr, true, false, 0 };
+
+ QPlatformNativeInterface *native = qApp->platformNativeInterface();
+ screen_name = getenv("HOMESCREEN_START_SCREEN");
+
+ const char *is_demo = getenv("HOMESCREEN_DEMO_CI");
+ if (is_demo && strcmp(is_demo, "1") == 0)
+ is_demo_val = true;
+
+ const char *embedded_panels = getenv("HOMESCREEN_EMBEDDED_PANELS");
+ if (embedded_panels && strcmp(embedded_panels, "1") == 0)
+ is_embedded_panels = true;
+
+ QCoreApplication::setOrganizationDomain("LinuxFoundation");
+ QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
+ QCoreApplication::setApplicationName("HomeScreen");
+ QCoreApplication::setApplicationVersion("0.7.0");
+
+ // we need to have an app_id
+ app.setDesktopFileName("homescreen");
+
+ register_agl_shell(native, &shell_data);
+ if (!shell_data.shell) {
+ fprintf(stderr, "agl_shell extension is not advertised. "
+ "Are you sure that agl-compositor is running?\n");
+ exit(EXIT_FAILURE);
+ }
+
+ qDebug() << "agl-shell interface is at version " << shell_data.ver;
+ if (shell_data.ver >= 2) {
+ while (ret != -1 && shell_data.wait_for_bound) {
+ ret = wl_display_dispatch(getWlDisplay(native));
+
+ if (shell_data.wait_for_bound)
+ continue;
+ }
+
+ if (!shell_data.bound_ok) {
+ qInfo() << "agl_shell extension already in use by other shell client.";
+ exit(EXIT_FAILURE);
+ }
+ }
+
+
+ std::shared_ptr<struct agl_shell> agl_shell{shell_data.shell, agl_shell_destroy};
+ Shell *aglShell = new Shell(agl_shell, &app);
+
+ // Import C++ class to QML
+ qmlRegisterType<StatusBarModel>("HomeScreen", 1, 0, "StatusBarModel");
+ qmlRegisterType<MasterVolume>("MasterVolume", 1, 0, "MasterVolume");
+
+ ApplicationLauncher *launcher = new ApplicationLauncher();
+ launcher->setCurrent(QStringLiteral("launcher"));
+
+ HomescreenHandler* homescreenHandler = new HomescreenHandler(aglShell, launcher);
+ shell_data.homescreenHandler = homescreenHandler;
+
+ QQmlApplicationEngine engine;
+ QQmlContext *context = engine.rootContext();
+
+ context->setContextProperty("homescreenHandler", homescreenHandler);
+ context->setContextProperty("launcher", launcher);
+ context->setContextProperty("weather", new Weather());
+ context->setContextProperty("bluetooth", new Bluetooth(false, context));
+
+ // We add it here even if we don't use it
+ context->setContextProperty("shell", aglShell);
+
+ // Instead of loading main.qml we load one-by-one each of the QMLs,
+ // divided now between several surfaces: panels, background.
+ load_agl_shell_app(native, &engine, shell_data.shell,
+ screen_name, is_demo_val, is_embedded_panels);
+
+ return app.exec();