diff options
author | Manuel Stoeckl <code@mstoeckl.com> | 2023-01-08 09:21:30 -0500 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2023-01-16 10:47:42 -0500 |
commit | 5e73acb431258d81a01709fbd28da2e151bd3bd3 (patch) | |
tree | 94b773c7ff37dfe45c6e99cfaecff98927bf0b8b | |
parent | input: enable user xkb configs with cap_sys_nice (diff) | |
download | sway-5e73acb431258d81a01709fbd28da2e151bd3bd3.tar.gz sway-5e73acb431258d81a01709fbd28da2e151bd3bd3.tar.zst sway-5e73acb431258d81a01709fbd28da2e151bd3bd3.zip |
swaynag: call swaynag_destroy on clean exit
And fix the fallout of the swaynag_destroy having evolved without
being tested:
* wl_display_disconnect was called too early
* `button_close` and `swaynag.details.button_details` needed to be
heap allocated, since they are added to swaynag.buttons, and all
entries of swaynag.buttons are freed in swaynag_destroy
* To keep things simpler, disconnect the lifetime of the 'Toggle details'
button text config setting from the button itself.
-rw-r--r-- | include/swaynag/swaynag.h | 3 | ||||
-rw-r--r-- | swaynag/config.c | 4 | ||||
-rw-r--r-- | swaynag/main.c | 21 | ||||
-rw-r--r-- | swaynag/swaynag.c | 9 |
4 files changed, 19 insertions, 18 deletions
diff --git a/include/swaynag/swaynag.h b/include/swaynag/swaynag.h index 2d68b6c9..ccd313a0 100644 --- a/include/swaynag/swaynag.h +++ b/include/swaynag/swaynag.h | |||
@@ -58,6 +58,7 @@ struct swaynag_button { | |||
58 | struct swaynag_details { | 58 | struct swaynag_details { |
59 | bool visible; | 59 | bool visible; |
60 | char *message; | 60 | char *message; |
61 | char *details_text; | ||
61 | 62 | ||
62 | int x; | 63 | int x; |
63 | int y; | 64 | int y; |
@@ -67,7 +68,7 @@ struct swaynag_details { | |||
67 | int offset; | 68 | int offset; |
68 | int visible_lines; | 69 | int visible_lines; |
69 | int total_lines; | 70 | int total_lines; |
70 | struct swaynag_button button_details; | 71 | struct swaynag_button *button_details; |
71 | struct swaynag_button button_up; | 72 | struct swaynag_button button_up; |
72 | struct swaynag_button button_down; | 73 | struct swaynag_button button_down; |
73 | }; | 74 | }; |
diff --git a/swaynag/config.c b/swaynag/config.c index 6c8c26fc..6d39f342 100644 --- a/swaynag/config.c +++ b/swaynag/config.c | |||
@@ -243,8 +243,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, | |||
243 | break; | 243 | break; |
244 | case 'L': // Detailed Button Text | 244 | case 'L': // Detailed Button Text |
245 | if (swaynag) { | 245 | if (swaynag) { |
246 | free(swaynag->details.button_details.text); | 246 | free(swaynag->details.details_text); |
247 | swaynag->details.button_details.text = strdup(optarg); | 247 | swaynag->details.details_text = strdup(optarg); |
248 | } | 248 | } |
249 | break; | 249 | break; |
250 | case 'm': // Message | 250 | case 'm': // Message |
diff --git a/swaynag/main.c b/swaynag/main.c index 679afbce..20390207 100644 --- a/swaynag/main.c +++ b/swaynag/main.c | |||
@@ -29,10 +29,12 @@ int main(int argc, char **argv) { | |||
29 | wl_list_init(&swaynag.outputs); | 29 | wl_list_init(&swaynag.outputs); |
30 | wl_list_init(&swaynag.seats); | 30 | wl_list_init(&swaynag.seats); |
31 | 31 | ||
32 | struct swaynag_button button_close = { 0 }; | 32 | struct swaynag_button *button_close = calloc(1, sizeof(struct swaynag_button)); |
33 | button_close.text = strdup("X"); | 33 | button_close->text = strdup("X"); |
34 | button_close.type = SWAYNAG_ACTION_DISMISS; | 34 | button_close->type = SWAYNAG_ACTION_DISMISS; |
35 | list_add(swaynag.buttons, &button_close); | 35 | list_add(swaynag.buttons, button_close); |
36 | |||
37 | swaynag.details.details_text = strdup("Toggle details"); | ||
36 | 38 | ||
37 | char *config_path = NULL; | 39 | char *config_path = NULL; |
38 | bool debug = false; | 40 | bool debug = false; |
@@ -54,8 +56,6 @@ int main(int argc, char **argv) { | |||
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | swaynag.details.button_details.text = strdup("Toggle details"); | ||
58 | swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND; | ||
59 | 59 | ||
60 | if (argc > 1) { | 60 | if (argc > 1) { |
61 | struct swaynag_type *type_args = swaynag_type_new("<args>"); | 61 | struct swaynag_type *type_args = swaynag_type_new("<args>"); |
@@ -88,10 +88,11 @@ int main(int argc, char **argv) { | |||
88 | swaynag_type_merge(type, swaynag_type_get(types, "<args>")); | 88 | swaynag_type_merge(type, swaynag_type_get(types, "<args>")); |
89 | swaynag.type = type; | 89 | swaynag.type = type; |
90 | 90 | ||
91 | swaynag_types_free(types); | ||
92 | |||
93 | if (swaynag.details.message) { | 91 | if (swaynag.details.message) { |
94 | list_add(swaynag.buttons, &swaynag.details.button_details); | 92 | swaynag.details.button_details = calloc(1, sizeof(struct swaynag_button)); |
93 | swaynag.details.button_details->text = strdup(swaynag.details.details_text); | ||
94 | swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND; | ||
95 | list_add(swaynag.buttons, swaynag.details.button_details); | ||
95 | } | 96 | } |
96 | 97 | ||
97 | sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output); | 98 | sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output); |
@@ -111,11 +112,9 @@ int main(int argc, char **argv) { | |||
111 | 112 | ||
112 | swaynag_setup(&swaynag); | 113 | swaynag_setup(&swaynag); |
113 | swaynag_run(&swaynag); | 114 | swaynag_run(&swaynag); |
114 | return status; | ||
115 | 115 | ||
116 | cleanup: | 116 | cleanup: |
117 | swaynag_types_free(types); | 117 | swaynag_types_free(types); |
118 | free(swaynag.details.button_details.text); | ||
119 | swaynag_destroy(&swaynag); | 118 | swaynag_destroy(&swaynag); |
120 | return status; | 119 | return status; |
121 | } | 120 | } |
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 5620155d..08e26127 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -483,10 +483,6 @@ void swaynag_run(struct swaynag *swaynag) { | |||
483 | && wl_display_dispatch(swaynag->display) != -1) { | 483 | && wl_display_dispatch(swaynag->display) != -1) { |
484 | // This is intentionally left blank | 484 | // This is intentionally left blank |
485 | } | 485 | } |
486 | |||
487 | if (swaynag->display) { | ||
488 | wl_display_disconnect(swaynag->display); | ||
489 | } | ||
490 | } | 486 | } |
491 | 487 | ||
492 | void swaynag_destroy(struct swaynag *swaynag) { | 488 | void swaynag_destroy(struct swaynag *swaynag) { |
@@ -501,6 +497,7 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
501 | } | 497 | } |
502 | list_free(swaynag->buttons); | 498 | list_free(swaynag->buttons); |
503 | free(swaynag->details.message); | 499 | free(swaynag->details.message); |
500 | free(swaynag->details.details_text); | ||
504 | free(swaynag->details.button_up.text); | 501 | free(swaynag->details.button_up.text); |
505 | free(swaynag->details.button_down.text); | 502 | free(swaynag->details.button_down.text); |
506 | 503 | ||
@@ -541,4 +538,8 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
541 | if (swaynag->shm) { | 538 | if (swaynag->shm) { |
542 | wl_shm_destroy(swaynag->shm); | 539 | wl_shm_destroy(swaynag->shm); |
543 | } | 540 | } |
541 | |||
542 | if (swaynag->display) { | ||
543 | wl_display_disconnect(swaynag->display); | ||
544 | } | ||
544 | } | 545 | } |