shell: Reset the area activation
[src/agl-compositor.git] / src / shell.c
index 4f33103..640cc73 100644 (file)
@@ -802,7 +802,8 @@ ivi_shell_finalize(struct ivi_compositor *ivi)
        weston_layer_fini(&ivi->popup);
 
        wl_list_for_each(output, &ivi->outputs, link) {
-               if (output->fullscreen_view.fs->view) {
+               if (output->fullscreen_view.fs &&
+                   output->fullscreen_view.fs->view) {
                        weston_surface_destroy(output->fullscreen_view.fs->view->surface);
                        output->fullscreen_view.fs->view = NULL;
                }
@@ -1097,9 +1098,10 @@ remove_black_curtain(struct ivi_output *output)
 {
        struct weston_view *view;
 
-       if (!output &&
+       if ((!output &&
            !output->fullscreen_view.fs &&
-           !output->fullscreen_view.fs->view) {
+           !output->fullscreen_view.fs->view) ||
+           !output->fullscreen_view.fs) {
                weston_log("Output %s doesn't have a surface installed!\n", output->name);
                return;
        }
@@ -1126,7 +1128,8 @@ insert_black_curtain(struct ivi_output *output)
 
        if ((!output &&
            !output->fullscreen_view.fs &&
-           !output->fullscreen_view.fs->view) || !output->output) {
+           !output->fullscreen_view.fs->view) || !output->output ||
+           !output->fullscreen_view.fs) {
                weston_log("Output %s doesn't have a surface installed!\n", output->name);
                return;
        }
@@ -1171,7 +1174,8 @@ shell_ready(struct wl_client *client, struct wl_resource *shell_res)
        struct ivi_output *output;
        struct ivi_surface *surface, *tmp;
 
-       if (ivi->shell_client.resource &&
+       if (wl_resource_get_version(shell_res) >=
+           AGL_SHELL_BOUND_OK_SINCE_VERSION &&
            ivi->shell_client.status == BOUND_FAILED) {
                wl_resource_post_error(shell_res,
                                       WL_DISPLAY_ERROR_INVALID_OBJECT,
@@ -1226,9 +1230,10 @@ shell_set_background(struct wl_client *client,
        struct weston_desktop_surface *dsurface;
        struct ivi_surface *surface;
 
-       if ((ivi->shell_client.resource &&
-            ivi->shell_client.status == BOUND_FAILED) ||
-            ivi->shell_client.resource_ext == shell_res) {
+       if ((wl_resource_get_version(shell_res) >=
+           AGL_SHELL_BOUND_OK_SINCE_VERSION &&
+           ivi->shell_client.status == BOUND_FAILED) ||
+           ivi->shell_client.resource_ext == shell_res) {
                wl_resource_post_error(shell_res,
                                       WL_DISPLAY_ERROR_INVALID_OBJECT,
                                       "agl_shell has already been bound. "
@@ -1290,8 +1295,9 @@ shell_set_panel(struct wl_client *client,
        struct ivi_surface **member;
        int32_t width = 0, height = 0;
 
-       if ((ivi->shell_client.resource &&
-           ivi->shell_client.status == BOUND_FAILED) ||
+       if ((wl_resource_get_version(shell_res) >=
+            AGL_SHELL_BOUND_OK_SINCE_VERSION &&
+            ivi->shell_client.status == BOUND_FAILED) ||
            ivi->shell_client.resource_ext == shell_res) {
                wl_resource_post_error(shell_res,
                                       WL_DISPLAY_ERROR_INVALID_OBJECT,
@@ -1408,7 +1414,8 @@ shell_activate_app(struct wl_client *client,
        struct ivi_compositor *ivi = wl_resource_get_user_data(shell_res);
        struct ivi_output *output = to_ivi_output(woutput);
 
-       if (ivi->shell_client.resource &&
+       if (wl_resource_get_version(shell_res) >=
+           AGL_SHELL_BOUND_OK_SINCE_VERSION &&
            ivi->shell_client.status == BOUND_FAILED) {
                wl_resource_post_error(shell_res,
                                       WL_DISPLAY_ERROR_INVALID_OBJECT,
@@ -1448,10 +1455,15 @@ shell_deactivate_app(struct wl_client *client,
                                  NULL, AGL_SHELL_DESKTOP_APP_STATE_DEACTIVATED);
 }
 
-/* stub, no usage for the time being */
 static void
 shell_destroy(struct wl_client *client, struct wl_resource *res)
 {
+       struct  ivi_compositor *ivi = wl_resource_get_user_data(res);
+
+       /* reset status in case bind_fail was sent */
+       if (wl_resource_get_version(res) >= AGL_SHELL_BOUND_OK_SINCE_VERSION &&
+           ivi->shell_client.status == BOUND_FAILED)
+               ivi->shell_client.status = BOUND_OK;
 }
 
 static void
@@ -1591,13 +1603,16 @@ unbind_agl_shell(struct wl_resource *resource)
        ivi = wl_resource_get_user_data(resource);
 
        /* reset status to allow other clients issue legit requests */
-       if (ivi->shell_client.resource &&
+       if (wl_resource_get_version(resource) >=
+           AGL_SHELL_BOUND_OK_SINCE_VERSION &&
            ivi->shell_client.status == BOUND_FAILED) {
                ivi->shell_client.status = BOUND_OK;
                return;
        }
 
        wl_list_for_each(output, &ivi->outputs, link) {
+               struct weston_geometry area = {};
+
                /* reset the active surf if there's one present */
                if (output->active) {
                        output->active->view->is_mapped = false;
@@ -1607,6 +1622,7 @@ unbind_agl_shell(struct wl_resource *resource)
                        output->active = NULL;
                }
 
+               output->area_activation = area;
                insert_black_curtain(output);
        }
 
@@ -1670,31 +1686,45 @@ bind_agl_shell(struct wl_client *client,
                if (ivi->shell_client_ext.resource && 
                    ivi->shell_client_ext.doas_requested) {
 
+                       /* reset status in case client-ext doesn't send an
+                        * explicit agl_shell_destroy request, see
+                        * shell_destroy() */
+                       if (ivi->shell_client.status == BOUND_FAILED)
+                               ivi->shell_client.status = BOUND_OK;
+
                        wl_resource_set_implementation(resource, &agl_shell_implementation,
                                                       ivi, NULL);
                        ivi->shell_client.resource_ext = resource;
 
-                       if (ivi->shell_client.status == BOUND_OK &&
-                           wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION) {
-                               ivi->shell_client_ext.status = BOUND_OK;
-                               agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
-                               weston_log("agl_shell_send_bound_ok to client ext\n");
-                       }
+                       ivi->shell_client_ext.status = BOUND_OK;
+                       agl_shell_send_bound_ok(ivi->shell_client.resource_ext);
 
                        return;
                } else {
+                       wl_resource_set_implementation(resource, &agl_shell_implementation,
+                                                      ivi, NULL);
                        agl_shell_send_bound_fail(resource);
                        ivi->shell_client.status = BOUND_FAILED;
+                       return;
                }
        }
 
-       wl_resource_set_implementation(resource, &agl_shell_implementation,
-                                      ivi, unbind_agl_shell);
-       ivi->shell_client.resource = resource;
 
-       if (ivi->shell_client.status == BOUND_OK &&
-           wl_resource_get_version(resource) >= AGL_SHELL_BOUND_OK_SINCE_VERSION)
+       if (wl_resource_get_version(resource) >=
+           AGL_SHELL_BOUND_OK_SINCE_VERSION) {
+               wl_resource_set_implementation(resource, &agl_shell_implementation,
+                                              ivi, unbind_agl_shell);
+               ivi->shell_client.resource = resource;
+               /* if we land here we'll have BOUND_OK by default,
+                  but still do the assignment */
+               ivi->shell_client.status = BOUND_OK;
                agl_shell_send_bound_ok(ivi->shell_client.resource);
+       } else {
+               /* fallback for just version 1 of the protocol */
+               wl_resource_set_implementation(resource, &agl_shell_implementation,
+                                              ivi, unbind_agl_shell);
+               ivi->shell_client.resource = resource;
+       }
 }
 
 static void