| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
#include "foreign-toplevel/ext-foreign.h" |
| 3 |
#include <assert.h> |
| 4 |
#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h> |
| 5 |
#include "common/macros.h" |
| 6 |
#include "labwc.h" |
| 7 |
#include "view.h" |
| 8 |
|
| 9 |
/* ext signals */ |
| 10 |
static void |
| 11 |
handle_handle_destroy(struct wl_listener *listener, void *data) |
| 12 |
{ |
| 13 |
struct ext_foreign_toplevel *ext_toplevel = |
| 14 |
wl_container_of(listener, ext_toplevel, on.handle_destroy); |
| 15 |
|
| 16 |
/* Client side requests */ |
| 17 |
wl_list_remove(&ext_toplevel->on.handle_destroy.link); |
| 18 |
|
| 19 |
/* Compositor side state changes */ |
| 20 |
wl_list_remove(&ext_toplevel->on_view.new_app_id.link); |
| 21 |
wl_list_remove(&ext_toplevel->on_view.new_title.link); |
| 22 |
|
| 23 |
ext_toplevel->handle = NULL; |
| 24 |
} |
| 25 |
|
| 26 |
/* Compositor signals */ |
| 27 |
static void |
| 28 |
handle_new_app_id(struct wl_listener *listener, void *data) |
| 29 |
{ |
| 30 |
struct ext_foreign_toplevel *ext_toplevel = |
| 31 |
wl_container_of(listener, ext_toplevel, on_view.new_app_id); |
| 32 |
assert(ext_toplevel->handle); |
| 33 |
|
| 34 |
struct wlr_ext_foreign_toplevel_handle_v1_state state = { |
| 35 |
.title = ext_toplevel->view->title, |
| 36 |
.app_id = ext_toplevel->view->app_id, |
| 37 |
}; |
| 38 |
wlr_ext_foreign_toplevel_handle_v1_update_state(ext_toplevel->handle, |
| 39 |
&state); |
| 40 |
} |
| 41 |
|
| 42 |
static void |
| 43 |
handle_new_title(struct wl_listener *listener, void *data) |
| 44 |
{ |
| 45 |
struct ext_foreign_toplevel *ext_toplevel = |
| 46 |
wl_container_of(listener, ext_toplevel, on_view.new_title); |
| 47 |
assert(ext_toplevel->handle); |
| 48 |
|
| 49 |
struct wlr_ext_foreign_toplevel_handle_v1_state state = { |
| 50 |
.title = ext_toplevel->view->title, |
| 51 |
.app_id = ext_toplevel->view->app_id, |
| 52 |
}; |
| 53 |
wlr_ext_foreign_toplevel_handle_v1_update_state(ext_toplevel->handle, |
| 54 |
&state); |
| 55 |
} |
| 56 |
|
| 57 |
/* Internal API */ |
| 58 |
void |
| 59 |
ext_foreign_toplevel_init(struct ext_foreign_toplevel *ext_toplevel, |
| 60 |
struct view *view) |
| 61 |
{ |
| 62 |
assert(server.foreign_toplevel_list); |
| 63 |
ext_toplevel->view = view; |
| 64 |
|
| 65 |
struct wlr_ext_foreign_toplevel_handle_v1_state state = { |
| 66 |
.title = view->title, |
| 67 |
.app_id = view->app_id, |
| 68 |
}; |
| 69 |
ext_toplevel->handle = wlr_ext_foreign_toplevel_handle_v1_create( |
| 70 |
server.foreign_toplevel_list, &state); |
| 71 |
|
| 72 |
if (!ext_toplevel->handle) { |
| 73 |
wlr_log(WLR_ERROR, "cannot create ext toplevel handle for (%s)", |
| 74 |
view->title); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
/* In support for ext-toplevel-capture */ |
| 79 |
ext_toplevel->handle->data = view; |
| 80 |
|
| 81 |
/* Client side requests */ |
| 82 |
ext_toplevel->on.handle_destroy.notify = handle_handle_destroy; |
| 83 |
wl_signal_add(&ext_toplevel->handle->events.destroy, &ext_toplevel->on.handle_destroy); |
| 84 |
|
| 85 |
/* Compositor side state changes */ |
| 86 |
CONNECT_SIGNAL(view, &ext_toplevel->on_view, new_app_id); |
| 87 |
CONNECT_SIGNAL(view, &ext_toplevel->on_view, new_title); |
| 88 |
} |
| 89 |
|
| 90 |
void |
| 91 |
ext_foreign_toplevel_finish(struct ext_foreign_toplevel *ext_toplevel) |
| 92 |
{ |
| 93 |
if (!ext_toplevel->handle) { |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
/* invokes handle_handle_destroy() which does more cleanup */ |
| 98 |
wlr_ext_foreign_toplevel_handle_v1_destroy(ext_toplevel->handle); |
| 99 |
assert(!ext_toplevel->handle); |
| 100 |
} |