swaynag: allocate button_details with details

They are used together, so it doesn't make sense to allocate them
separately.
This commit is contained in:
Nihal Jere 2022-02-28 17:02:40 -06:00 committed by Simon Ser
parent f167acce3a
commit 0babfce4b5
3 changed files with 8 additions and 18 deletions

View file

@ -67,7 +67,7 @@ struct swaynag_details {
int offset;
int visible_lines;
int total_lines;
struct swaynag_button *button_details;
struct swaynag_button button_details;
struct swaynag_button button_up;
struct swaynag_button button_down;
};

View file

@ -232,8 +232,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
break;
case 'L': // Detailed Button Text
if (swaynag) {
free(swaynag->details.button_details->text);
swaynag->details.button_details->text = strdup(optarg);
free(swaynag->details.button_details.text);
swaynag->details.button_details.text = strdup(optarg);
}
break;
case 'm': // Message

View file

@ -40,15 +40,6 @@ int main(int argc, char **argv) {
button_close->type = SWAYNAG_ACTION_DISMISS;
list_add(swaynag.buttons, button_close);
swaynag.details.button_details =
calloc(sizeof(struct swaynag_button), 1);
if (!swaynag.details.button_details) {
perror("calloc");
return EXIT_FAILURE;
}
swaynag.details.button_details->text = strdup("Toggle details");
swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND;
char *config_path = NULL;
bool debug = false;
int launch_status = swaynag_parse_options(argc, argv, NULL, NULL, NULL,
@ -72,6 +63,9 @@ int main(int argc, char **argv) {
}
}
swaynag.details.button_details.text = strdup("Toggle details");
swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND;
if (argc > 1) {
struct swaynag_type *type_args = swaynag_type_new("<args>");
list_add(types, type_args);
@ -107,10 +101,7 @@ int main(int argc, char **argv) {
swaynag_types_free(types);
if (swaynag.details.message) {
list_add(swaynag.buttons, swaynag.details.button_details);
} else {
free(swaynag.details.button_details->text);
free(swaynag.details.button_details);
list_add(swaynag.buttons, &swaynag.details.button_details);
}
sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output);
@ -132,8 +123,7 @@ int main(int argc, char **argv) {
cleanup:
swaynag_types_free(types);
free(swaynag.details.button_details->text);
free(swaynag.details.button_details);
free(swaynag.details.button_details.text);
swaynag_destroy(&swaynag);
return exit_code;
}