Skip to content

Commit

Permalink
Implement wlr-foreign-toplevel-management-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevault committed Aug 21, 2019
1 parent ff7d979 commit b2c22ef
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_presentation_time.h>
Expand Down Expand Up @@ -69,6 +70,8 @@ struct sway_server {
struct wl_listener output_manager_apply;
struct wl_listener output_manager_test;

struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;

size_t txn_timeout_ms;
list_t *transactions;
list_t *dirty_nodes;
Expand Down
4 changes: 4 additions & 0 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ struct sway_view {
// when a transaction is applied.
struct wlr_box saved_geometry;

struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel;
struct wl_listener foreign_activate_request;
struct wl_listener foreign_close_request;

bool destroying;

list_t *executed_criteria; // struct criteria *
Expand Down
3 changes: 3 additions & 0 deletions sway/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ bool server_init(struct sway_server *server) {
wl_signal_add(&server->output_manager_v1->events.test,
&server->output_manager_test);

server->foreign_toplevel_manager =
wlr_foreign_toplevel_manager_v1_create(server->wl_display);

wlr_export_dmabuf_manager_v1_create(server->wl_display);
wlr_screencopy_manager_v1_create(server->wl_display);
wlr_data_control_manager_v1_create(server->wl_display);
Expand Down
8 changes: 8 additions & 0 deletions sway/tree/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,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) {
Expand All @@ -1139,6 +1143,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);
}
Expand Down
50 changes: 50 additions & 0 deletions sway/tree/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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"
Expand Down Expand Up @@ -299,6 +300,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) {
Expand Down Expand Up @@ -556,6 +561,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) {
Expand All @@ -582,6 +608,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)) {
Expand Down Expand Up @@ -645,6 +680,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) {
Expand All @@ -657,6 +698,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);
Expand Down Expand Up @@ -1060,6 +1106,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) {
Expand Down

0 comments on commit b2c22ef

Please sign in to comment.