homescreenhandler: Handle dynamic movement of windows
[apps/homescreen.git] / homescreen / src / main.cpp
index 5d7e36d..d0bd2c3 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;
@@ -85,17 +102,56 @@ agl_shell_app_state(void *data, struct agl_shell *agl_shell,
                qDebug() << "Got AGL_SHELL_APP_STATE_ACTIVATED for app_id " << app_id;
                homescreenHandler->addAppToStack(app_id);
                break;
+       case AGL_SHELL_APP_STATE_DEACTIVATED:
+               qDebug() << "Got AGL_SHELL_APP_STATE_DEACTIVATED for app_id " << app_id;
+               homescreenHandler->processAppStatusEvent(app_id, "deactivated");
+               break;
        default:
                break;
        }
 }
 
+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;
+
+       // a couple of use-cases, if there is no app_id in the app_list then it
+       // means this is a request to map the application, from the start to a
+       // different output that the default one. We'd get an
+       // AGL_SHELL_APP_STATE_STARTED which will handle activation.
+       //
+       // if there's an app_id then it means we might have gotten an event to
+       // move the application to another output; so we'd need to process it
+       // by explicitly calling processAppStatusEvent() which would ultimately
+       // activate the application on other output. We'd have to pick-up the
+       // last activated window and activate the default output.
+       //
+       // finally if the outputs are identical probably that's an user-error -
+       // but the compositor won't activate it again, so we don't handle that.
+       std::pair new_pending_app = std::pair(QString(app_id),
+                                             QString(output_name));
+       homescreenHandler->pending_app_list.push_back(new_pending_app);
+
+       if (homescreenHandler->apps_stack.contains(QString(app_id))) {
+               qDebug() << "Gove event to move " << app_id <<
+                       " to another output " << output_name;
+               homescreenHandler->processAppStatusEvent(app_id, "started");
+       }
+}
+
 
 #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 +168,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 +248,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,