+static void
+ivi_remove_pending_desktop_surface_remote(struct pending_remote *remote)
+{
+ free(remote->app_id);
+ wl_list_remove(&remote->link);
+ free(remote);
+}
+
+static bool
+ivi_compositor_keep_pending_surfaces(struct ivi_surface *surface)
+{
+ return surface->ivi->keep_pending_surfaces;
+}
+
+static bool
+ivi_check_pending_desktop_surface_popup(struct ivi_surface *surface)
+{
+ struct ivi_compositor *ivi = surface->ivi;
+ struct pending_popup *p_popup, *next_p_popup;
+ const char *_app_id =
+ weston_desktop_surface_get_app_id(surface->dsurface);
+
+ if (wl_list_empty(&ivi->popup_pending_apps) || !_app_id)
+ return false;
+
+ wl_list_for_each_safe(p_popup, next_p_popup,
+ &ivi->popup_pending_apps, link) {
+ if (!strcmp(_app_id, p_popup->app_id)) {
+ surface->popup.output = p_popup->ioutput;
+ surface->popup.x = p_popup->x;
+ surface->popup.y = p_popup->y;
+
+ surface->popup.bb.x = p_popup->bb.x;
+ surface->popup.bb.y = p_popup->bb.y;
+ surface->popup.bb.width = p_popup->bb.width;
+ surface->popup.bb.height = p_popup->bb.height;
+
+ if (!ivi_compositor_keep_pending_surfaces(surface))
+ ivi_remove_pending_desktop_surface_popup(p_popup);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+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;
+}
+void
+ivi_check_pending_surface_desktop(struct ivi_surface *surface,
+ enum ivi_surface_role *role)
+{
+ 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);
+
+ role_pending_list = &ivi->popup_pending_apps;
+ wl_list_for_each(p_popup, role_pending_list, link) {
+ if (app_id && !strcmp(app_id, p_popup->app_id)) {
+ *role = IVI_SURFACE_ROLE_POPUP;
+ return;
+ }
+ }
+
+ role_pending_list = &ivi->split_pending_apps;
+ wl_list_for_each(p_split, role_pending_list, link) {
+ if (app_id && !strcmp(app_id, p_split->app_id)) {
+ *role = IVI_SURFACE_ROLE_SPLIT_V;
+ return;
+ }
+ }
+
+ role_pending_list = &ivi->fullscreen_pending_apps;
+ wl_list_for_each(p_fullscreen, role_pending_list, link) {
+ if (app_id && !strcmp(app_id, p_fullscreen->app_id)) {
+ *role = IVI_SURFACE_ROLE_FULLSCREEN;
+ return;
+ }
+ }
+
+ role_pending_list = &ivi->remote_pending_apps;
+ wl_list_for_each(p_remote, role_pending_list, link) {
+ if (app_id && !strcmp(app_id, p_remote->app_id)) {
+ *role = IVI_SURFACE_ROLE_REMOTE;
+ return;
+ }
+ }
+
+ /* else, we are a regular desktop surface */
+ *role = IVI_SURFACE_ROLE_DESKTOP;
+}
+
+
+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;
+ }