mirror of
https://github.com/swaywm/sway.git
synced 2025-11-16 06:59:49 -05:00
Introduce common functions to create, map, unmap, destroy views
This commit is contained in:
parent
122b96abed
commit
b2c2ee693b
8 changed files with 212 additions and 150 deletions
|
|
@ -102,56 +102,35 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
|||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_surface *sway_surface =
|
||||
wl_container_of(listener, sway_surface, destroy);
|
||||
|
||||
wl_list_remove(&sway_surface->commit.link);
|
||||
wl_list_remove(&sway_surface->destroy.link);
|
||||
wl_list_remove(&sway_surface->request_configure.link);
|
||||
wl_list_remove(&sway_surface->view->unmanaged_view_link);
|
||||
container_view_destroy(sway_surface->view->swayc);
|
||||
sway_surface->view->swayc = NULL;
|
||||
sway_surface->view->surface = NULL;
|
||||
wl_list_remove(&sway_surface->map.link);
|
||||
wl_list_remove(&sway_surface->unmap.link);
|
||||
view_destroy(sway_surface->view);
|
||||
free(sway_surface);
|
||||
}
|
||||
|
||||
static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_surface *sway_surface =
|
||||
wl_container_of(listener, sway_surface, unmap);
|
||||
view_damage_whole(sway_surface->view);
|
||||
wl_list_remove(&sway_surface->view->unmanaged_view_link);
|
||||
wl_list_init(&sway_surface->view->unmanaged_view_link);
|
||||
container_view_destroy(sway_surface->view->swayc);
|
||||
sway_surface->view->swayc = NULL;
|
||||
sway_surface->view->surface = NULL;
|
||||
view_unmap(sway_surface->view);
|
||||
}
|
||||
|
||||
static void handle_map(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_surface *sway_surface =
|
||||
wl_container_of(listener, sway_surface, map);
|
||||
struct wlr_xwayland_surface *xsurface = data;
|
||||
|
||||
sway_surface->view->surface = xsurface->surface;
|
||||
struct sway_view *view = sway_surface->view;
|
||||
|
||||
// put it back into the tree
|
||||
if (wlr_xwayland_surface_is_unmanaged(xsurface) ||
|
||||
xsurface->override_redirect) {
|
||||
wl_list_remove(&sway_surface->view->unmanaged_view_link);
|
||||
wl_list_insert(&root_container.sway_root->unmanaged_views,
|
||||
&sway_surface->view->unmanaged_view_link);
|
||||
view_map_unmanaged(view, xsurface->surface);
|
||||
} else {
|
||||
struct sway_view *view = sway_surface->view;
|
||||
container_view_destroy(view->swayc);
|
||||
|
||||
wlr_xwayland_surface_set_maximized(xsurface, true);
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus = sway_seat_get_focus_inactive(seat,
|
||||
&root_container);
|
||||
struct sway_container *cont = container_view_create(focus, view);
|
||||
view->swayc = cont;
|
||||
arrange_windows(cont->parent, -1, -1);
|
||||
sway_input_manager_set_focus(input_manager, cont);
|
||||
view_map(view, xsurface->surface);
|
||||
}
|
||||
|
||||
view_damage_whole(sway_surface->view);
|
||||
}
|
||||
|
||||
static void handle_request_configure(struct wl_listener *listener, void *data) {
|
||||
|
|
@ -180,25 +159,21 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sway_view *sway_view = calloc(1, sizeof(struct sway_view));
|
||||
if (!sway_assert(sway_view, "Failed to allocate view!")) {
|
||||
struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW);
|
||||
if (!sway_assert(view, "Failed to allocate view")) {
|
||||
return;
|
||||
}
|
||||
sway_view->type = SWAY_XWAYLAND_VIEW;
|
||||
sway_view->iface.get_prop = get_prop;
|
||||
sway_view->iface.set_size = set_size;
|
||||
sway_view->iface.set_position = set_position;
|
||||
sway_view->iface.set_activated = set_activated;
|
||||
sway_view->iface.close = close_view;
|
||||
sway_view->wlr_xwayland_surface = xsurface;
|
||||
sway_view->sway_xwayland_surface = sway_surface;
|
||||
sway_surface->view = sway_view;
|
||||
|
||||
wl_list_init(&sway_view->unmanaged_view_link);
|
||||
view->iface.get_prop = get_prop;
|
||||
view->iface.set_size = set_size;
|
||||
view->iface.set_position = set_position;
|
||||
view->iface.set_activated = set_activated;
|
||||
view->iface.close = close_view;
|
||||
view->wlr_xwayland_surface = xsurface;
|
||||
view->sway_xwayland_surface = sway_surface;
|
||||
sway_surface->view = view;
|
||||
|
||||
// TODO:
|
||||
// - Look up pid and open on appropriate workspace
|
||||
// - Set new view to maximized so it behaves nicely
|
||||
// - Criteria
|
||||
|
||||
wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue