Skip to content

Commit

Permalink
lock: fix crash on output destroy
Browse files Browse the repository at this point in the history
Closes: swaywm#7120
  • Loading branch information
emersion committed Nov 10, 2022
1 parent 6c3b357 commit 572f4cc
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sway/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct sway_session_lock_surface {
struct wl_listener surface_commit;
struct wl_listener output_mode;
struct wl_listener output_commit;
struct wl_listener output_destroy;
};

static void set_lock_focused_surface(struct wlr_surface *focused) {
Expand All @@ -28,6 +29,9 @@ static void set_lock_focused_surface(struct wlr_surface *focused) {

static void handle_surface_map(struct wl_listener *listener, void *data) {
struct sway_session_lock_surface *surf = wl_container_of(listener, surf, map);
if (surf->output == NULL) {
return;
}
if (server.session_lock.focused == NULL) {
set_lock_focused_surface(surf->surface);
}
Expand All @@ -36,6 +40,9 @@ static void handle_surface_map(struct wl_listener *listener, void *data) {

static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct sway_session_lock_surface *surf = wl_container_of(listener, surf, surface_commit);
if (surf->output == NULL) {
return;
}
output_damage_surface(surf->output, 0, 0, surf->surface, false);
}

Expand Down Expand Up @@ -79,10 +86,19 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&surf->surface_commit.link);
wl_list_remove(&surf->output_mode.link);
wl_list_remove(&surf->output_commit.link);
output_damage_whole(surf->output);
wl_list_remove(&surf->output_destroy.link);
if (surf->output != NULL) {
output_damage_whole(surf->output);
}
free(surf);
}

static void handle_output_destroy(struct wl_listener *listener, void *data) {
struct sway_session_lock_surface *surf =
wl_container_of(listener, surf, output_destroy);
surf->output = NULL;
}

static void handle_new_surface(struct wl_listener *listener, void *data) {
struct wlr_session_lock_surface_v1 *lock_surface = data;
struct sway_session_lock_surface *surf = calloc(1, sizeof(*surf));
Expand All @@ -108,6 +124,8 @@ static void handle_new_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&output->wlr_output->events.mode, &surf->output_mode);
surf->output_commit.notify = handle_output_commit;
wl_signal_add(&output->wlr_output->events.commit, &surf->output_commit);
surf->output_destroy.notify = handle_output_destroy;
wl_signal_add(&output->node.events.destroy, &surf->output_destroy);
}

static void handle_unlock(struct wl_listener *listener, void *data) {
Expand Down

0 comments on commit 572f4cc

Please sign in to comment.