layout: Add missing hooks for other surface roles
[src/agl-compositor.git] / src / layout.c
index ea1e684..fa49163 100644 (file)
@@ -77,10 +77,8 @@ ivi_background_init(struct ivi_compositor *ivi, struct ivi_output *output)
        weston_view_set_output(view, woutput);
        weston_view_set_position(view, woutput->x, woutput->y);
 
-#ifdef AGL_COMP_DEBUG
-       weston_log("(background) position view %p, x %d, y %d\n", view,
-                       woutput->x, woutput->y);
-#endif
+       weston_log("(background) position view %p, x %d, y %d, on output %s\n", view,
+                       woutput->x, woutput->y, output->name);
 
        view->is_mapped = true;
        view->surface->is_mapped = true;
@@ -106,10 +104,10 @@ ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
        dsurface = panel->dsurface;
        view = panel->view;
        geom = weston_desktop_surface_get_geometry(dsurface);
-#ifdef AGL_COMP_DEBUG
+
        weston_log("(panel) geom.width %d, geom.height %d, geom.x %d, geom.y %d\n",
                        geom.width, geom.height, geom.x, geom.y);
-#endif
+
        switch (panel->panel.edge) {
        case AGL_SHELL_EDGE_TOP:
                output->area.y += geom.height;
@@ -134,33 +132,16 @@ ivi_panel_init(struct ivi_compositor *ivi, struct ivi_output *output,
 
        weston_view_set_output(view, woutput);
        weston_view_set_position(view, x, y);
-#ifdef AGL_COMP_DEBUG
+
        weston_log("(panel) edge %d position view %p, x %d, y %d\n",
                        panel->panel.edge, view, x, y);
-#endif
-
-       /* this is necessary for cases we already mapped it desktop_committed()
-        * but we not running the older qtwayland, so we still have a chance
-        * for this to run at the next test */
-       if (view->surface->is_mapped) {
-               weston_layer_entry_remove(&view->layer_link);
-
-               view->is_mapped = false;
-               view->surface->is_mapped = false;
-       }
-
-       /* give ivi_layout_panel_committed() a chance to map the view/surface
-        * instead */
-       if ((geom.width == geom.height && geom.width == 0) &&
-           (geom.x == geom.y && geom.x == 0) &&
-           panel->panel.edge != AGL_SHELL_EDGE_TOP)
-               return;
 
        view->is_mapped = true;
        view->surface->is_mapped = true;
-#ifdef AGL_COMP_DEBUG
-       weston_log("panel type %d inited\n", panel->panel.edge);
-#endif
+
+       weston_log("panel type %d inited on output %s\n", panel->panel.edge,
+                       output->name);
+
        weston_layer_entry_insert(&ivi->panel.view_list, &view->layer_link);
 }
 
@@ -250,13 +231,13 @@ ivi_layout_activate_complete(struct ivi_output *output,
                surf->desktop.pending_output = NULL;
        }
 
-       weston_log("Activation completed for app_id %s, role %s\n",
+       weston_log("Activation completed for app_id %s, role %s, output %s\n",
                        weston_desktop_surface_get_app_id(surf->dsurface),
-                       ivi_layout_get_surface_role_name(surf));
+                       ivi_layout_get_surface_role_name(surf), output->name);
 }
 
-static struct ivi_output *
-ivi_layout_find_app_id(const char *app_id, struct ivi_compositor *ivi)
+struct ivi_output *
+ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi)
 {
        struct ivi_output *out;
 
@@ -322,7 +303,7 @@ ivi_layout_desktop_committed(struct ivi_surface *surf)
                        return;
 
                /* check first if there aren't any outputs being set */
-               r_output = ivi_layout_find_app_id(app_id, surf->ivi);
+               r_output = ivi_layout_find_with_app_id(app_id, surf->ivi);
 
                if (r_output) {
                        struct weston_view *view = r_output->fullscreen_view.fs->view;
@@ -385,10 +366,12 @@ void
 ivi_layout_fullscreen_committed(struct ivi_surface *surface)
 {
        struct ivi_compositor *ivi = surface->ivi;
+       struct ivi_policy *policy = ivi->policy;
 
        struct weston_desktop_surface *dsurface = surface->dsurface;
        struct weston_surface *wsurface =
                weston_desktop_surface_get_surface(dsurface);
+       const char *app_id = weston_desktop_surface_get_app_id(dsurface);
 
        struct ivi_output *output = surface->split.output;
        struct weston_output *woutput = output->output;
@@ -396,6 +379,11 @@ ivi_layout_fullscreen_committed(struct ivi_surface *surface)
        struct weston_view *view = surface->view;
        struct weston_geometry geom;
 
+       if (policy && policy->api.surface_activate_by_default &&
+           !policy->api.surface_activate_by_default(surface, surface->ivi) &&
+           !surface->activated_by_default)
+               return;
+
        if (surface->view->is_mapped)
                return;
 
@@ -416,6 +404,12 @@ ivi_layout_fullscreen_committed(struct ivi_surface *surface)
 
        wsurface->is_mapped = true;
        surface->view->is_mapped = true;
+
+       shell_advertise_app_state(ivi, app_id,
+                                 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
+
+       weston_log("Activation completed for app_id %s, role %s, output %s\n",
+                       app_id, ivi_layout_get_surface_role_name(surface), output->name);
 }
 
 void
@@ -442,10 +436,12 @@ void
 ivi_layout_split_committed(struct ivi_surface *surface)
 {
        struct ivi_compositor *ivi = surface->ivi;
+       struct ivi_policy *policy = ivi->policy;
 
        struct weston_desktop_surface *dsurface = surface->dsurface;
        struct weston_surface *wsurface =
                weston_desktop_surface_get_surface(dsurface);
+       const char *app_id = weston_desktop_surface_get_app_id(dsurface);
 
        struct ivi_output *output = surface->split.output;
        struct weston_output *woutput = output->output;
@@ -459,6 +455,11 @@ ivi_layout_split_committed(struct ivi_surface *surface)
        x = woutput->x;
        y = woutput->y;
 
+       if (policy && policy->api.surface_activate_by_default &&
+           !policy->api.surface_activate_by_default(surface, surface->ivi) &&
+           !surface->activated_by_default)
+               return;
+
        if (surface->view->is_mapped)
                return;
 
@@ -521,37 +522,50 @@ ivi_layout_split_committed(struct ivi_surface *surface)
 
        wsurface->is_mapped = true;
        surface->view->is_mapped = true;
+
+       shell_advertise_app_state(ivi, app_id,
+                                 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
+
+       weston_log("Activation completed for app_id %s, role %s, output %s\n",
+                       app_id, ivi_layout_get_surface_role_name(surface), output->name);
 }
 
 void
 ivi_layout_popup_committed(struct ivi_surface *surface)
 {
        struct ivi_compositor *ivi = surface->ivi;
+       struct ivi_policy *policy = ivi->policy;
 
        struct weston_desktop_surface *dsurface = surface->dsurface;
        struct weston_surface *wsurface =
                weston_desktop_surface_get_surface(dsurface);
+       const char *app_id = weston_desktop_surface_get_app_id(dsurface);
 
        struct ivi_output *output = surface->popup.output;
        struct weston_output *woutput = output->output;
 
        struct weston_view *view = surface->view;
-       struct weston_geometry geom;
 
-       if (surface->view->is_mapped)
+       if (policy && policy->api.surface_activate_by_default &&
+           !policy->api.surface_activate_by_default(surface, surface->ivi) &&
+           !surface->activated_by_default)
                return;
 
-       geom = weston_desktop_surface_get_geometry(dsurface);
-       weston_log("(popup) geom x %d, y %d, width %d, height %d\n", geom.x, geom.y,
-                       geom.width, geom.height);
+       if (surface->view->is_mapped)
+               return;
 
        assert(surface->role == IVI_SURFACE_ROLE_POPUP);
 
        weston_view_set_output(view, woutput);
-       if (surface->popup.x || surface->popup.y)
-               weston_view_set_position(view, surface->popup.x, surface->popup.y);
-       else
-               weston_view_set_position(view, geom.x, geom.y);
+       weston_view_set_position(view, surface->popup.x, surface->popup.y);
+
+       /* only clip the pop-up dialog window if we have a valid
+        * width and height being passed on. Users might not want to have one
+        * set-up so only enfore it is really passed on. */
+       if (surface->popup.bb.width > 0 && surface->popup.bb.height > 0)
+               weston_view_set_mask(view, surface->popup.bb.x, surface->popup.bb.y,
+                                    surface->popup.bb.width, surface->popup.bb.height);
+
        weston_layer_entry_insert(&ivi->popup.view_list, &view->layer_link);
 
        weston_view_update_transform(view);
@@ -559,6 +573,12 @@ ivi_layout_popup_committed(struct ivi_surface *surface)
 
        wsurface->is_mapped = true;
        surface->view->is_mapped = true;
+
+       shell_advertise_app_state(ivi, app_id,
+                                 NULL, AGL_SHELL_DESKTOP_APP_STATE_ACTIVATED);
+
+       weston_log("Activation completed for app_id %s, role %s, output %s\n",
+                       app_id, ivi_layout_get_surface_role_name(surface), output->name);
 }
 
 static void
@@ -578,6 +598,11 @@ ivi_layout_popup_re_add(struct ivi_surface *surface)
                view->is_mapped = false;
        }
 
+       /* reset the activate by default in order to (still) allow the surface
+        * to be activaved using the request */
+       if (!surface->activated_by_default)
+               surface->activated_by_default = true;
+
        ivi_layout_popup_committed(surface);
 }
 
@@ -592,6 +617,11 @@ ivi_layout_surface_is_split_or_fullscreen(struct ivi_surface *surf)
            surf->role != IVI_SURFACE_ROLE_FULLSCREEN)
                return false;
 
+       /* reset the activate by default in order to (still) allow the surface
+        * to be activaved using the request */
+       if (!surf->activated_by_default)
+               surf->activated_by_default = true;
+
        wl_list_for_each(is, &ivi->surfaces, link)
                if (is == surf)
                        return true;
@@ -633,6 +663,16 @@ ivi_layout_activate(struct ivi_output *output, const char *app_id)
            ivi_layout_surface_is_split_or_fullscreen(surf))
                return;
 
+       if (surf->role == IVI_SURFACE_ROLE_REMOTE) {
+               struct ivi_output *remote_output =
+                       ivi_layout_find_with_app_id(app_id, ivi);
+
+               /* if already active on a remote output do not
+                * attempt to activate it again */
+               if (remote_output && remote_output->active == surf)
+                       return;
+       }
+
 
        dsurf = surf->dsurface;
        view = surf->view;