homescreenhandler: Add support for starting apps on different outputs 78/28678/1
authorMarius Vlad <marius.vlad@collabora.com>
Thu, 13 Apr 2023 08:22:58 +0000 (11:22 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Thu, 20 Apr 2023 18:34:19 +0000 (21:34 +0300)
Using the agl-shell protocol. This also needs a bump to version 8 of the
agl-shell protocol to be able to receive events.

Bug-AGL: SPEC-4529
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I2989ebc8eb36b8b1272782e5986017e9b557cab7

homescreen/src/homescreenhandler.cpp
homescreen/src/homescreenhandler.h
homescreen/src/main.cpp

index e7d6a39..918237a 100644 (file)
@@ -11,6 +11,8 @@
 #include "homescreenhandler.h"
 #include "hmi-debug.h"
 
+QScreen *find_screen(const char *output);
+
 // defined by meson build file
 #include QT_QPA_HEADER
 
@@ -98,8 +100,39 @@ void HomescreenHandler::activateApp(const QString& app_id)
        if (mp_launcher) {
                mp_launcher->setCurrent(app_id);
        }
+       HMI_DEBUG("HomeScreen", "Activating app_id %s by default output %p\n",
+                       app_id.toStdString().c_str(), mm_output);
+
+       // search for a pending application which might have a different output
+       auto iter = pending_app_list.begin();
+       bool found_pending_app = false;
+       while (iter != pending_app_list.end()) {
+               const QString &app_to_search = iter->first;
+
+               if (app_to_search == app_id) {
+                       found_pending_app = true;
+                       break;
+               }
+
+               iter++;
+       }
+
+       if (found_pending_app) {
+               const QString &output_name = iter->second;
+               QScreen *screen =
+                       ::find_screen(output_name.toStdString().c_str());
+
+               mm_output = getWlOutput(native, screen);
+               pending_app_list.erase(iter);
+
+               HMI_DEBUG("HomeScreen", "For application %s found another "
+                               "output to activate %s\n",
+                               app_id.toStdString().c_str(),
+                               output_name.toStdString().c_str());
+       }
 
-       HMI_DEBUG("HomeScreen", "Activating application %s", app_id.toStdString().c_str());
+       HMI_DEBUG("HomeScreen", "Activating application %s",
+                       app_id.toStdString().c_str());
 
        agl_shell_activate_app(agl_shell, app_id.toStdString().c_str(), mm_output);
 }
index a2baeb2..e014192 100644 (file)
@@ -30,6 +30,7 @@ public:
        void activateApp(const QString& app_id);
        void deactivateApp(const QString& app_id);
 
+       std::list<std::pair<const QString, const QString>> pending_app_list;
 signals:
        void showNotification(QString application_id, QString icon_path, QString text);
        void showInformation(QString info);
index 5d7e36d..d2967ca 100644 (file)
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 #endif
 
+QScreen *
+find_screen(const char *screen_name)
+{
+       QList<QScreen *> screens = qApp->screens();
+       QScreen *found = nullptr;
+       QString qstr_name = QString::fromUtf8(screen_name, -1);
+
+       for (QScreen *xscreen : screens) {
+               if (qstr_name == xscreen->name()) {
+                       found = xscreen;
+                       break;
+               }
+       }
+
+       return found;
+}
+
 struct shell_data {
        struct agl_shell *shell;
        HomescreenHandler *homescreenHandler;
@@ -90,12 +107,28 @@ agl_shell_app_state(void *data, struct agl_shell *agl_shell,
        }
 }
 
+static void
+agl_shell_app_on_output(void *data, struct agl_shell *agl_shell,
+               const char *app_id, const char *output_name)
+{
+       struct shell_data *shell_data = static_cast<struct shell_data *>(data);
+       HomescreenHandler *homescreenHandler = shell_data->homescreenHandler;
+
+       if (!homescreenHandler)
+               return;
+
+       std::pair new_pending_app = std::pair(QString(app_id),
+                                             QString(output_name));
+       homescreenHandler->pending_app_list.push_back(new_pending_app);
+}
+
 
 #ifdef AGL_SHELL_BOUND_OK_SINCE_VERSION
 static const struct agl_shell_listener shell_listener = {
        agl_shell_bound_ok,
        agl_shell_bound_fail,
        agl_shell_app_state,
+       agl_shell_app_on_output,
 };
 #endif
 
@@ -112,7 +145,7 @@ global_add(void *data, struct wl_registry *reg, uint32_t name,
                if (ver >= 2) {
                        shell_data->shell =
                                static_cast<struct agl_shell *>(
-                                       wl_registry_bind(reg, name, &agl_shell_interface, MIN(4, ver)));
+                                       wl_registry_bind(reg, name, &agl_shell_interface, MIN(8, ver)));
 #ifdef AGL_SHELL_BOUND_OK_SINCE_VERSION
                        agl_shell_add_listener(shell_data->shell, &shell_listener, data);
 #endif
@@ -192,22 +225,6 @@ create_component(QPlatformNativeInterface *native, QQmlComponent *comp,
        return getWlSurface(native, win);
 }
 
-static QScreen *
-find_screen(const char *screen_name)
-{
-       QList<QScreen *> screens = qApp->screens();
-       QScreen *found = nullptr;
-       QString qstr_name = QString::fromUtf8(screen_name, -1);
-
-       for (QScreen *xscreen : screens) {
-               if (qstr_name == xscreen->name()) {
-                       found = xscreen;
-                       break;
-               }
-       }
-
-       return found;
-}
 
 static void
 load_agl_shell(QPlatformNativeInterface *native, QQmlApplicationEngine *engine,