Skip to content

Commit

Permalink
swaynag: statically allocate button_close, and move declaration
Browse files Browse the repository at this point in the history
Every swaynag has a close button, so it doesn't make sense to
allocate it dynamically. The declaration is moved later to when
it is actually needed.
  • Loading branch information
noocsharp authored and emersion committed Mar 15, 2022
1 parent 0babfce commit 4780afb
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions swaynag/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ int main(int argc, char **argv) {
wl_list_init(&swaynag.outputs);
wl_list_init(&swaynag.seats);

struct swaynag_button *button_close =
calloc(sizeof(struct swaynag_button), 1);
if (!button_close) {
perror("calloc");
return EXIT_FAILURE;
}
button_close->text = strdup("X");
button_close->type = SWAYNAG_ACTION_DISMISS;
list_add(swaynag.buttons, button_close);

char *config_path = NULL;
bool debug = false;
int launch_status = swaynag_parse_options(argc, argv, NULL, NULL, NULL,
Expand Down Expand Up @@ -100,6 +90,11 @@ int main(int argc, char **argv) {

swaynag_types_free(types);

struct swaynag_button button_close = { 0 };
button_close.text = strdup("X");
button_close.type = SWAYNAG_ACTION_DISMISS;
list_add(swaynag.buttons, &button_close);

if (swaynag.details.message) {
list_add(swaynag.buttons, &swaynag.details.button_details);
}
Expand Down

0 comments on commit 4780afb

Please sign in to comment.