From 8d5e627bc98f376f84e7f5b0a7caed791351c577 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Aug 2019 18:30:09 +0900 Subject: Implement wlr-foreign-toplevel-management-v1 --- sway/tree/container.c | 8 ++++++++ sway/tree/view.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'sway/tree') diff --git a/sway/tree/container.c b/sway/tree/container.c index 2fbd0d38..4cc42747 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1168,6 +1168,10 @@ void container_discover_outputs(struct sway_container *con) { if (con->view) { view_for_each_surface(con->view, surface_send_enter_iterator, output->wlr_output); + if (con->view->foreign_toplevel) { + wlr_foreign_toplevel_handle_v1_output_enter( + con->view->foreign_toplevel, output->wlr_output); + } } list_add(con->outputs, output); } else if (!intersects && index != -1) { @@ -1176,6 +1180,10 @@ void container_discover_outputs(struct sway_container *con) { if (con->view) { view_for_each_surface(con->view, surface_send_leave_iterator, output->wlr_output); + if (con->view->foreign_toplevel) { + wlr_foreign_toplevel_handle_v1_output_leave( + con->view->foreign_toplevel, output->wlr_output); + } } list_del(con->outputs, index); } diff --git a/sway/tree/view.c b/sway/tree/view.c index e5d3948c..6dccaa2e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -22,6 +22,7 @@ #include "sway/ipc-server.h" #include "sway/output.h" #include "sway/input/seat.h" +#include "sway/server.h" #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/view.h" @@ -329,6 +330,10 @@ void view_set_activated(struct sway_view *view, bool activated) { if (view->impl->set_activated) { view->impl->set_activated(view, activated); } + if (view->foreign_toplevel) { + wlr_foreign_toplevel_handle_v1_set_activated( + view->foreign_toplevel, activated); + } } void view_request_activate(struct sway_view *view) { @@ -589,6 +594,27 @@ static bool should_focus(struct sway_view *view) { return len == 0; } +static void handle_foreign_activate_request( + struct wl_listener *listener, void *data) { + struct sway_view *view = wl_container_of( + listener, view, foreign_activate_request); + struct wlr_foreign_toplevel_handle_v1_activated_event *event = data; + struct sway_seat *seat; + wl_list_for_each(seat, &server.input->seats, link) { + if (seat->wlr_seat == event->seat) { + seat_set_focus_container(seat, view->container); + break; + } + } +} + +static void handle_foreign_close_request( + struct wl_listener *listener, void *data) { + struct sway_view *view = wl_container_of( + listener, view, foreign_close_request); + view_close(view); +} + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, bool fullscreen, struct wlr_output *fullscreen_output, bool decoration) { @@ -617,6 +643,15 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, struct sway_container *target_sibling = node->type == N_CONTAINER ? node->sway_container : NULL; + view->foreign_toplevel = + wlr_foreign_toplevel_handle_v1_create(server.foreign_toplevel_manager); + view->foreign_activate_request.notify = handle_foreign_activate_request; + wl_signal_add(&view->foreign_toplevel->events.request_activate, + &view->foreign_activate_request); + view->foreign_close_request.notify = handle_foreign_close_request; + wl_signal_add(&view->foreign_toplevel->events.request_close, + &view->foreign_close_request); + // If we're about to launch the view into the floating container, then // launch it as a tiled view in the root of the workspace instead. if (target_sibling && container_is_floating(target_sibling)) { @@ -679,6 +714,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, if (should_focus(view)) { input_manager_set_focus(&view->container->node); } + + const char *app_id = view_get_app_id(view); + if (app_id != NULL) { + wlr_foreign_toplevel_handle_v1_set_app_id( + view->foreign_toplevel, app_id); + } } void view_unmap(struct sway_view *view) { @@ -691,6 +732,11 @@ void view_unmap(struct sway_view *view) { view->urgent_timer = NULL; } + if (view->foreign_toplevel) { + wlr_foreign_toplevel_handle_v1_destroy(view->foreign_toplevel); + view->foreign_toplevel = NULL; + } + struct sway_container *parent = view->container->parent; struct sway_workspace *ws = view->container->workspace; container_begin_destroy(view->container); @@ -1097,6 +1143,10 @@ void view_update_title(struct sway_view *view, bool force) { container_update_title_textures(view->container); ipc_event_window(view->container, "title"); + + if (view->foreign_toplevel) { + wlr_foreign_toplevel_handle_v1_set_title(view->foreign_toplevel, title); + } } bool view_is_visible(struct sway_view *view) { -- cgit v1.2.3