aboutsummaryrefslogtreecommitdiff
path: root/swaybar/state.c
diff options
context:
space:
mode:
authorMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-24 01:03:08 +0100
committerMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-24 14:22:19 +0100
commit6140f9c42c4f09142d647c96236cc030689e6f34 (patch)
tree2958848d61b10e20dfa9d4f5cd9188d384be0029 /swaybar/state.c
parentfcc47cb3bddd20a2fd068a4e486415112e4d4d20 (diff)
swaybar: Move swaybar_teardown to free_state
Diffstat (limited to 'swaybar/state.c')
-rw-r--r--swaybar/state.c69
1 files changed, 62 insertions, 7 deletions
diff --git a/swaybar/state.c b/swaybar/state.c
index 77427555..26cdcafe 100644
--- a/swaybar/state.c
+++ b/swaybar/state.c
@@ -1,6 +1,10 @@
#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include "list.h"
+#include "log.h"
#include "config.h"
#include "status_line.h"
#include "state.h"
@@ -18,13 +22,64 @@ struct swaybar_state *init_state() {
return state;
}
-void free_workspace(void *item) {
- if (!item) {
- return;
- }
- struct workspace *ws = (struct workspace *)item;
- if (ws->name) {
+void free_workspaces(list_t *workspaces) {
+ int i;
+ for (i = 0; i < workspaces->length; ++i) {
+ struct workspace *ws = workspaces->items[i];
free(ws->name);
+ free(ws);
+ }
+ list_free(workspaces);
+}
+
+static void free_output(struct output *output) {
+ window_teardown(output->window);
+ if (output->registry) {
+ registry_teardown(output->registry);
+ }
+
+ free(output->name);
+
+ if (output->workspaces) {
+ free_workspaces(output->workspaces);
+ }
+
+ free(output);
+}
+
+static void terminate_status_command(pid_t pid) {
+ if (pid) {
+ // terminate status_command process
+ int ret = kill(pid, SIGTERM);
+ if (ret != 0) {
+ sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid);
+ } else {
+ int status;
+ waitpid(pid, &status, 0);
+ }
}
- free(ws);
+}
+
+void free_state(struct swaybar_state *state) {
+ free_config(state->config);
+ free_output(state->output);
+ free_status_line(state->status);
+
+ /* close sockets/pipes */
+ if (state->status_read_fd) {
+ close(state->status_read_fd);
+ }
+
+ if (state->ipc_socketfd) {
+ close(state->ipc_socketfd);
+ }
+
+ if (state->ipc_event_socketfd) {
+ close(state->ipc_event_socketfd);
+ }
+
+ /* terminate status command process */
+ terminate_status_command(state->status_command_pid);
+
+ free(state);
}