aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-05 15:39:57 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-05 16:04:30 -0400
commitf242362e7e521a8f35f47572038a20d404d25327 (patch)
tree523748eb922a50f9e74a485b86f445f8bc759464
parentAdd -Wno-unused-result (diff)
downloadsway-f242362e7e521a8f35f47572038a20d404d25327.tar.gz
sway-f242362e7e521a8f35f47572038a20d404d25327.tar.zst
sway-f242362e7e521a8f35f47572038a20d404d25327.zip
Handle output removal on swaybar
-rw-r--r--client/pool-buffer.c2
-rw-r--r--include/pool-buffer.h1
-rw-r--r--include/swaybar/bar.h1
-rw-r--r--sway/tree/container.c4
-rw-r--r--swaybar/bar.c42
-rw-r--r--swaybar/ipc.c2
-rw-r--r--swaybar/render.c2
7 files changed, 45 insertions, 9 deletions
diff --git a/client/pool-buffer.c b/client/pool-buffer.c
index b5ed9c98..1f54a77c 100644
--- a/client/pool-buffer.c
+++ b/client/pool-buffer.c
@@ -79,7 +79,7 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm,
79 return buf; 79 return buf;
80} 80}
81 81
82static void destroy_buffer(struct pool_buffer *buffer) { 82void destroy_buffer(struct pool_buffer *buffer) {
83 if (buffer->buffer) { 83 if (buffer->buffer) {
84 wl_buffer_destroy(buffer->buffer); 84 wl_buffer_destroy(buffer->buffer);
85 } 85 }
diff --git a/include/pool-buffer.h b/include/pool-buffer.h
index cdebd64d..856f7c8c 100644
--- a/include/pool-buffer.h
+++ b/include/pool-buffer.h
@@ -17,5 +17,6 @@ struct pool_buffer {
17 17
18struct pool_buffer *get_next_buffer(struct wl_shm *shm, 18struct pool_buffer *get_next_buffer(struct wl_shm *shm,
19 struct pool_buffer pool[static 2], uint32_t width, uint32_t height); 19 struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
20void destroy_buffer(struct pool_buffer *buffer);
20 21
21#endif 22#endif
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 503b961c..0037190b 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -49,6 +49,7 @@ struct swaybar_output {
49 struct wl_output *output; 49 struct wl_output *output;
50 struct wl_surface *surface; 50 struct wl_surface *surface;
51 struct zwlr_layer_surface_v1 *layer_surface; 51 struct zwlr_layer_surface_v1 *layer_surface;
52 uint32_t wl_name;
52 53
53 struct wl_list workspaces; 54 struct wl_list workspaces;
54 struct wl_list hotspots; 55 struct wl_list hotspots;
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 8fc9e3e8..3e8c1c75 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -64,7 +64,9 @@ static void container_close_notify(struct sway_container *container) {
64 return; 64 return;
65 } 65 }
66 // TODO send ipc event type based on the container type 66 // TODO send ipc event type based on the container type
67 ipc_event_window(container, "close"); 67 if (container->type == C_VIEW || container->type == C_WORKSPACE) {
68 ipc_event_window(container, "close");
69 }
68} 70}
69 71
70struct sway_container *container_create(enum sway_container_type type) { 72struct sway_container *container_create(enum sway_container_type type) {
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
37static 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
37static void layer_surface_configure(void *data, 65static 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
47static void layer_surface_closed(void *_output, 75static 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
55struct zwlr_layer_surface_v1_listener layer_surface_listener = { 81struct 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
273static void handle_global_remove(void *data, struct wl_registry *registry, 300static 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
278static const struct wl_registry_listener registry_listener = { 312static 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,
421static uint32_t render_to_cairo(cairo_t *cairo, 421static 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);