aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config/bar.c')
-rw-r--r--sway/config/bar.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 5a97c3cc..3a74331e 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -16,10 +16,10 @@
16#include "log.h" 16#include "log.h"
17 17
18static void terminate_swaybar(pid_t pid) { 18static void terminate_swaybar(pid_t pid) {
19 wlr_log(L_DEBUG, "Terminating swaybar %d", pid); 19 wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid);
20 int ret = kill(-pid, SIGTERM); 20 int ret = kill(-pid, SIGTERM);
21 if (ret != 0) { 21 if (ret != 0) {
22 wlr_log_errno(L_ERROR, "Unable to terminate swaybar %d", pid); 22 wlr_log_errno(WLR_ERROR, "Unable to terminate swaybar %d", pid);
23 } else { 23 } else {
24 int status; 24 int status;
25 waitpid(pid, &status, 0); 25 waitpid(pid, &status, 0);
@@ -30,6 +30,7 @@ void free_bar_config(struct bar_config *bar) {
30 if (!bar) { 30 if (!bar) {
31 return; 31 return;
32 } 32 }
33 free(bar->id);
33 free(bar->mode); 34 free(bar->mode);
34 free(bar->position); 35 free(bar->position);
35 free(bar->hidden_state); 36 free(bar->hidden_state);
@@ -70,16 +71,12 @@ void free_bar_config(struct bar_config *bar) {
70 71
71struct bar_config *default_bar_config(void) { 72struct bar_config *default_bar_config(void) {
72 struct bar_config *bar = NULL; 73 struct bar_config *bar = NULL;
73 bar = malloc(sizeof(struct bar_config)); 74 bar = calloc(1, sizeof(struct bar_config));
74 if (!bar) { 75 if (!bar) {
75 return NULL; 76 return NULL;
76 } 77 }
77 if (!(bar->mode = strdup("dock"))) goto cleanup;
78 if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
79 bar->outputs = NULL; 78 bar->outputs = NULL;
80 bar->position = strdup("bottom"); 79 bar->position = strdup("bottom");
81 if (!(bar->bindings = create_list())) goto cleanup;
82 if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
83 bar->pango_markup = false; 80 bar->pango_markup = false;
84 bar->swaybar_command = NULL; 81 bar->swaybar_command = NULL;
85 bar->font = NULL; 82 bar->font = NULL;
@@ -91,6 +88,19 @@ struct bar_config *default_bar_config(void) {
91 bar->binding_mode_indicator = true; 88 bar->binding_mode_indicator = true;
92 bar->verbose = false; 89 bar->verbose = false;
93 bar->pid = 0; 90 bar->pid = 0;
91 if (!(bar->mode = strdup("dock"))) {
92 goto cleanup;
93 }
94 if (!(bar->hidden_state = strdup("hide"))) {
95 goto cleanup;
96 }
97 if (!(bar->bindings = create_list())) {
98 goto cleanup;
99 }
100 if (!(bar->status_command =
101 strdup("while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done"))) {
102 goto cleanup;
103 }
94 // set default colors 104 // set default colors
95 if (!(bar->colors.background = strndup("#000000ff", 9))) { 105 if (!(bar->colors.background = strndup("#000000ff", 9))) {
96 goto cleanup; 106 goto cleanup;
@@ -157,7 +167,7 @@ void invoke_swaybar(struct bar_config *bar) {
157 // Pipe to communicate errors 167 // Pipe to communicate errors
158 int filedes[2]; 168 int filedes[2];
159 if (pipe(filedes) == -1) { 169 if (pipe(filedes) == -1) {
160 wlr_log(L_ERROR, "Pipe setup failed! Cannot fork into bar"); 170 wlr_log(WLR_ERROR, "Pipe setup failed! Cannot fork into bar");
161 return; 171 return;
162 } 172 }
163 173
@@ -174,7 +184,7 @@ void invoke_swaybar(struct bar_config *bar) {
174 if (!command) { 184 if (!command) {
175 const char msg[] = "Unable to allocate swaybar command string"; 185 const char msg[] = "Unable to allocate swaybar command string";
176 size_t msg_len = sizeof(msg); 186 size_t msg_len = sizeof(msg);
177 if (write(filedes[1], &msg_len, sizeof(int))) {}; 187 if (write(filedes[1], &msg_len, sizeof(size_t))) {};
178 if (write(filedes[1], msg, msg_len)) {}; 188 if (write(filedes[1], msg, msg_len)) {};
179 close(filedes[1]); 189 close(filedes[1]);
180 exit(1); 190 exit(1);
@@ -187,17 +197,17 @@ void invoke_swaybar(struct bar_config *bar) {
187 execvp(cmd[0], cmd); 197 execvp(cmd[0], cmd);
188 exit(1); 198 exit(1);
189 } 199 }
190 wlr_log(L_DEBUG, "Spawned swaybar %d", bar->pid); 200 wlr_log(WLR_DEBUG, "Spawned swaybar %d", bar->pid);
191 close(filedes[0]); 201 close(filedes[0]);
192 ssize_t len; 202 size_t len;
193 if (read(filedes[1], &len, sizeof(int)) == sizeof(int)) { 203 if (read(filedes[1], &len, sizeof(size_t)) == sizeof(size_t)) {
194 char *buf = malloc(len); 204 char *buf = malloc(len);
195 if(!buf) { 205 if(!buf) {
196 wlr_log(L_ERROR, "Cannot allocate error string"); 206 wlr_log(WLR_ERROR, "Cannot allocate error string");
197 return; 207 return;
198 } 208 }
199 if (read(filedes[1], buf, len)) { 209 if (read(filedes[1], buf, len)) {
200 wlr_log(L_ERROR, "%s", buf); 210 wlr_log(WLR_ERROR, "%s", buf);
201 } 211 }
202 free(buf); 212 free(buf);
203 } 213 }
@@ -234,7 +244,7 @@ void load_swaybars() {
234 if (bar->pid != 0) { 244 if (bar->pid != 0) {
235 terminate_swaybar(bar->pid); 245 terminate_swaybar(bar->pid);
236 } 246 }
237 wlr_log(L_DEBUG, "Invoking swaybar for bar id '%s'", bar->id); 247 wlr_log(WLR_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
238 invoke_swaybar(bar); 248 invoke_swaybar(bar);
239 } 249 }
240 } 250 }