shell/layout: Add implementation for the width param
[src/agl-compositor.git] / src / layout.c
index a5e3b36..7a2c9ac 100644 (file)
@@ -30,6 +30,7 @@
 #include <assert.h>
 #include <string.h>
 
+#include <libweston/config-parser.h>
 #include <libweston/libweston.h>
 #include <libweston-desktop/libweston-desktop.h>
 
@@ -47,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
@@ -155,6 +157,29 @@ void
 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output)
 {
        bool use_default_area = true;
+       struct weston_config_section *section = output->config;
+       char *t;
+
+       weston_config_section_get_string(section, "activation-area", &t, NULL);
+       if (t) {
+               if (output->area_activation.width == 0 &&
+                   output->area_activation.height == 0 &&
+                   output->area_activation.x == 0 &&
+                   output->area_activation.y == 0) {
+                       weston_log("WARNING: activation-area set in "
+                                       "configuration file, but yet applied!\n");
+                       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);
 
        ivi_background_init(ivi, output);
 
@@ -260,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;
@@ -301,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;
                }
        }
@@ -430,8 +462,10 @@ ivi_layout_add_to_hidden_layer(struct ivi_surface *surf,
        if (surf->hidden_layer_output &&
            surf->hidden_layer_output != ivi_output) {
                weston_layer_entry_remove(&ev->layer_link);
+               weston_view_geometry_dirty(ev);
+               weston_surface_damage(ev->surface);
 
-               if (ivi_output->area.width != surf->hidden_layer_output->area.width &&
+               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,
@@ -555,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 ||
@@ -585,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);
+                               }
                        }
                }
 
@@ -696,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);
        }
 }
 
@@ -940,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)
 {
@@ -963,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)
 {
@@ -993,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);
@@ -1083,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;
        }
 
@@ -1114,7 +1255,8 @@ ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id)
        weston_log("Deactiving %s, role %s\n", app_id,
                        ivi_layout_get_surface_role_name(surf));
 
-       if (surf->role == IVI_SURFACE_ROLE_DESKTOP) {
+       if (surf->role == IVI_SURFACE_ROLE_DESKTOP ||
+           surf->role == IVI_SURFACE_ROLE_REMOTE) {
                struct ivi_surface *previous_active;
 
                previous_active = ivi_output->previous_active;
@@ -1142,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);
@@ -1153,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);
 }