diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index ea0141cc..f1a701b9 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -34,6 +34,34 @@ static void bar_init(struct swaybar *bar) { | |||
34 | wl_list_init(&bar->outputs); | 34 | wl_list_init(&bar->outputs); |
35 | } | 35 | } |
36 | 36 | ||
37 | static void swaybar_output_free(struct swaybar_output *output) { | ||
38 | if (!output) { | ||
39 | return; | ||
40 | } | ||
41 | wlr_log(L_DEBUG, "Removing output %s", output->name); | ||
42 | zwlr_layer_surface_v1_destroy(output->layer_surface); | ||
43 | wl_surface_destroy(output->surface); | ||
44 | wl_output_destroy(output->output); | ||
45 | destroy_buffer(&output->buffers[0]); | ||
46 | destroy_buffer(&output->buffers[1]); | ||
47 | struct swaybar_workspace *ws, *ws_tmp; | ||
48 | wl_list_for_each_safe(ws, ws_tmp, &output->workspaces, link) { | ||
49 | wl_list_remove(&ws->link); | ||
50 | free(ws->name); | ||
51 | free(ws); | ||
52 | } | ||
53 | struct swaybar_hotspot *hotspot, *hotspot_tmp; | ||
54 | wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) { | ||
55 | if (hotspot->destroy) { | ||
56 | hotspot->destroy(hotspot->data); | ||
57 | } | ||
58 | free(hotspot); | ||
59 | } | ||
60 | wl_list_remove(&output->link); | ||
61 | free(output->name); | ||
62 | free(output); | ||
63 | } | ||
64 | |||
37 | static void layer_surface_configure(void *data, | 65 | static void layer_surface_configure(void *data, |
38 | struct zwlr_layer_surface_v1 *surface, | 66 | struct zwlr_layer_surface_v1 *surface, |
39 | uint32_t serial, uint32_t width, uint32_t height) { | 67 | uint32_t serial, uint32_t width, uint32_t height) { |
@@ -46,10 +74,8 @@ static void layer_surface_configure(void *data, | |||
46 | 74 | ||
47 | static void layer_surface_closed(void *_output, | 75 | static void layer_surface_closed(void *_output, |
48 | struct zwlr_layer_surface_v1 *surface) { | 76 | struct zwlr_layer_surface_v1 *surface) { |
49 | // TODO: Deal with hotplugging | ||
50 | struct swaybar_output *output = _output; | 77 | struct swaybar_output *output = _output; |
51 | zwlr_layer_surface_v1_destroy(output->layer_surface); | 78 | swaybar_output_free(output); |
52 | wl_surface_destroy(output->surface); | ||
53 | } | 79 | } |
54 | 80 | ||
55 | struct zwlr_layer_surface_v1_listener layer_surface_listener = { | 81 | struct zwlr_layer_surface_v1_listener layer_surface_listener = { |
@@ -261,6 +287,7 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
261 | wl_output_add_listener(output->output, &output_listener, output); | 287 | wl_output_add_listener(output->output, &output_listener, output); |
262 | output->scale = 1; | 288 | output->scale = 1; |
263 | output->index = index++; | 289 | output->index = index++; |
290 | output->wl_name = name; | ||
264 | wl_list_init(&output->workspaces); | 291 | wl_list_init(&output->workspaces); |
265 | wl_list_init(&output->hotspots); | 292 | wl_list_init(&output->hotspots); |
266 | wl_list_insert(&bar->outputs, &output->link); | 293 | wl_list_insert(&bar->outputs, &output->link); |
@@ -272,7 +299,14 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
272 | 299 | ||
273 | static void handle_global_remove(void *data, struct wl_registry *registry, | 300 | static void handle_global_remove(void *data, struct wl_registry *registry, |
274 | uint32_t name) { | 301 | uint32_t name) { |
275 | // who cares | 302 | struct swaybar *bar = data; |
303 | struct swaybar_output *output, *tmp; | ||
304 | wl_list_for_each_safe(output, tmp, &bar->outputs, link) { | ||
305 | if (output->wl_name == name) { | ||
306 | swaybar_output_free(output); | ||
307 | break; | ||
308 | } | ||
309 | } | ||
276 | } | 310 | } |
277 | 311 | ||
278 | static const struct wl_registry_listener registry_listener = { | 312 | static const struct wl_registry_listener registry_listener = { |