diff options
author | 2023-01-08 09:21:30 -0500 | |
---|---|---|
committer | 2023-01-16 10:47:42 -0500 | |
commit | 5e73acb431258d81a01709fbd28da2e151bd3bd3 (patch) | |
tree | 94b773c7ff37dfe45c6e99cfaecff98927bf0b8b /swaynag/main.c | |
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.
Diffstat (limited to 'swaynag/main.c')
-rw-r--r-- | swaynag/main.c | 21 |
1 files changed, 10 insertions, 11 deletions
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 | } |