aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaynag/main.c')
-rw-r--r--swaynag/main.c48
1 files changed, 18 insertions, 30 deletions
diff --git a/swaynag/main.c b/swaynag/main.c
index 88007818..634bddbf 100644
--- a/swaynag/main.c
+++ b/swaynag/main.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <stdlib.h> 1#include <stdlib.h>
3#include <signal.h> 2#include <signal.h>
4#include "log.h" 3#include "log.h"
@@ -20,33 +19,27 @@ void sway_terminate(int code) {
20} 19}
21 20
22int main(int argc, char **argv) { 21int main(int argc, char **argv) {
23 int exit_code = EXIT_SUCCESS; 22 int status = EXIT_SUCCESS;
24 23
25 list_t *types = create_list(); 24 list_t *types = create_list();
26 swaynag_types_add_default(types); 25 swaynag_types_add_default(types);
27 26
28 memset(&swaynag, 0, sizeof(swaynag));
29 swaynag.buttons = create_list(); 27 swaynag.buttons = create_list();
30 wl_list_init(&swaynag.outputs); 28 wl_list_init(&swaynag.outputs);
31 wl_list_init(&swaynag.seats); 29 wl_list_init(&swaynag.seats);
32 30
33 struct swaynag_button *button_close = 31 struct swaynag_button *button_close = calloc(1, sizeof(struct swaynag_button));
34 calloc(sizeof(struct swaynag_button), 1);
35 button_close->text = strdup("X"); 32 button_close->text = strdup("X");
36 button_close->type = SWAYNAG_ACTION_DISMISS; 33 button_close->type = SWAYNAG_ACTION_DISMISS;
37 list_add(swaynag.buttons, button_close); 34 list_add(swaynag.buttons, button_close);
38 35
39 swaynag.details.button_details = 36 swaynag.details.details_text = strdup("Toggle details");
40 calloc(sizeof(struct swaynag_button), 1);
41 swaynag.details.button_details->text = strdup("Toggle details");
42 swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND;
43 37
44 char *config_path = NULL; 38 char *config_path = NULL;
45 bool debug = false; 39 bool debug = false;
46 int launch_status = swaynag_parse_options(argc, argv, NULL, NULL, NULL, 40 status = swaynag_parse_options(argc, argv, NULL, NULL, NULL,
47 &config_path, &debug); 41 &config_path, &debug);
48 if (launch_status != 0) { 42 if (status != 0) {
49 exit_code = launch_status;
50 goto cleanup; 43 goto cleanup;
51 } 44 }
52 sway_log_init(debug ? SWAY_DEBUG : SWAY_ERROR, NULL); 45 sway_log_init(debug ? SWAY_DEBUG : SWAY_ERROR, NULL);
@@ -56,29 +49,27 @@ int main(int argc, char **argv) {
56 } 49 }
57 if (config_path) { 50 if (config_path) {
58 sway_log(SWAY_DEBUG, "Loading config file: %s", config_path); 51 sway_log(SWAY_DEBUG, "Loading config file: %s", config_path);
59 int config_status = swaynag_load_config(config_path, &swaynag, types); 52 status = swaynag_load_config(config_path, &swaynag, types);
60 free(config_path); 53 if (status != 0) {
61 if (config_status != 0) {
62 exit_code = config_status;
63 goto cleanup; 54 goto cleanup;
64 } 55 }
65 } 56 }
66 57
58
67 if (argc > 1) { 59 if (argc > 1) {
68 struct swaynag_type *type_args = swaynag_type_new("<args>"); 60 struct swaynag_type *type_args = swaynag_type_new("<args>");
69 list_add(types, type_args); 61 list_add(types, type_args);
70 62
71 int result = swaynag_parse_options(argc, argv, &swaynag, types, 63 status = swaynag_parse_options(argc, argv, &swaynag, types,
72 type_args, NULL, NULL); 64 type_args, NULL, NULL);
73 if (result != 0) { 65 if (status != 0) {
74 exit_code = result;
75 goto cleanup; 66 goto cleanup;
76 } 67 }
77 } 68 }
78 69
79 if (!swaynag.message) { 70 if (!swaynag.message) {
80 sway_log(SWAY_ERROR, "No message passed. Please provide --message/-m"); 71 sway_log(SWAY_ERROR, "No message passed. Please provide --message/-m");
81 exit_code = EXIT_FAILURE; 72 status = EXIT_FAILURE;
82 goto cleanup; 73 goto cleanup;
83 } 74 }
84 75
@@ -96,20 +87,20 @@ int main(int argc, char **argv) {
96 swaynag_type_merge(type, swaynag_type_get(types, "<args>")); 87 swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
97 swaynag.type = type; 88 swaynag.type = type;
98 89
99 swaynag_types_free(types);
100
101 if (swaynag.details.message) { 90 if (swaynag.details.message) {
91 swaynag.details.button_details = calloc(1, sizeof(struct swaynag_button));
92 swaynag.details.button_details->text = strdup(swaynag.details.details_text);
93 swaynag.details.button_details->type = SWAYNAG_ACTION_EXPAND;
102 list_add(swaynag.buttons, swaynag.details.button_details); 94 list_add(swaynag.buttons, swaynag.details.button_details);
103 } else {
104 free(swaynag.details.button_details->text);
105 free(swaynag.details.button_details);
106 } 95 }
107 96
108 sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output); 97 sway_log(SWAY_DEBUG, "Output: %s", swaynag.type->output);
109 sway_log(SWAY_DEBUG, "Anchors: %" PRIu32, swaynag.type->anchors); 98 sway_log(SWAY_DEBUG, "Anchors: %" PRIu32, swaynag.type->anchors);
110 sway_log(SWAY_DEBUG, "Type: %s", swaynag.type->name); 99 sway_log(SWAY_DEBUG, "Type: %s", swaynag.type->name);
111 sway_log(SWAY_DEBUG, "Message: %s", swaynag.message); 100 sway_log(SWAY_DEBUG, "Message: %s", swaynag.message);
112 sway_log(SWAY_DEBUG, "Font: %s", swaynag.type->font); 101 char *font = pango_font_description_to_string(swaynag.type->font_description);
102 sway_log(SWAY_DEBUG, "Font: %s", font);
103 free(font);
113 sway_log(SWAY_DEBUG, "Buttons"); 104 sway_log(SWAY_DEBUG, "Buttons");
114 for (int i = 0; i < swaynag.buttons->length; i++) { 105 for (int i = 0; i < swaynag.buttons->length; i++) {
115 struct swaynag_button *button = swaynag.buttons->items[i]; 106 struct swaynag_button *button = swaynag.buttons->items[i];
@@ -120,12 +111,9 @@ int main(int argc, char **argv) {
120 111
121 swaynag_setup(&swaynag); 112 swaynag_setup(&swaynag);
122 swaynag_run(&swaynag); 113 swaynag_run(&swaynag);
123 return exit_code;
124 114
125cleanup: 115cleanup:
126 swaynag_types_free(types); 116 swaynag_types_free(types);
127 free(swaynag.details.button_details->text);
128 free(swaynag.details.button_details);
129 swaynag_destroy(&swaynag); 117 swaynag_destroy(&swaynag);
130 return exit_code; 118 return status;
131} 119}