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