X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=homescreen%2Fsrc%2Fmain.cpp;h=74ec4f49420f9dd01bb85776f231310196e355fa;hb=e490ff1e1e31b4a837cb8063f7346dc65ffe073e;hp=75ed97c32da419fc1e7b3b2507270ab97e97f1e2;hpb=2b7ca7a6eeb79e03507abb7a16b0503591d2b064;p=apps%2Fhomescreen.git diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 75ed97c..74ec4f4 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -26,10 +26,9 @@ #include #include -#if 0 #include #include -#endif + #include "applicationlauncher.h" #include "statusbarmodel.h" #include "mastervolume.h" @@ -40,19 +39,64 @@ #include #include "wayland-agl-shell-client-protocol.h" +#include "wayland-agl-shell-desktop-client-protocol.h" #include "shell.h" +struct shell_data { + struct agl_shell *shell; + struct agl_shell_desktop *shell_desktop; +}; + +static void +agl_shell_desktop_application(void *data, + struct agl_shell_desktop *agl_shell_desktop, + const char *app_id) +{ + HomescreenHandler *homescreenHandler = static_cast(data); + + if (homescreenHandler) + homescreenHandler->addAppToStack(app_id); +} + +static void +agl_shell_desktop_state_app(void *data, + struct agl_shell_desktop *agl_shell_desktop, + const char *app_id, + const char *app_data, + uint32_t state, + uint32_t role) +{ + HomescreenHandler *homescreenHandler = static_cast(data); + + if (homescreenHandler && state == AGL_SHELL_DESKTOP_APP_STATE_DESTROYED) + homescreenHandler->appTerminated(app_id); +} + +static const struct agl_shell_desktop_listener shell_desktop_listener = { + agl_shell_desktop_application, + agl_shell_desktop_state_app +}; + static void global_add(void *data, struct wl_registry *reg, uint32_t name, const char *interface, uint32_t) { - struct agl_shell **shell = static_cast(data); + struct shell_data *shell_data = static_cast(data); + + if (!shell_data) + return; if (strcmp(interface, agl_shell_interface.name) == 0) { - *shell = static_cast( + shell_data->shell = static_cast( wl_registry_bind(reg, name, &agl_shell_interface, 1) ); } + + if (strcmp(interface, agl_shell_desktop_interface.name) == 0) { + shell_data->shell_desktop = static_cast( + wl_registry_bind(reg, name, &agl_shell_desktop_interface, 1) + ); + } } static void @@ -84,25 +128,22 @@ getWlOutput(QPlatformNativeInterface *native, QScreen *screen) } -static struct agl_shell * -register_agl_shell(QPlatformNativeInterface *native) +static void +register_agl_shell(QPlatformNativeInterface *native, struct shell_data *shell_data) { struct wl_display *wl; struct wl_registry *registry; - struct agl_shell *shell = nullptr; wl = static_cast( native->nativeResourceForIntegration("display") ); registry = wl_display_get_registry(wl); - wl_registry_add_listener(registry, ®istry_listener, &shell); + wl_registry_add_listener(registry, ®istry_listener, shell_data); /* Roundtrip to get all globals advertised by the compositor */ wl_display_roundtrip(wl); wl_registry_destroy(registry); - - return shell; } static struct wl_surface * @@ -207,17 +248,18 @@ load_agl_shell_app(QPlatformNativeInterface *native, int main(int argc, char *argv[]) { setenv("QT_QPA_PLATFORM", "wayland", 1); + setenv("QT_QUICK_CONTROLS_STYLE", "AGL", 1); QGuiApplication a(argc, argv); const char *screen_name; bool is_demo_val = false; + struct shell_data shell_data = { nullptr, nullptr }; QPlatformNativeInterface *native = qApp->platformNativeInterface(); - struct agl_shell *agl_shell = nullptr; 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; + is_demo_val = true; QCoreApplication::setOrganizationDomain("LinuxFoundation"); QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); @@ -226,15 +268,20 @@ int main(int argc, char *argv[]) /* we need to have an app_id */ a.setDesktopFileName("homescreen"); - 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); + 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); + } + if (!shell_data.shell_desktop) { + fprintf(stderr, "agl_shell_desktop extension is not advertised. " + "Are you sure that agl-compositor is running?\n"); + exit(EXIT_FAILURE); } - std::shared_ptr shell{agl_shell, agl_shell_destroy}; - Shell *aglShell = new Shell(shell, &a); + std::shared_ptr agl_shell{shell_data.shell, agl_shell_destroy}; + Shell *aglShell = new Shell(agl_shell, &a); // import C++ class to QML qmlRegisterType("HomeScreen", 1, 0, "StatusBarModel"); @@ -245,22 +292,23 @@ int main(int argc, char *argv[]) HomescreenHandler* homescreenHandler = new HomescreenHandler(aglShell, launcher); homescreenHandler->init(); + agl_shell_desktop_add_listener(shell_data.shell_desktop, &shell_desktop_listener, homescreenHandler); + QQmlApplicationEngine engine; QQmlContext *context = engine.rootContext(); context->setContextProperty("homescreenHandler", homescreenHandler); context->setContextProperty("launcher", launcher); -#if 0 - context->setContextProperty("weather", new Weather(bindingAddress)); - context->setContextProperty("bluetooth", new Bluetooth(bindingAddress, context)); -#endif + 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, agl_shell, screen_name, is_demo_val); + load_agl_shell_app(native, &engine, shell_data.shell, screen_name, is_demo_val); return a.exec(); }