+static struct wl_output *
+getWlOutput(QPlatformNativeInterface *native, QScreen *screen)
+{
+ void *output = native->nativeResourceForScreen("output", screen);
+ return static_cast<struct ::wl_output*>(output);
+}
+
+static struct wl_display *
+getWlDisplay(QPlatformNativeInterface *native)
+{
+ return static_cast<struct wl_display *>(
+ native->nativeResourceForIntegration("display")
+ );
+}
+
+
+static void
+register_agl_shell(QPlatformNativeInterface *native, struct shell_data *shell_data)
+{
+ struct wl_display *wl;
+ struct wl_registry *registry;
+
+ wl = getWlDisplay(native);
+ registry = wl_display_get_registry(wl);
+
+ 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);
+}
+
+static struct wl_surface *
+create_component(QPlatformNativeInterface *native, QQmlComponent *comp,
+ QScreen *screen, QObject **qobj)
+{
+ QObject *obj = comp->create();
+ obj->setParent(screen);
+
+ QWindow *win = qobject_cast<QWindow *>(obj);
+ *qobj = obj;
+
+ return getWlSurface(native, win);
+}
+
+
+static void
+load_agl_shell(QPlatformNativeInterface *native, QQmlApplicationEngine *engine,
+ struct agl_shell *agl_shell, QScreen *screen)
+{
+ struct wl_surface *bg;
+ struct wl_output *output;
+ int32_t x, y;
+ int32_t width, height;
+ QObject *qobj_bg;
+ QSize size = screen->size();
+
+ // this incorporates the panels directly, but in doing so, it
+ // would also need to specify an activation area the same area
+ // in order to void overlapping any new activation window
+ QQmlComponent bg_comp(engine, QUrl("qrc:/background_with_panels.qml"));
+ qInfo() << bg_comp.errors();
+
+ bg = create_component(native, &bg_comp, screen, &qobj_bg);
+
+ output = getWlOutput(native, screen);
+
+ qDebug() << "Normal mode - with single surface";
+ qDebug() << "Setting homescreen to screen " << screen->name();
+ agl_shell_set_background(agl_shell, bg, output);
+
+ // 216 is the width size of the panel
+ x = 0;
+ y = 216;
+
+ width = size.width();
+ height = size.height() - (2 * y);
+
+ qDebug() << "Using custom rectangle " << width << "x" << height
+ << "+" << x << "x" << y << " for activation";
+ qDebug() << "Panels should be embedded the background surface";
+
+#ifdef AGL_SHELL_SET_ACTIVATE_REGION_SINCE_VERSION
+ agl_shell_set_activate_region(agl_shell, output,
+ x, y, width, height);
+#endif
+}
+
+static void
+load_agl_shell_for_ci(QPlatformNativeInterface *native,
+ QQmlApplicationEngine *engine,
+ struct agl_shell *agl_shell, QScreen *screen)
+{
+ struct wl_surface *bg, *top, *bottom;
+ struct wl_output *output;
+ QObject *qobj_bg, *qobj_top, *qobj_bottom;
+
+ QQmlComponent bg_comp(engine, QUrl("qrc:/background_demo.qml"));
+ qInfo() << bg_comp.errors();
+
+ QQmlComponent top_comp(engine, QUrl("qrc:/toppanel_demo.qml"));
+ qInfo() << top_comp.errors();
+
+ QQmlComponent bot_comp(engine, QUrl("qrc:/bottompanel_demo.qml"));
+ qInfo() << bot_comp.errors();
+
+ top = create_component(native, &top_comp, screen, &qobj_top);
+ bottom = create_component(native, &bot_comp, screen, &qobj_bottom);
+ bg = create_component(native, &bg_comp, screen, &qobj_bg);
+
+ /* engine.rootObjects() works only if we had a load() */
+ StatusBarModel *statusBar = qobj_top->findChild<StatusBarModel *>("statusBar");
+ if (statusBar) {
+ qDebug() << "got statusBar objectname, doing init()";
+ statusBar->init(engine->rootContext());
+ }
+
+ output = getWlOutput(native, screen);
+
+ qDebug() << "Setting homescreen to screen " << screen->name();
+
+ agl_shell_set_background(agl_shell, bg, output);
+ agl_shell_set_panel(agl_shell, top, output, AGL_SHELL_EDGE_TOP);
+ agl_shell_set_panel(agl_shell, bottom, output, AGL_SHELL_EDGE_BOTTOM);
+
+ qDebug() << "CI mode - with multiple surfaces";
+}
+
+static void
+load_agl_shell_app(QPlatformNativeInterface *native, QQmlApplicationEngine *engine,
+ struct agl_shell *agl_shell, const char *screen_name, bool is_demo)
+{
+ QScreen *screen = nullptr;
+
+ if (!screen_name)
+ screen = qApp->primaryScreen();
+ else
+ screen = find_screen(screen_name);
+
+ if (!screen) {
+ qDebug() << "No outputs present in the system.";
+ return;
+ }
+
+ if (is_demo) {
+ load_agl_shell_for_ci(native, engine, agl_shell, screen);
+ } else {
+ load_agl_shell(native, engine, agl_shell, screen);
+ }
+
+ /* Delay the ready signal until after Qt has done all of its own setup
+ * in a.exec() */
+ QTimer::singleShot(500, [agl_shell](){
+ qDebug() << "sending ready to compositor";
+ agl_shell_ready(agl_shell);
+ });