shell/layout: Add implementation for the width param
[src/agl-compositor.git] / src / layout.c
index 8c8b4be..7a2c9ac 100644 (file)
@@ -48,6 +48,7 @@ static const char *ivi_roles_as_string[] = {
        [IVI_SURFACE_ROLE_SPLIT_V]      = "SPLIT_V",
        [IVI_SURFACE_ROLE_FULLSCREEN]   = "FULLSCREEN",
        [IVI_SURFACE_ROLE_REMOTE]       = "REMOTE",
+       [IVI_SURFACE_ROLE_TILE]         = "SPLIT",
 };
 
 bool
@@ -170,6 +171,12 @@ ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
                        if (parse_activation_area(t, output) < 0)
                                weston_log("Invalid activation-area \"%s\" for output %s\n",
                                           t, output->name);
+               } else {
+                       weston_log("WARNING: activation-area detected in ini file, "
+                                       "but agl_shell override detected!\n");
+                       if (parse_activation_area(t, output) < 0)
+                               weston_log("Invalid activation-area \"%s\" for output %s\n",
+                                          t, output->name);
                }
        }
        free(t);
@@ -278,6 +285,13 @@ ivi_layout_activate_complete(struct ivi_output *output,
                                         woutput->x + output->area.x,
                                         woutput->y + output->area.y);
 
+       /* reset any previous orientation */
+       if (surf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
+               weston_log("%s() resetting itself to none orientation\n", __func__);
+               surf->orientation = AGL_SHELL_TILE_ORIENTATION_NONE;
+               weston_desktop_surface_set_orientation(surf->dsurface,
+                                                      surf->orientation);
+       }
        view->is_mapped = true;
        surf->mapped = true;
        view->surface->is_mapped = true;
@@ -319,7 +333,7 @@ ivi_layout_activate_complete(struct ivi_output *output,
                 * we're trying to complete activation with means we're
                 * operating on the same app_id so do update previous_active as
                 * it will overwrite it with the same value */
-               if (!strcmp(c_app_id, app_id)) {
+               if (app_id && !strcmp(c_app_id, app_id)) {
                        update_previous = false;
                }
        }
@@ -575,9 +589,12 @@ ivi_layout_desktop_committed(struct ivi_surface *surf)
                        return;
                }
 
-               if (!surf->ivi->activate_by_default) {
-                       weston_log("Refusing to activate surface role %d, app_id %s\n",
-                                       surf->role, app_id);
+               if (!surf->ivi->activate_by_default &&
+                   (!surf->xwayland.is_set && !is_shell_surface_xwayland(surf))) {
+                       weston_log("Refusing to activate surface role %d, app_id %s, type %s\n",
+                                       surf->role, app_id,
+                                       is_shell_surface_xwayland(surf) ?
+                                       "xwayland" : "regular");
 
                        if (!weston_desktop_surface_get_maximized(dsurf) ||
                            geom.width != r_output->area.width ||
@@ -605,7 +622,12 @@ ivi_layout_desktop_committed(struct ivi_surface *surf)
                                 */
                                weston_log("Surface no app_id, role %s activating by default\n",
                                        ivi_layout_get_surface_role_name(surf));
-                               ivi_layout_activate_by_surf(r_output, surf);
+                               if (surf->xwayland.is_set || is_shell_surface_xwayland(surf)) {
+                                       ivi_layout_activate_by_surf(r_output, surf);
+                                       ivi_layout_activate_complete(r_output, surf);
+                               } else {
+                                       ivi_layout_activate_by_surf(r_output, surf);
+                               }
                        }
                }
 
@@ -716,6 +738,7 @@ ivi_layout_fullscreen_committed(struct ivi_surface *surface)
                           ivi_layout_get_surface_role_name(surface),
                           output->name);
 
+               weston_compositor_schedule_repaint(ivi->compositor);
        }
 }
 
@@ -960,6 +983,32 @@ ivi_layout_popup_re_add(struct ivi_surface *surface)
        ivi_layout_popup_committed(surface);
 }
 
+static void
+ivi_layout_fullscreen_re_add(struct ivi_surface *surface)
+{
+       assert(surface->role == IVI_SURFACE_ROLE_FULLSCREEN);
+       struct weston_view *view = surface->view;
+
+       if (weston_view_is_mapped(view)) {
+               struct weston_desktop_surface *dsurface = surface->dsurface;
+               struct weston_surface *wsurface =
+                       weston_desktop_surface_get_surface(dsurface);
+
+               weston_layer_entry_remove(&view->layer_link);
+
+               wsurface->is_mapped = false;
+               view->is_mapped = false;
+       }
+
+       /* reset the activate by default in order to (still) allow the surface
+        * to be activaved using the request */
+       if (!surface->mapped)
+               surface->mapped = true;
+
+       surface->state = NORMAL;
+       ivi_layout_fullscreen_committed(surface);
+}
+
 static bool
 ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
 {
@@ -983,6 +1032,53 @@ ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
        return false;
 }
 
+void
+ivi_layout_reset_split_surfaces(struct ivi_compositor *ivi)
+{
+       struct ivi_surface *ivisurf;
+       bool found_split_surface = false;
+       struct ivi_output *output = NULL;
+
+       wl_list_for_each(ivisurf, &ivi->surfaces, link) {
+               if (ivisurf->orientation != AGL_SHELL_TILE_ORIENTATION_NONE) {
+                       found_split_surface = true;
+                       break;
+               }
+       }
+
+       if (!found_split_surface)
+               return;
+
+       output = ivisurf->current_completed_output;
+       if (output->previous_active && output->background != output->previous_active) {
+               struct weston_view *ev = output->previous_active->view;
+               struct weston_output *woutput = output->output;
+
+               if (!weston_view_is_mapped(ev))
+                       weston_view_update_transform(ev);
+               else
+                       weston_layer_entry_remove(&ev->layer_link);
+
+               ev->is_mapped = true;
+               ev->surface->is_mapped = true;
+               output->previous_active->mapped = true;
+
+               weston_view_set_output(ev, woutput);
+
+               weston_layer_entry_insert(&ivi->normal.view_list, &ev->layer_link);
+
+               _ivi_set_shell_surface_split(output->previous_active, NULL, 0,
+                                            AGL_SHELL_TILE_ORIENTATION_NONE, false);
+
+               if (output->active == ivisurf) {
+                       output->active = output->previous_active;
+               }
+       }
+
+       _ivi_set_shell_surface_split(ivisurf, NULL, 0,
+                                    AGL_SHELL_TILE_ORIENTATION_NONE, false);
+}
+
 void
 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
 {
@@ -1013,14 +1109,34 @@ ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf)
                return;
        }
 
+       if (surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
+               ivi_layout_fullscreen_re_add(surf);
+               return;
+       }
+#if 0
+       /* reset tile to desktop to allow to resize correctly */
+       if (surf->role == IVI_SURFACE_ROLE_TILE && output->active == surf) {
+               weston_log("%s() resetting tile role!\n", __func__);
+               surf->role = IVI_SURFACE_ROLE_DESKTOP;
+       }
+#endif
+
        /* do not 're'-activate surfaces that are split or active */
-       if (surf == output->active ||
-           ivi_layout_surface_is_split_or_fullscreen(surf)) {
+       if (surf == output->active) {
                weston_log("Application %s is already active on output %s\n",
                                app_id, output->output->name);
                return;
        }
 
+       if (ivi_layout_surface_is_split_or_fullscreen(surf)) {
+               weston_log("Application %s is fullscreen or split on output %s\n",
+                               app_id, output->output->name);
+               return;
+       }
+
+       // destroy any split types to allow correct re-activation
+       ivi_layout_reset_split_surfaces(surf->ivi);
+
        if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
                struct ivi_output *remote_output =
                        ivi_layout_find_with_app_id(app_id, ivi);
@@ -1103,8 +1219,13 @@ ivi_layout_get_output_from_surface(struct ivi_surface *surf)
        case IVI_SURFACE_ROLE_REMOTE:
                ivi_output = surf->remote.output;
                break;
+       case IVI_SURFACE_ROLE_TILE:
+               ivi_output = surf->current_completed_output;
+               break;
        case IVI_SURFACE_ROLE_NONE:
        default:
+               if (surf->view->output)
+                       return to_ivi_output(surf->view->output);
                break;
        }
 
@@ -1163,7 +1284,8 @@ ivi_layout_deactivate(struct ivi_compositor *ivi, const char *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) {
+       } else if (surf->role == IVI_SURFACE_ROLE_POPUP ||
+                  surf->role == IVI_SURFACE_ROLE_FULLSCREEN) {
                struct weston_view *view  = surf->view;
 
                weston_view_unmap(view);
@@ -1174,5 +1296,5 @@ ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
                weston_surface_damage(view->surface);
        }
 
-      shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);
+       shell_send_app_state(ivi, app_id, AGL_SHELL_APP_STATE_DEACTIVATED);
 }