remove binding mode from sway side. switch from strings to enums on swaybar side

This commit is contained in:
Calvin Kosmatka 2017-04-16 23:34:27 -05:00
parent b23fd02fb6
commit 0dc55dda6a
6 changed files with 61 additions and 24 deletions

View file

@ -30,6 +30,28 @@ char *parse_font(const char *font) {
return new_font;
}
enum display_mode_types parse_display_mode(const char *display_mode) {
if (strcmp("hide", display_mode) == 0) {
return MODE_HIDE;
} else if (strcmp("dock", display_mode) == 0) {
return MODE_DOCK;
} else if (strcmp("invisible", display_mode) == 0) {
return MODE_INVISIBLE;
} else {
return MODE_DOCK;
}
}
enum hidden_states parse_hidden_state(const char *hidden_state) {
if (strcmp("show", hidden_state) == 0) {
return BAR_SHOW;
} else if (strcmp("hide", hidden_state) == 0) {
return BAR_HIDDEN;
} else {
return BAR_SHOW;
}
}
struct config *init_config() {
struct config *config = calloc(1, sizeof(struct config));
config->status_command = NULL;
@ -37,8 +59,8 @@ struct config *init_config() {
config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
config->font = strdup("monospace 10");
config->mode = NULL;
config->display_mode = NULL;
config->hidden_state = NULL;
config->display_mode = MODE_DOCK;
config->hidden_state = BAR_SHOW;
config->sep_symbol = NULL;
config->strip_workspace_numbers = false;
config->binding_mode_indicator = true;

View file

@ -49,13 +49,11 @@ static void ipc_parse_config(struct config *config, const char *payload) {
}
if (display_mode) {
free(config->display_mode);
config->display_mode = strdup(json_object_get_string(display_mode));
config->display_mode = parse_display_mode(strdup(json_object_get_string(display_mode)));
}
if (hidden_state) {
free(config->hidden_state);
config->hidden_state = strdup(json_object_get_string(hidden_state));
config->hidden_state = parse_hidden_state(strdup(json_object_get_string(hidden_state)));
}
if (position) {
@ -337,11 +335,15 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
json_object_put(outputs);
// Will need to be redone for display mode toggling compatibility
// Will require setting bar->config->hidden_state to "show" as default
const char *subscribe_json = strcmp(bar->config->display_mode, "hide") == 0 ?
"[ \"workspace\", \"mode\", \"modifier\" ]"
: "[ \"workspace\", \"mode\" ]";
len = strlen(subscribe_json);
res = ipc_single_command(bar->ipc_event_socketfd, IPC_SUBSCRIBE, subscribe_json, &len);
json_object *subscribe_json = json_object_new_array();
json_object_array_add(subscribe_json, json_object_new_string("workspace"));
json_object_array_add(subscribe_json, json_object_new_string("mode"));
if (bar->config->display_mode == MODE_HIDE) {
json_object_array_add(subscribe_json, json_object_new_string("modifier"));
}
const char *subscribe_json_string = json_object_to_json_string(subscribe_json);
len = strlen(subscribe_json_string);
res = ipc_single_command(bar->ipc_event_socketfd, IPC_SUBSCRIBE, subscribe_json_string, &len);
free(res);
ipc_update_workspaces(bar);
@ -390,11 +392,10 @@ bool handle_ipc_event(struct bar *bar) {
json_object *json_change;
if (json_object_object_get_ex(result, "change", &json_change)) {
const char *change = json_object_get_string(json_change);
free(bar->config->hidden_state);
if (strcmp(change, "pressed") == 0) {
bar->config->hidden_state = strdup("show");
bar->config->hidden_state = BAR_SHOW;
} else { //must be "released"
bar->config->hidden_state = strdup("hide");
bar->config->hidden_state = BAR_HIDDEN;
}
} else {

View file

@ -288,7 +288,7 @@ void render(struct output *output, struct config *config, struct status_line *li
cairo_restore(cairo);
// Could also be done by always rendering then conditionally clearing and drawing alpha
// That may be preferable down the line
if ((!strcmp(config->display_mode, "hide")) == 0 || strcmp(config->hidden_state, "show") == 0) {
if ((!config->display_mode == MODE_HIDE) || config->hidden_state == BAR_SHOW) {
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);