Fix crash when switching workspace

Prior to this commit, it was possible that view->workspace
was not the same as the workspace on which the view was displayed
leading to erroneous behaviour and crashes when closing
such a window.
This commit is contained in:
project-repo 2020-09-11 15:04:43 +02:00
commit 4515ed8574
4 changed files with 9 additions and 7 deletions

10
view.c
View file

@ -315,8 +315,8 @@ view_unmap(struct cg_view *view) {
}
void
view_map(struct cg_view *view, struct wlr_surface *surface) {
struct cg_output *output = view->workspace->output;
view_map(struct cg_view *view, struct wlr_surface *surface, struct cg_workspace *ws) {
struct cg_output *output = ws->output;
view->wlr_surface = surface;
struct wlr_subsurface *subsurface;
@ -328,18 +328,20 @@ view_map(struct cg_view *view, struct wlr_surface *surface) {
wl_signal_add(&view->wlr_surface->events.new_subsurface,
&view->new_subsurface);
view->workspace=ws;
#if CG_HAS_XWAYLAND
/* We shouldn't position override-redirect windows. They set
their own (x,y) coordinates in handle_wayland_surface_map. */
if(view->type == CG_XWAYLAND_VIEW && !xwayland_view_should_manage(view)) {
wl_list_insert(
&output->workspaces[output->curr_workspace]->unmanaged_views,
&ws->unmanaged_views,
&view->link);
} else
#endif
{
view_position(view);
wl_list_insert(&output->workspaces[output->curr_workspace]->views,
wl_list_insert(&ws->views,
&view->link);
}
seat_set_focus(output->server->seat, view);

2
view.h
View file

@ -99,7 +99,7 @@ view_unmap(struct cg_view *view);
void
view_maximize(struct cg_view *view, const struct wlr_box *tile_box);
void
view_map(struct cg_view *view, struct wlr_surface *surface);
view_map(struct cg_view *view, struct wlr_surface *surface, struct cg_workspace *ws);
void
view_destroy(struct cg_view *view);
void

View file

@ -300,7 +300,7 @@ handle_xdg_shell_surface_map(struct wl_listener *listener, void *_data) {
wl_signal_add(&xdg_shell_view->xdg_surface->surface->events.commit,
&xdg_shell_view->commit);
view_map(view, xdg_shell_view->xdg_surface->surface);
view_map(view, xdg_shell_view->xdg_surface->surface,view->workspace->server->curr_output->workspaces[view->workspace->server->curr_output->curr_workspace]);
view_damage_whole(view);
}

View file

@ -188,7 +188,7 @@ handle_xwayland_surface_map(struct wl_listener *listener, void *_data) {
wl_signal_add(&xwayland_view->xwayland_surface->surface->events.commit,
&xwayland_view->commit);
view_map(view, xwayland_view->xwayland_surface->surface);
view_map(view, xwayland_view->xwayland_surface->surface,view->workspace->server->curr_output->workspaces[view->workspace->server->curr_output->curr_workspace]);
view_damage_whole(view);
}