aboutsummaryrefslogtreecommitdiff
path: root/swaynag
diff options
context:
space:
mode:
authorNihal Jere <nihal@nihaljere.xyz>2022-02-28 17:02:40 -0600
committerSimon Ser <contact@emersion.fr>2022-03-15 11:40:32 +0100
commit0babfce4b5f8ab22c4395766e8b7af4ad076503b (patch)
treef4568402e89431e42d20b6db9b791d77fb465329 /swaynag
parentf167acce3a11f342df5fef21679ae4eb8624ae15 (diff)
swaynag: allocate button_details with details
They are used together, so it doesn't make sense to allocate them separately.
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c4
-rw-r--r--swaynag/main.c20
2 files changed, 7 insertions, 17 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index 73fc41c8..b212a0c3 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -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
diff --git a/swaynag/main.c b/swaynag/main.c
index 0c94cb1a..112a8b2f 100644
--- a/swaynag/main.c
+++ b/swaynag/main.c
@@ -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;
}