|
|
@ -1,6 +1,10 @@
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "status_line.h"
|
|
|
|
#include "status_line.h"
|
|
|
|
#include "state.h"
|
|
|
|
#include "state.h"
|
|
|
@ -18,13 +22,64 @@ struct swaybar_state *init_state() {
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_workspace(void *item) {
|
|
|
|
void free_workspaces(list_t *workspaces) {
|
|
|
|
if (!item) {
|
|
|
|
int i;
|
|
|
|
return;
|
|
|
|
for (i = 0; i < workspaces->length; ++i) {
|
|
|
|
}
|
|
|
|
struct workspace *ws = workspaces->items[i];
|
|
|
|
struct workspace *ws = (struct workspace *)item;
|
|
|
|
|
|
|
|
if (ws->name) {
|
|
|
|
|
|
|
|
free(ws->name);
|
|
|
|
free(ws->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ws);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|