Properly track mapping and unmapping

We shouldn't render a window before it is mapped (obviously), but we
render all windows in the view list. Hence, only insert the window once
it is mapped.

We could run into the case where a window is destroyed without being in
the window list, so we now track unmapping again and remove windows from
the list when they get unmapped.
This commit is contained in:
Jente Hidskes 2018-12-31 19:52:47 +01:00
parent a9818c0df1
commit 786e28bdac
No known key found for this signature in database
GPG key ID: 04BE5A29F32D91EA
3 changed files with 19 additions and 6 deletions

10
view.c
View file

@ -56,6 +56,13 @@ view_is_primary(struct cg_view *view)
return view->is_primary(view);
}
void
view_unmap(struct cg_view *view)
{
wl_list_remove(&view->link);
view->wlr_surface = NULL;
}
void
view_map(struct cg_view *view, struct wlr_surface *surface)
{
@ -67,6 +74,7 @@ view_map(struct cg_view *view, struct wlr_surface *surface)
view_center(view);
}
wl_list_insert(&view->server->views, &view->link);
seat_set_focus(view->server->seat, view);
}
@ -76,7 +84,6 @@ view_destroy(struct cg_view *view)
struct cg_server *server = view->server;
bool terminate = view_is_primary(view);
wl_list_remove(&view->link);
free(view);
/* If this was our primary view, exit. */
@ -91,7 +98,6 @@ cg_view_create(struct cg_server *server)
struct cg_view *view = calloc(1, sizeof(struct cg_view));
view->server = server;
wl_list_insert(&server->views, &view->link);
return view;
}

2
view.h
View file

@ -25,6 +25,7 @@ struct cg_view {
};
struct wl_listener destroy;
struct wl_listener unmap;
struct wl_listener map;
// TODO: allow applications to go to fullscreen from maximized?
// struct wl_listener request_fullscreen;
@ -39,6 +40,7 @@ void view_activate(struct cg_view *view, bool activate);
void view_maximize(struct cg_view *view);
void view_center(struct cg_view *view);
bool view_is_primary(struct cg_view *view);
void view_unmap(struct cg_view *view);
void view_map(struct cg_view *view, struct wlr_surface *surface);
void view_destroy(struct cg_view *view);
struct cg_view *cg_view_create(struct cg_server *server);

View file

@ -41,6 +41,13 @@ is_primary(struct cg_view *view)
return parent == NULL; /*&& role == WLR_XDG_SURFACE_ROLE_TOPLEVEL */
}
static void
handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data)
{
struct cg_view *view = wl_container_of(listener, view, unmap);
view_unmap(view);
}
static void
handle_xdg_shell_surface_map(struct wl_listener *listener, void *data)
{
@ -61,16 +68,14 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data)
struct cg_server *server = wl_container_of(listener, server, new_xdg_shell_surface);
struct wlr_xdg_surface *xdg_surface = data;
if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
return;
}
struct cg_view *view = cg_view_create(server);
view->type = CAGE_XDG_SHELL_VIEW;
view->xdg_surface = xdg_surface;
view->map.notify = handle_xdg_shell_surface_map;
wl_signal_add(&xdg_surface->events.map, &view->map);
view->unmap.notify = handle_xdg_shell_surface_unmap;
wl_signal_add(&xdg_surface->events.unmap, &view->unmap);
view->destroy.notify = handle_xdg_shell_surface_destroy;
wl_signal_add(&xdg_surface->events.destroy, &view->destroy);