diff options
author | Simon Ser <contact@emersion.fr> | 2022-11-10 11:24:48 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-11 17:01:50 +0100 |
commit | d945c8f519282be4bfadaded990effd729c8321d (patch) | |
tree | cac20612d5a1fd49071f006ab185a3ffc251e0d8 | |
parent | Use wlr_damage_ring (diff) | |
download | sway-d945c8f519282be4bfadaded990effd729c8321d.tar.gz sway-d945c8f519282be4bfadaded990effd729c8321d.tar.zst sway-d945c8f519282be4bfadaded990effd729c8321d.zip |
lock: fix crash on output destroy
Closes: https://github.com/swaywm/sway/issues/7120
-rw-r--r-- | sway/lock.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/sway/lock.c b/sway/lock.c index 3c7c06cf..bf7d5de8 100644 --- a/sway/lock.c +++ b/sway/lock.c | |||
@@ -15,6 +15,7 @@ struct sway_session_lock_surface { | |||
15 | struct wl_listener surface_commit; | 15 | struct wl_listener surface_commit; |
16 | struct wl_listener output_mode; | 16 | struct wl_listener output_mode; |
17 | struct wl_listener output_commit; | 17 | struct wl_listener output_commit; |
18 | struct wl_listener output_destroy; | ||
18 | }; | 19 | }; |
19 | 20 | ||
20 | static void set_lock_focused_surface(struct wlr_surface *focused) { | 21 | static void set_lock_focused_surface(struct wlr_surface *focused) { |
@@ -57,9 +58,7 @@ static void handle_output_commit(struct wl_listener *listener, void *data) { | |||
57 | } | 58 | } |
58 | } | 59 | } |
59 | 60 | ||
60 | static void handle_surface_destroy(struct wl_listener *listener, void *data) { | 61 | static void destroy_lock_surface(struct sway_session_lock_surface *surf) { |
61 | struct sway_session_lock_surface *surf = wl_container_of(listener, surf, destroy); | ||
62 | |||
63 | // Move the seat focus to another surface if one is available | 62 | // Move the seat focus to another surface if one is available |
64 | if (server.session_lock.focused == surf->surface) { | 63 | if (server.session_lock.focused == surf->surface) { |
65 | struct wlr_surface *next_focus = NULL; | 64 | struct wlr_surface *next_focus = NULL; |
@@ -79,10 +78,22 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) { | |||
79 | wl_list_remove(&surf->surface_commit.link); | 78 | wl_list_remove(&surf->surface_commit.link); |
80 | wl_list_remove(&surf->output_mode.link); | 79 | wl_list_remove(&surf->output_mode.link); |
81 | wl_list_remove(&surf->output_commit.link); | 80 | wl_list_remove(&surf->output_commit.link); |
81 | wl_list_remove(&surf->output_destroy.link); | ||
82 | output_damage_whole(surf->output); | 82 | output_damage_whole(surf->output); |
83 | free(surf); | 83 | free(surf); |
84 | } | 84 | } |
85 | 85 | ||
86 | static void handle_surface_destroy(struct wl_listener *listener, void *data) { | ||
87 | struct sway_session_lock_surface *surf = wl_container_of(listener, surf, destroy); | ||
88 | destroy_lock_surface(surf); | ||
89 | } | ||
90 | |||
91 | static void handle_output_destroy(struct wl_listener *listener, void *data) { | ||
92 | struct sway_session_lock_surface *surf = | ||
93 | wl_container_of(listener, surf, output_destroy); | ||
94 | destroy_lock_surface(surf); | ||
95 | } | ||
96 | |||
86 | static void handle_new_surface(struct wl_listener *listener, void *data) { | 97 | static void handle_new_surface(struct wl_listener *listener, void *data) { |
87 | struct wlr_session_lock_surface_v1 *lock_surface = data; | 98 | struct wlr_session_lock_surface_v1 *lock_surface = data; |
88 | struct sway_session_lock_surface *surf = calloc(1, sizeof(*surf)); | 99 | struct sway_session_lock_surface *surf = calloc(1, sizeof(*surf)); |
@@ -108,6 +119,8 @@ static void handle_new_surface(struct wl_listener *listener, void *data) { | |||
108 | wl_signal_add(&output->wlr_output->events.mode, &surf->output_mode); | 119 | wl_signal_add(&output->wlr_output->events.mode, &surf->output_mode); |
109 | surf->output_commit.notify = handle_output_commit; | 120 | surf->output_commit.notify = handle_output_commit; |
110 | wl_signal_add(&output->wlr_output->events.commit, &surf->output_commit); | 121 | wl_signal_add(&output->wlr_output->events.commit, &surf->output_commit); |
122 | surf->output_destroy.notify = handle_output_destroy; | ||
123 | wl_signal_add(&output->node.events.destroy, &surf->output_destroy); | ||
111 | } | 124 | } |
112 | 125 | ||
113 | static void handle_unlock(struct wl_listener *listener, void *data) { | 126 | static void handle_unlock(struct wl_listener *listener, void *data) { |