+
+static struct ivi_output *
+ivi_layout_get_output_from_surface(struct ivi_surface *surf)
+{
+ struct ivi_output *ivi_output = NULL;
+
+ switch (surf->role) {
+ case IVI_SURFACE_ROLE_DESKTOP:
+ if (surf->desktop.pending_output)
+ ivi_output = surf->desktop.pending_output;
+ else
+ ivi_output = surf->desktop.last_output;
+ break;
+ case IVI_SURFACE_ROLE_POPUP:
+ ivi_output = surf->popup.output;
+ break;
+ default:
+ case IVI_SURFACE_ROLE_BACKGROUND:
+ case IVI_SURFACE_ROLE_PANEL:
+ case IVI_SURFACE_ROLE_NONE:
+ break;
+ }
+
+ return ivi_output;
+}
+
+void
+ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
+{
+ struct ivi_surface *surf;
+ struct ivi_output *ivi_output;
+
+ surf = ivi_find_app(ivi, app_id);
+ if (!surf)
+ return;
+
+ ivi_output = ivi_layout_get_output_from_surface(surf);
+ weston_log("deactiving %s\n", app_id);
+
+ if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
+ struct ivi_surface *previous_active;
+
+ previous_active = ivi_output->previous_active;
+ if (!previous_active) {
+ /* we don't have a previous active it means we should
+ * display the bg */
+ if (ivi_output->active) {
+ struct weston_view *view;
+
+ view = ivi_output->active->view;
+ view->is_mapped = false;
+ view->surface->is_mapped = false;
+
+ weston_layer_entry_remove(&view->layer_link);
+ weston_output_damage(ivi_output->output);
+ }
+ } else {
+ struct weston_desktop_surface *dsurface;
+ const char *previous_active_app_id;
+
+ dsurface = previous_active->dsurface;
+ previous_active_app_id =
+ weston_desktop_surface_get_app_id(dsurface);
+ ivi_layout_activate(ivi_output, previous_active_app_id);
+ }
+ } else if (surf->role == IVI_SURFACE_ROLE_POPUP) {
+ struct weston_view *view = surf->view;
+
+ weston_layer_entry_remove(&view->layer_link);
+ weston_view_damage_below(view);
+ }
+}