|
|
@ -23,6 +23,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
struct sway_config *config = NULL;
|
|
|
|
struct sway_config *config = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void terminate_swaybar(pid_t pid);
|
|
|
|
|
|
|
|
|
|
|
|
static void free_variable(struct sway_variable *var) {
|
|
|
|
static void free_variable(struct sway_variable *var) {
|
|
|
|
free(var->name);
|
|
|
|
free(var->name);
|
|
|
|
free(var->value);
|
|
|
|
free(var->value);
|
|
|
@ -60,6 +62,11 @@ static void free_bar(struct bar_config *bar) {
|
|
|
|
if (bar->outputs) {
|
|
|
|
if (bar->outputs) {
|
|
|
|
free_flat_list(bar->outputs);
|
|
|
|
free_flat_list(bar->outputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bar->pid != 0) {
|
|
|
|
|
|
|
|
terminate_swaybar(bar->pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
free(bar);
|
|
|
|
free(bar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -471,32 +478,23 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i) {
|
|
|
|
static void invoke_swaybar(struct bar_config *bar) {
|
|
|
|
sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, output_i, bar->id);
|
|
|
|
bar->pid = fork();
|
|
|
|
|
|
|
|
if (bar->pid == 0) {
|
|
|
|
size_t bufsize = 4;
|
|
|
|
|
|
|
|
char output_id[bufsize];
|
|
|
|
|
|
|
|
snprintf(output_id, bufsize, "%d", output_i);
|
|
|
|
|
|
|
|
output_id[bufsize-1] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pid_t *pid = malloc(sizeof(pid_t));
|
|
|
|
|
|
|
|
*pid = fork();
|
|
|
|
|
|
|
|
if (*pid == 0) {
|
|
|
|
|
|
|
|
if (!bar->swaybar_command) {
|
|
|
|
if (!bar->swaybar_command) {
|
|
|
|
char *const cmd[] = {
|
|
|
|
char *const cmd[] = {
|
|
|
|
"swaybar",
|
|
|
|
"swaybar",
|
|
|
|
"-b",
|
|
|
|
"-b",
|
|
|
|
bar->id,
|
|
|
|
bar->id,
|
|
|
|
output_id,
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
execvp(cmd[0], cmd);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// run custom swaybar
|
|
|
|
// run custom swaybar
|
|
|
|
int len = strlen(bar->swaybar_command) + strlen(bar->id) + strlen(output_id) + 6;
|
|
|
|
int len = strlen(bar->swaybar_command) + strlen(bar->id) + 5;
|
|
|
|
char *command = malloc(len * sizeof(char));
|
|
|
|
char *command = malloc(len * sizeof(char));
|
|
|
|
snprintf(command, len, "%s -b %s %s", bar->swaybar_command, bar->id, output_id);
|
|
|
|
snprintf(command, len, "%s -b %s", bar->swaybar_command, bar->id);
|
|
|
|
|
|
|
|
|
|
|
|
char *const cmd[] = {
|
|
|
|
char *const cmd[] = {
|
|
|
|
"sh",
|
|
|
|
"sh",
|
|
|
@ -509,30 +507,15 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i
|
|
|
|
free(command);
|
|
|
|
free(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add swaybar pid to output
|
|
|
|
|
|
|
|
list_add(output->bar_pids, pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void terminate_swaybars(list_t *pids) {
|
|
|
|
static void terminate_swaybar(pid_t pid) {
|
|
|
|
int i, ret;
|
|
|
|
int ret = kill(pid, SIGTERM);
|
|
|
|
pid_t *pid;
|
|
|
|
if (ret != 0) {
|
|
|
|
for (i = 0; i < pids->length; ++i) {
|
|
|
|
sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", pid);
|
|
|
|
pid = pids->items[i];
|
|
|
|
} else {
|
|
|
|
ret = kill(*pid, SIGTERM);
|
|
|
|
int status;
|
|
|
|
if (ret != 0) {
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", *pid);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
waitpid(*pid, &status, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// empty pids list
|
|
|
|
|
|
|
|
for (i = 0; i < pids->length; ++i) {
|
|
|
|
|
|
|
|
pid = pids->items[i];
|
|
|
|
|
|
|
|
list_del(pids, i);
|
|
|
|
|
|
|
|
free(pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -546,7 +529,7 @@ void terminate_swaybg(pid_t pid) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void load_swaybars(swayc_t *output, int output_idx) {
|
|
|
|
void load_swaybars(swayc_t *output) {
|
|
|
|
// Check for bars
|
|
|
|
// Check for bars
|
|
|
|
list_t *bars = create_list();
|
|
|
|
list_t *bars = create_list();
|
|
|
|
struct bar_config *bar = NULL;
|
|
|
|
struct bar_config *bar = NULL;
|
|
|
@ -571,13 +554,13 @@ void load_swaybars(swayc_t *output, int output_idx) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// terminate swaybar processes previously spawned for this
|
|
|
|
|
|
|
|
// output.
|
|
|
|
|
|
|
|
terminate_swaybars(output->bar_pids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < bars->length; ++i) {
|
|
|
|
for (i = 0; i < bars->length; ++i) {
|
|
|
|
bar = bars->items[i];
|
|
|
|
bar = bars->items[i];
|
|
|
|
invoke_swaybar(output, bar, output_idx);
|
|
|
|
if (bar->pid != 0) {
|
|
|
|
|
|
|
|
terminate_swaybar(bar->pid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Invoking swaybar for output %s and bar '%s'", output->name, bar->id);
|
|
|
|
|
|
|
|
invoke_swaybar(bar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
list_free(bars);
|
|
|
|
list_free(bars);
|
|
|
@ -701,7 +684,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// load swaybars for output
|
|
|
|
// load swaybars for output
|
|
|
|
load_swaybars(output, output_i);
|
|
|
|
load_swaybars(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *do_var_replacement(char *str) {
|
|
|
|
char *do_var_replacement(char *str) {
|
|
|
@ -889,6 +872,7 @@ struct bar_config *default_bar_config(void) {
|
|
|
|
bar->strip_workspace_numbers = false;
|
|
|
|
bar->strip_workspace_numbers = false;
|
|
|
|
bar->binding_mode_indicator = true;
|
|
|
|
bar->binding_mode_indicator = true;
|
|
|
|
bar->tray_padding = 2;
|
|
|
|
bar->tray_padding = 2;
|
|
|
|
|
|
|
|
bar->pid = 0;
|
|
|
|
// set default colors
|
|
|
|
// set default colors
|
|
|
|
strcpy(bar->colors.background, "#000000ff");
|
|
|
|
strcpy(bar->colors.background, "#000000ff");
|
|
|
|
strcpy(bar->colors.statusline, "#ffffffff");
|
|
|
|
strcpy(bar->colors.statusline, "#ffffffff");
|
|
|
|