protocol/agl-shell.xml: Add an app_state event -- app state notification
[src/agl-compositor.git] / src / layout.c
index c2b17ce..25221e2 100644 (file)
@@ -194,6 +194,7 @@ ivi_layout_activate_complete(struct ivi_output *output,
        struct weston_view *view = surf->view;
        struct weston_seat *wseat = get_ivi_shell_weston_first_seat(ivi);
        struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(wseat);
+       const char *app_id = weston_desktop_surface_get_app_id(surf->dsurface);
 
        if (weston_view_is_mapped(view)) {
                weston_layer_entry_remove(&view->layer_link);
@@ -201,6 +202,28 @@ ivi_layout_activate_complete(struct ivi_output *output,
                weston_view_update_transform(view);
        }
 
+       if (output_has_black_curtain(output)) {
+               if (!output->background) {
+                       weston_log("Found that we have no background surface "
+                                   "for output %s. Using black curtain as background\n",
+                                   output->output->name);
+
+                       struct weston_view *ev =
+                               output->fullscreen_view.fs->view;
+
+                       /* use the black curtain as background when we have
+                        * none added by the shell client. */
+                       weston_layer_entry_remove(&ev->layer_link);
+                       weston_layer_entry_insert(&ivi->normal.view_list,
+                                                 &ev->layer_link);
+                       weston_view_geometry_dirty(ev);
+                       weston_surface_damage(ev->surface);
+               } else {
+                       remove_black_curtain(output);
+               }
+       }
+
+
        weston_view_set_output(view, woutput);
        weston_view_set_position(view,
                                 woutput->x + output->area.x,
@@ -210,6 +233,26 @@ ivi_layout_activate_complete(struct ivi_output *output,
        surf->mapped = true;
        view->surface->is_mapped = true;
 
+       /* handle a movement from one output to another */
+       if (surf->current_completed_output &&
+           surf->current_completed_output != output) {
+
+               /* we're migrating the same surface but to another output */
+               if (surf->current_completed_output->active == surf) {
+                       struct weston_view *ev =
+                               surf->current_completed_output->active->view;
+
+                       weston_layer_entry_remove(&ev->layer_link);
+                       surf->current_completed_output->previous_active =
+                               surf->current_completed_output->active;
+                       surf->current_completed_output->active = NULL;
+
+                       /* damage all possible outputs to avoid stale views */
+                       weston_compositor_damage_all(ivi->compositor);
+               }
+       }
+
+
        if (output->active) {
                output->active->view->is_mapped = false;
                output->active->view->surface->is_mapped = false;
@@ -218,6 +261,7 @@ ivi_layout_activate_complete(struct ivi_output *output,
        }
        output->previous_active = output->active;
        output->active = surf;
+       surf->current_completed_output = output;
 
        weston_layer_entry_insert(&ivi->normal.view_list, &view->layer_link);
        weston_view_geometry_dirty(view);
@@ -238,8 +282,13 @@ ivi_layout_activate_complete(struct ivi_output *output,
        }
 
        weston_log("Activation completed for app_id %s, role %s, output %s\n",
-                       weston_desktop_surface_get_app_id(surf->dsurface),
+                       app_id,
                        ivi_layout_get_surface_role_name(surf), output->name);
+
+      if (wl_resource_get_version(ivi->shell_client.resource) >= AGL_SHELL_APP_STATE_SINCE_VERSION)
+               agl_shell_send_app_state(ivi->shell_client.resource,
+                                        app_id, AGL_SHELL_APP_STATE_ACTIVATED);
+
 }
 
 struct ivi_output *
@@ -303,11 +352,43 @@ ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
                                app_id, ivi_layout_get_surface_role_name(surf),
                                ivi_output->area.width, ivi_output->area.height);
 
+               surf->hidden_layer_output = ivi_output;
                weston_view_set_output(ev, ivi_output->output);
                weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
-               weston_log("Placed app_id %s, type %s in hidden layer\n",
-                               app_id, ivi_layout_get_surface_role_name(surf));
+               weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
+                               app_id, ivi_layout_get_surface_role_name(surf),
+                               ivi_output->output->name);
+
+               weston_compositor_schedule_repaint(ivi->compositor);
+               return;
        }
+
+       /* we might have another output to activate */
+       if (surf->hidden_layer_output &&
+           surf->hidden_layer_output != ivi_output) {
+               weston_layer_entry_remove(&ev->layer_link);
+
+               if (ivi_output->area.width != surf->hidden_layer_output->area.width &&
+                   ivi_output->area.height != surf->hidden_layer_output->area.height) {
+                       weston_desktop_surface_set_maximized(dsurf, true);
+                       weston_desktop_surface_set_size(dsurf,
+                                                       ivi_output->area.width,
+                                                       ivi_output->area.height);
+               }
+
+               weston_log("Setting app_id %s, role %s, set to maximized (%dx%d)\n",
+                               app_id, ivi_layout_get_surface_role_name(surf),
+                               ivi_output->area.width, ivi_output->area.height);
+
+               surf->hidden_layer_output = ivi_output;
+               weston_view_set_output(ev, ivi_output->output);
+               weston_layer_entry_insert(&ivi->hidden.view_list, &ev->layer_link);
+               weston_log("Placed app_id %s, type %s in hidden layer on output %s\n",
+                               app_id, ivi_layout_get_surface_role_name(surf),
+                               ivi_output->output->name);
+       }
+
+       weston_compositor_schedule_repaint(ivi->compositor);
 }
 
 void
@@ -351,7 +432,7 @@ ivi_layout_desktop_committed(struct ivi_surface *surf)
                if (r_output) {
                        struct weston_view *view = r_output->fullscreen_view.fs->view;
                        if (view->is_mapped || view->surface->is_mapped)
-                               remove_black_surface(r_output);
+                               remove_black_curtain(r_output);
                }
 
 
@@ -419,9 +500,11 @@ ivi_layout_desktop_committed(struct ivi_surface *surf)
                        return;
 
                if (app_id) {
-                       weston_log("Surface with app_id %s, role %s activating by default\n",
-                                       weston_desktop_surface_get_app_id(surf->dsurface),
-                                       ivi_layout_get_surface_role_name(surf));
+                       weston_log("Surface with app_id %s, role %s activating "
+                                  "by default on output %s\n",
+                                  weston_desktop_surface_get_app_id(surf->dsurface),
+                                  ivi_layout_get_surface_role_name(surf),
+                                  output->output->name);
                        ivi_layout_activate(output, app_id);
                }
                return;
@@ -796,8 +879,8 @@ ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
        }
 
 #ifdef AGL_COMP_DEBUG
-       weston_log("Activating app_id %s, type %s\n", app_id,
-                       ivi_layout_get_surface_role_name(surf));
+       weston_log("Activating app_id %s, type %s, on output %s\n", app_id,
+                       ivi_layout_get_surface_role_name(surf), output->output->name);
 #endif
 
        if (surf->role == IVI_SURFACE_ROLE_POPUP) {
@@ -807,8 +890,11 @@ ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
 
        /* do not 're'-activate surfaces that are split or active */
        if (surf == output->active ||
-           ivi_layout_surface_is_split_or_fullscreen(surf))
+           ivi_layout_surface_is_split_or_fullscreen(surf)) {
+               weston_log("Application %s is already active on output %s\n",
+                               app_id, output->output->name);
                return;
+       }
 
        if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
                struct ivi_output *remote_output =
@@ -951,4 +1037,8 @@ ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
                weston_view_geometry_dirty(view);
                weston_surface_damage(view->surface);
        }
+
+      if (wl_resource_get_version(ivi->shell_client.resource) >= AGL_SHELL_APP_STATE_SINCE_VERSION)
+             agl_shell_send_app_state(ivi->shell_client.resource, app_id,
+                                      AGL_SHELL_APP_STATE_DEACTIVATED);
 }