shell: Don't reset the activation area always
[src/agl-compositor.git] / src / shell.c
index db9638f..1aabb5a 100644 (file)
 #include "agl-shell-server-protocol.h"
 #include "agl-shell-desktop-server-protocol.h"
 
-#ifdef HAVE_WALTHAM
-#include <waltham-transmitter/transmitter_api.h>
-#endif
-
 static void
 create_black_curtain_view(struct ivi_output *output);
 
@@ -125,88 +121,6 @@ ivi_set_desktop_surface_fullscreen(struct ivi_surface *surface)
        agl_shell_desktop_advertise_application_id(ivi, surface);
 }
 
-#ifdef HAVE_WALTHAM
-void
-ivi_destroy_waltham_destroy(struct ivi_surface *surface)
-{
-       struct ivi_compositor *ivi = surface->ivi;
-       const struct weston_transmitter_api *api =
-               ivi->waltham_transmitter_api;
-
-       if (!api)
-               return;
-
-       if (surface->waltham_surface.transmitter_surface)
-               api->surface_destroy(surface->waltham_surface.transmitter_surface);
-}
-
-static void
-ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
-{
-       struct ivi_compositor *ivi = surface->ivi;
-       const struct weston_transmitter_api *api = ivi->waltham_transmitter_api;
-       struct weston_transmitter *transmitter;
-       struct weston_transmitter_remote *trans_remote;
-       struct weston_surface *weston_surface;
-       struct weston_output *woutput = surface->remote.output->output;
-       const char *app_id;
-
-       if (!api)
-               return;
-
-       transmitter = api->transmitter_get(ivi->compositor);
-       if (!transmitter)
-               return;
-
-       trans_remote = api->get_transmitter_remote(woutput->name, transmitter);
-       if (!trans_remote) {
-               weston_log("Could not find a valie weston_transmitter_remote "
-                               "that matches the output %s\n", woutput->name);
-               return;
-       }
-
-       app_id = weston_desktop_surface_get_app_id(surface->dsurface);
-       weston_surface =
-               weston_desktop_surface_get_surface(surface->dsurface);
-
-       weston_log("Forwarding app_id %s to remote %s\n", app_id, woutput->name);
-
-       /* this will have the effect of informing the remote side to create a
-        * surface with the name app_id. W/ xdg-shell the following happens:
-        *
-        * compositor (server):
-        * surface_push_to_remote():
-        *      waltham-transmitter plug-in
-        *              -> wthp_ivi_app_id_surface_create()
-        *
-        * client -- on the receiver side:
-        *      -> wthp_ivi_app_id_surface_create()
-        *              -> wth_receiver_weston_main()
-        *                      -> wl_compositor_create_surface()
-        *                      -> xdg_wm_base_get_xdg_surface
-        *                      -> xdg_toplevel_set_app_id()
-        *                      -> gst_init()
-        *                      -> gst_parse_launch()
-        *
-        * wth_receiver_weston_main() will be invoked from the handler of
-        * wthp_ivi_app_id_surface_create() and is responsible for setting-up
-        * the gstreamer pipeline as well.
-        */
-       surface->waltham_surface.transmitter_surface =
-           api->surface_push_to_remote(weston_surface, app_id, trans_remote, NULL);
-}
-
-#else
-void
-ivi_destroy_waltham_destroy(struct ivi_surface *surface)
-{
-}
-static void
-ivi_output_notify_waltham_plugin(struct ivi_surface *surface)
-{
-}
-#endif
-
 static void
 ivi_set_desktop_surface_remote(struct ivi_surface *surface)
 {
@@ -227,9 +141,6 @@ ivi_set_desktop_surface_remote(struct ivi_surface *surface)
        if (view->is_mapped || view->surface->is_mapped)
                remove_black_curtain(output);
 
-       if (output->type == OUTPUT_WALTHAM)
-               ivi_output_notify_waltham_plugin(surface);
-
        wl_list_insert(&ivi->surfaces, &surface->link);
 }
 
@@ -706,7 +617,7 @@ ivi_check_pending_desktop_surface(struct ivi_surface *surface)
        ret = ivi_check_pending_desktop_surface_remote(surface);
        if (ret) {
                ivi_set_desktop_surface_remote(surface);
-               ivi_layout_desktop_committed(surface);
+               ivi_layout_remote_committed(surface);
                return;
        }
 
@@ -1168,6 +1079,23 @@ shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
        }
 }
 
+void
+shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
+                        const char *output_name)
+{
+       if (app_id && ivi->shell_client.resource &&
+           wl_resource_get_version(ivi->shell_client.resource) >=
+           AGL_SHELL_APP_ON_OUTPUT_SINCE_VERSION) {
+
+               agl_shell_send_app_on_output(ivi->shell_client.resource,
+                                        app_id, output_name);
+
+               if (ivi->shell_client.resource_ext)
+                       agl_shell_send_app_on_output(ivi->shell_client.resource_ext,
+                                                app_id, output_name);
+       }
+}
+
 static void
 shell_ready(struct wl_client *client, struct wl_resource *shell_res)
 {
@@ -1685,6 +1613,57 @@ shell_set_activate_region(struct wl_client *client, struct wl_resource *res,
        ioutput->area_activation = area;
 }
 
+static void
+shell_set_app_output(struct wl_client *client, struct wl_resource *res,
+                   const char *app_id, struct wl_resource *output)
+{
+       struct ivi_compositor *ivi = wl_resource_get_user_data(res);
+       struct weston_head *head = weston_head_from_resource(output);
+       struct weston_output *woutput = weston_head_get_output(head);
+       struct ivi_output *ioutput = to_ivi_output(woutput);
+       struct ivi_surface *surf = ivi_find_app(ivi, app_id);
+       struct ivi_output *desktop_last_output = surf->desktop.last_output;
+       struct ivi_output *current_completed_output =
+               surf->current_completed_output;
+
+       if (!app_id || !ioutput)
+               return;
+
+       /* handle the case we're not mapped at all */
+       if (!surf) {
+               ivi_set_pending_desktop_surface_remote(ioutput, app_id);
+               shell_send_app_on_output(ivi, app_id, woutput->name);
+               return;
+       }
+
+       if (surf->remote.output)
+               surf->hidden_layer_output = surf->remote.output;
+       else
+               surf->hidden_layer_output = desktop_last_output;
+       assert(surf->hidden_layer_output);
+
+       if (ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_REMOTE) ||
+           ivi_surface_count_one(current_completed_output, IVI_SURFACE_ROLE_DESKTOP)) {
+               if (!current_completed_output->background)
+                       insert_black_curtain(current_completed_output);
+       } else {
+               ivi_layout_deactivate(ivi, app_id);
+       }
+
+       /* update the remote output */
+       surf->remote.output = ioutput;
+
+       if (surf->role != IVI_SURFACE_ROLE_REMOTE) {
+               wl_list_remove(&surf->link);
+               wl_list_init(&surf->link);
+
+               surf->role = IVI_SURFACE_ROLE_NONE;
+               ivi_set_desktop_surface_remote(surf);
+       }
+
+       shell_send_app_on_output(ivi, app_id, woutput->name);
+}
+
 static void
 shell_ext_destroy(struct wl_client *client, struct wl_resource *res)
 {
@@ -1712,6 +1691,7 @@ static const struct agl_shell_interface agl_shell_implementation = {
        .set_app_float = shell_set_app_float,
        .set_app_normal = shell_set_app_normal,
        .set_app_fullscreen = shell_set_app_fullscreen,
+       .set_app_output = shell_set_app_output,
 };
 
 static const struct agl_shell_ext_interface agl_shell_ext_implementation = {
@@ -1815,18 +1795,20 @@ unbind_agl_shell(struct wl_resource *resource)
        }
 
        wl_list_for_each(output, &ivi->outputs, link) {
-               struct weston_geometry area = {};
 
                /* reset the active surf if there's one present */
                if (output->active) {
+                       struct weston_geometry area = {};
+
                        output->active->view->is_mapped = false;
                        output->active->view->surface->is_mapped = false;
 
                        weston_layer_entry_remove(&output->active->view->layer_link);
                        output->active = NULL;
+
+                       output->area_activation = area;
                }
 
-               output->area_activation = area;
                insert_black_curtain(output);
        }
 
@@ -2011,7 +1993,7 @@ int
 ivi_shell_create_global(struct ivi_compositor *ivi)
 {
        ivi->agl_shell = wl_global_create(ivi->compositor->wl_display,
-                                         &agl_shell_interface, 7,
+                                         &agl_shell_interface, 8,
                                          ivi, bind_agl_shell);
        if (!ivi->agl_shell) {
                weston_log("Failed to create wayland global.\n");