+static bool
+ivi_check_pending_desktop_surface_split(struct ivi_surface *surface)
+{
+ struct pending_split *split_surf, *next_split_surf;
+ struct ivi_compositor *ivi = surface->ivi;
+ const char *_app_id =
+ weston_desktop_surface_get_app_id(surface->dsurface);
+
+ if (wl_list_empty(&ivi->split_pending_apps) || !_app_id)
+ return false;
+
+ wl_list_for_each_safe(split_surf, next_split_surf,
+ &ivi->split_pending_apps, link) {
+ if (!strcmp(_app_id, split_surf->app_id)) {
+ surface->split.output = split_surf->ioutput;
+ surface->split.orientation = split_surf->orientation;
+ if (!ivi_compositor_keep_pending_surfaces(surface))
+ ivi_remove_pending_desktop_surface_split(split_surf);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool
+ivi_check_pending_desktop_surface_fullscreen(struct ivi_surface *surface)
+{
+ struct pending_fullscreen *fs_surf, *next_fs_surf;
+ struct ivi_compositor *ivi = surface->ivi;
+ const char *_app_id =
+ weston_desktop_surface_get_app_id(surface->dsurface);
+
+ if (wl_list_empty(&ivi->fullscreen_pending_apps) || !_app_id)
+ return false;
+
+ wl_list_for_each_safe(fs_surf, next_fs_surf,
+ &ivi->fullscreen_pending_apps, link) {
+ if (!strcmp(_app_id, fs_surf->app_id)) {
+ surface->fullscreen.output = fs_surf->ioutput;
+ if (!ivi_compositor_keep_pending_surfaces(surface))
+ ivi_remove_pending_desktop_surface_fullscreen(fs_surf);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool
+ivi_check_pending_desktop_surface_remote(struct ivi_surface *surface)
+{
+ struct pending_remote *remote_surf, *next_remote_surf;
+ struct ivi_compositor *ivi = surface->ivi;
+ const char *_app_id =
+ weston_desktop_surface_get_app_id(surface->dsurface);
+
+ if (wl_list_empty(&ivi->remote_pending_apps) || !_app_id)
+ return false;
+
+ wl_list_for_each_safe(remote_surf, next_remote_surf,
+ &ivi->remote_pending_apps, link) {
+ if (!strcmp(_app_id, remote_surf->app_id)) {
+ surface->remote.output = remote_surf->ioutput;
+ if (!ivi_compositor_keep_pending_surfaces(surface))
+ ivi_remove_pending_desktop_surface_remote(remote_surf);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+ivi_check_pending_surface(struct ivi_surface *surface)
+{
+ struct ivi_compositor *ivi = surface->ivi;
+ struct wl_list *role_pending_list;
+ struct pending_popup *p_popup;
+ struct pending_split *p_split;
+ struct pending_fullscreen *p_fullscreen;
+ struct pending_remote *p_remote;
+ const char *app_id =
+ weston_desktop_surface_get_app_id(surface->dsurface);
+
+ if (!app_id)
+ return false;
+
+ role_pending_list = &ivi->popup_pending_apps;
+ wl_list_for_each(p_popup, role_pending_list, link) {
+ if (!strcmp(app_id, p_popup->app_id)) {
+ return true;
+ }
+ }
+
+ role_pending_list = &ivi->split_pending_apps;
+ wl_list_for_each(p_split, role_pending_list, link) {
+ if (!strcmp(app_id, p_split->app_id)) {
+ return true;
+ }
+ }
+
+ role_pending_list = &ivi->fullscreen_pending_apps;
+ wl_list_for_each(p_fullscreen, role_pending_list, link) {
+ if (!strcmp(app_id, p_fullscreen->app_id)) {
+ return true;
+ }
+ }
+
+ role_pending_list = &ivi->remote_pending_apps;
+ wl_list_for_each(p_remote, role_pending_list, link) {
+ if (!strcmp(app_id, p_remote->app_id)) {
+ return true;
+ }
+ }
+
+ /* else, we are a regular desktop surface */
+ return false;
+}
+
+
+void
+ivi_check_pending_desktop_surface(struct ivi_surface *surface)
+{
+ bool ret = false;
+
+ ret = ivi_check_pending_desktop_surface_popup(surface);
+ if (ret) {
+ ivi_set_desktop_surface_popup(surface);
+ ivi_layout_popup_committed(surface);
+ return;
+ }
+
+ ret = ivi_check_pending_desktop_surface_split(surface);
+ if (ret) {
+ ivi_set_desktop_surface_split(surface);
+ ivi_layout_split_committed(surface);
+ return;
+ }
+
+ ret = ivi_check_pending_desktop_surface_fullscreen(surface);
+ if (ret) {
+ ivi_set_desktop_surface_fullscreen(surface);
+ ivi_layout_fullscreen_committed(surface);
+ return;
+ }
+
+ ret = ivi_check_pending_desktop_surface_remote(surface);
+ if (ret) {
+ ivi_set_desktop_surface_remote(surface);
+ ivi_layout_desktop_committed(surface);
+ return;
+ }
+
+ /* if we end up here means we have a regular desktop app and
+ * try to activate it */
+ ivi_set_desktop_surface(surface);
+ ivi_layout_desktop_committed(surface);
+}
+