|
|
@ -11,7 +11,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|
|
|
json_object *bar_config = json_tokener_parse(payload);
|
|
|
|
json_object *bar_config = json_tokener_parse(payload);
|
|
|
|
json_object *tray_output, *mode, *hidden_bar, *position, *status_command;
|
|
|
|
json_object *tray_output, *mode, *hidden_bar, *position, *status_command;
|
|
|
|
json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers;
|
|
|
|
json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers;
|
|
|
|
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol;
|
|
|
|
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
|
|
|
|
json_object_object_get_ex(bar_config, "tray_output", &tray_output);
|
|
|
|
json_object_object_get_ex(bar_config, "tray_output", &tray_output);
|
|
|
|
json_object_object_get_ex(bar_config, "mode", &mode);
|
|
|
|
json_object_object_get_ex(bar_config, "mode", &mode);
|
|
|
|
json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar);
|
|
|
|
json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar);
|
|
|
@ -25,6 +25,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|
|
|
json_object_object_get_ex(bar_config, "verbose", &verbose);
|
|
|
|
json_object_object_get_ex(bar_config, "verbose", &verbose);
|
|
|
|
json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol);
|
|
|
|
json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol);
|
|
|
|
json_object_object_get_ex(bar_config, "colors", &colors);
|
|
|
|
json_object_object_get_ex(bar_config, "colors", &colors);
|
|
|
|
|
|
|
|
json_object_object_get_ex(bar_config, "outputs", &outputs);
|
|
|
|
|
|
|
|
|
|
|
|
if (status_command) {
|
|
|
|
if (status_command) {
|
|
|
|
free(config->status_command);
|
|
|
|
free(config->status_command);
|
|
|
@ -61,6 +62,28 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|
|
|
config->height = json_object_get_int(bar_height);
|
|
|
|
config->height = json_object_get_int(bar_height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// free previous outputs list
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < config->outputs->length; ++i) {
|
|
|
|
|
|
|
|
free(config->outputs->items[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
list_free(config->outputs);
|
|
|
|
|
|
|
|
config->outputs = create_list();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (outputs) {
|
|
|
|
|
|
|
|
int length = json_object_array_length(outputs);
|
|
|
|
|
|
|
|
json_object *output;
|
|
|
|
|
|
|
|
const char *output_str;
|
|
|
|
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
|
|
|
|
output = json_object_array_get_idx(outputs, i);
|
|
|
|
|
|
|
|
output_str = json_object_get_string(output);
|
|
|
|
|
|
|
|
if (strcmp("*", output_str) == 0) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(config->outputs, strdup(output_str));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (colors) {
|
|
|
|
if (colors) {
|
|
|
|
json_object *background, *statusline, *separator;
|
|
|
|
json_object *background, *statusline, *separator;
|
|
|
|
json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text;
|
|
|
|
json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text;
|
|
|
@ -151,10 +174,14 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ipc_update_workspaces(struct bar *bar) {
|
|
|
|
static void ipc_update_workspaces(struct bar *bar) {
|
|
|
|
if (bar->output->workspaces) {
|
|
|
|
int i;
|
|
|
|
free_workspaces(bar->output->workspaces);
|
|
|
|
for (i = 0; i < bar->outputs->length; ++i) {
|
|
|
|
|
|
|
|
struct output *output = bar->outputs->items[i];
|
|
|
|
|
|
|
|
if (output->workspaces) {
|
|
|
|
|
|
|
|
free_workspaces(output->workspaces);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
output->workspaces = create_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bar->output->workspaces = create_list();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t len = 0;
|
|
|
|
uint32_t len = 0;
|
|
|
|
char *res = ipc_single_command(bar->ipc_socketfd, IPC_GET_WORKSPACES, NULL, &len);
|
|
|
|
char *res = ipc_single_command(bar->ipc_socketfd, IPC_GET_WORKSPACES, NULL, &len);
|
|
|
@ -164,7 +191,6 @@ static void ipc_update_workspaces(struct bar *bar) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int length = json_object_array_length(results);
|
|
|
|
int length = json_object_array_length(results);
|
|
|
|
json_object *ws_json;
|
|
|
|
json_object *ws_json;
|
|
|
|
json_object *num, *name, *visible, *focused, *out, *urgent;
|
|
|
|
json_object *num, *name, *visible, *focused, *out, *urgent;
|
|
|
@ -178,14 +204,18 @@ static void ipc_update_workspaces(struct bar *bar) {
|
|
|
|
json_object_object_get_ex(ws_json, "output", &out);
|
|
|
|
json_object_object_get_ex(ws_json, "output", &out);
|
|
|
|
json_object_object_get_ex(ws_json, "urgent", &urgent);
|
|
|
|
json_object_object_get_ex(ws_json, "urgent", &urgent);
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(json_object_get_string(out), bar->output->name) == 0) {
|
|
|
|
int j;
|
|
|
|
struct workspace *ws = malloc(sizeof(struct workspace));
|
|
|
|
for (j = 0; j < bar->outputs->length; ++j) {
|
|
|
|
ws->num = json_object_get_int(num);
|
|
|
|
struct output *output = bar->outputs->items[j];
|
|
|
|
ws->name = strdup(json_object_get_string(name));
|
|
|
|
if (strcmp(json_object_get_string(out), output->name) == 0) {
|
|
|
|
ws->visible = json_object_get_boolean(visible);
|
|
|
|
struct workspace *ws = malloc(sizeof(struct workspace));
|
|
|
|
ws->focused = json_object_get_boolean(focused);
|
|
|
|
ws->num = json_object_get_int(num);
|
|
|
|
ws->urgent = json_object_get_boolean(urgent);
|
|
|
|
ws->name = strdup(json_object_get_string(name));
|
|
|
|
list_add(bar->output->workspaces, ws);
|
|
|
|
ws->visible = json_object_get_boolean(visible);
|
|
|
|
|
|
|
|
ws->focused = json_object_get_boolean(focused);
|
|
|
|
|
|
|
|
ws->urgent = json_object_get_boolean(urgent);
|
|
|
|
|
|
|
|
list_add(output->workspaces, ws);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -193,22 +223,58 @@ static void ipc_update_workspaces(struct bar *bar) {
|
|
|
|
free(res);
|
|
|
|
free(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ipc_bar_init(struct bar *bar, int outputi, const char *bar_id) {
|
|
|
|
void ipc_bar_init(struct bar *bar, const char *bar_id) {
|
|
|
|
uint32_t len = 0;
|
|
|
|
// Get bar config
|
|
|
|
char *res = ipc_single_command(bar->ipc_socketfd, IPC_GET_OUTPUTS, NULL, &len);
|
|
|
|
uint32_t len = strlen(bar_id);
|
|
|
|
json_object *outputs = json_tokener_parse(res);
|
|
|
|
char *res = ipc_single_command(bar->ipc_socketfd, IPC_GET_BAR_CONFIG, bar_id, &len);
|
|
|
|
json_object *info = json_object_array_get_idx(outputs, outputi);
|
|
|
|
|
|
|
|
json_object *name;
|
|
|
|
ipc_parse_config(bar->config, res);
|
|
|
|
json_object_object_get_ex(info, "name", &name);
|
|
|
|
|
|
|
|
bar->output->name = strdup(json_object_get_string(name));
|
|
|
|
|
|
|
|
free(res);
|
|
|
|
free(res);
|
|
|
|
json_object_put(outputs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len = strlen(bar_id);
|
|
|
|
// Get outputs
|
|
|
|
res = ipc_single_command(bar->ipc_socketfd, IPC_GET_BAR_CONFIG, bar_id, &len);
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
res = ipc_single_command(bar->ipc_socketfd, IPC_GET_OUTPUTS, NULL, &len);
|
|
|
|
|
|
|
|
json_object *outputs = json_tokener_parse(res);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int length = json_object_array_length(outputs);
|
|
|
|
|
|
|
|
json_object *output, *output_name, *output_active;
|
|
|
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
|
|
|
|
output = json_object_array_get_idx(outputs, i);
|
|
|
|
|
|
|
|
json_object_object_get_ex(output, "name", &output_name);
|
|
|
|
|
|
|
|
json_object_object_get_ex(output, "active", &output_active);
|
|
|
|
|
|
|
|
name = json_object_get_string(output_name);
|
|
|
|
|
|
|
|
active = json_object_get_boolean(output_active);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ipc_parse_config(bar->config, res);
|
|
|
|
bool use_output = false;
|
|
|
|
|
|
|
|
if (bar->config->outputs->length == 0) {
|
|
|
|
|
|
|
|
use_output = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < bar->config->outputs->length; ++j) {
|
|
|
|
|
|
|
|
const char *conf_name = bar->config->outputs->items[i];
|
|
|
|
|
|
|
|
if (strcasecmp(name, conf_name) == 0) {
|
|
|
|
|
|
|
|
use_output = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!use_output) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add bar to the output
|
|
|
|
|
|
|
|
struct output *bar_output = new_output(name);
|
|
|
|
|
|
|
|
bar_output->idx = i;
|
|
|
|
|
|
|
|
list_add(bar->outputs, bar_output);
|
|
|
|
|
|
|
|
}
|
|
|
|
free(res);
|
|
|
|
free(res);
|
|
|
|
|
|
|
|
json_object_put(outputs);
|
|
|
|
|
|
|
|
|
|
|
|
const char *subscribe_json = "[ \"workspace\", \"mode\" ]";
|
|
|
|
const char *subscribe_json = "[ \"workspace\", \"mode\" ]";
|
|
|
|
len = strlen(subscribe_json);
|
|
|
|
len = strlen(subscribe_json);
|
|
|
|