diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-05 15:39:57 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-04-05 16:04:30 -0400 |
commit | f242362e7e521a8f35f47572038a20d404d25327 (patch) | |
tree | 523748eb922a50f9e74a485b86f445f8bc759464 /swaybar | |
parent | Add -Wno-unused-result (diff) | |
download | sway-f242362e7e521a8f35f47572038a20d404d25327.tar.gz sway-f242362e7e521a8f35f47572038a20d404d25327.tar.zst sway-f242362e7e521a8f35f47572038a20d404d25327.zip |
Handle output removal on swaybar
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 42 | ||||
-rw-r--r-- | swaybar/ipc.c | 2 | ||||
-rw-r--r-- | swaybar/render.c | 2 |
3 files changed, 39 insertions, 7 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 = { |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index ed5d9a31..92dbb8ea 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -367,5 +367,5 @@ bool handle_ipc_readable(struct swaybar *bar) { | |||
367 | return false; | 367 | return false; |
368 | } | 368 | } |
369 | free_ipc_response(resp); | 369 | free_ipc_response(resp); |
370 | return true; | 370 | return false; |
371 | } | 371 | } |
diff --git a/swaybar/render.c b/swaybar/render.c index be58301d..53e578f0 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -421,8 +421,6 @@ static uint32_t render_workspace_button(cairo_t *cairo, | |||
421 | static uint32_t render_to_cairo(cairo_t *cairo, | 421 | static uint32_t render_to_cairo(cairo_t *cairo, |
422 | struct swaybar *bar, struct swaybar_output *output) { | 422 | struct swaybar *bar, struct swaybar_output *output) { |
423 | struct swaybar_config *config = bar->config; | 423 | struct swaybar_config *config = bar->config; |
424 | wlr_log(L_DEBUG, "output %p", output); | ||
425 | |||
426 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); | 424 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); |
427 | if (output->focused) { | 425 | if (output->focused) { |
428 | cairo_set_source_u32(cairo, config->colors.focused_background); | 426 | cairo_set_source_u32(cairo, config->colors.focused_background); |