summaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-05-18 19:13:08 +0100
committerLibravatar emersion <contact@emersion.fr>2018-05-18 19:13:08 +0100
commite4dbafe4d84c8666a2f658fd195a47d13ae42378 (patch)
treedc8cae3d93a5246b8003ee8efb5b5d200dbb214f /swaylock
parentMerge pull request #1982 from RyanDwyer/show-marks (diff)
downloadsway-e4dbafe4d84c8666a2f658fd195a47d13ae42378.tar.gz
sway-e4dbafe4d84c8666a2f658fd195a47d13ae42378.tar.zst
sway-e4dbafe4d84c8666a2f658fd195a47d13ae42378.zip
Fix swaylock crashing when unplugging output
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 200c1b5f..08a8691e 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -61,6 +61,20 @@ static void daemonize() {
61 } 61 }
62} 62}
63 63
64static void destroy_surface(struct swaylock_surface *surface) {
65 wl_list_remove(&surface->link);
66 if (surface->layer_surface != NULL) {
67 zwlr_layer_surface_v1_destroy(surface->layer_surface);
68 }
69 if (surface->surface != NULL) {
70 wl_surface_destroy(surface->surface);
71 }
72 destroy_buffer(&surface->buffers[0]);
73 destroy_buffer(&surface->buffers[1]);
74 wl_output_destroy(surface->output);
75 free(surface);
76}
77
64static void layer_surface_configure(void *data, 78static void layer_surface_configure(void *data,
65 struct zwlr_layer_surface_v1 *layer_surface, 79 struct zwlr_layer_surface_v1 *layer_surface,
66 uint32_t serial, uint32_t width, uint32_t height) { 80 uint32_t serial, uint32_t width, uint32_t height) {
@@ -74,9 +88,7 @@ static void layer_surface_configure(void *data,
74static void layer_surface_closed(void *data, 88static void layer_surface_closed(void *data,
75 struct zwlr_layer_surface_v1 *layer_surface) { 89 struct zwlr_layer_surface_v1 *layer_surface) {
76 struct swaylock_surface *surface = data; 90 struct swaylock_surface *surface = data;
77 zwlr_layer_surface_v1_destroy(surface->layer_surface); 91 destroy_surface(surface);
78 wl_surface_destroy(surface->surface);
79 surface->state->run_display = false;
80} 92}
81 93
82static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { 94static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
@@ -139,6 +151,7 @@ static void handle_global(void *data, struct wl_registry *registry,
139 surface->state = state; 151 surface->state = state;
140 surface->output = wl_registry_bind(registry, name, 152 surface->output = wl_registry_bind(registry, name,
141 &wl_output_interface, 3); 153 &wl_output_interface, 3);
154 surface->output_global_name = name;
142 wl_output_add_listener(surface->output, &output_listener, surface); 155 wl_output_add_listener(surface->output, &output_listener, surface);
143 wl_list_insert(&state->surfaces, &surface->link); 156 wl_list_insert(&state->surfaces, &surface->link);
144 } 157 }
@@ -146,7 +159,14 @@ static void handle_global(void *data, struct wl_registry *registry,
146 159
147static void handle_global_remove(void *data, struct wl_registry *registry, 160static void handle_global_remove(void *data, struct wl_registry *registry,
148 uint32_t name) { 161 uint32_t name) {
149 // who cares 162 struct swaylock_state *state = data;
163 struct swaylock_surface *surface;
164 wl_list_for_each(surface, &state->surfaces, link) {
165 if (surface->output_global_name == name) {
166 destroy_surface(surface);
167 break;
168 }
169 }
150} 170}
151 171
152static const struct wl_registry_listener registry_listener = { 172static const struct wl_registry_listener registry_listener = {
@@ -180,7 +200,7 @@ int main(int argc, char **argv) {
180 " -v, --version Show the version number and quit.\n" 200 " -v, --version Show the version number and quit.\n"
181 " -i, --image [<output>:]<path> Display the given image.\n" 201 " -i, --image [<output>:]<path> Display the given image.\n"
182 " -u, --no-unlock-indicator Disable the unlock indicator.\n" 202 " -u, --no-unlock-indicator Disable the unlock indicator.\n"
183 " -f, --daemonize Detach from the controlling terminal.\n" 203 " -f, --daemonize Detach from the controlling terminal.\n"
184 " --socket <socket> Use the specified socket.\n"; 204 " --socket <socket> Use the specified socket.\n";
185 205
186 struct swaylock_args args = { 206 struct swaylock_args args = {