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

@ -16,6 +16,17 @@ struct box_colors {
uint32_t text; uint32_t text;
}; };
enum display_mode_types {
MODE_HIDE,
MODE_DOCK,
MODE_INVISIBLE
};
enum hidden_states {
BAR_HIDDEN,
BAR_SHOW
};
/** /**
* Swaybar config. * Swaybar config.
*/ */
@ -26,8 +37,8 @@ struct config {
char *font; char *font;
char *sep_symbol; char *sep_symbol;
char *mode; char *mode;
char *display_mode; enum display_mode_types display_mode;
char *hidden_state; enum hidden_states hidden_state;
bool strip_workspace_numbers; bool strip_workspace_numbers;
bool binding_mode_indicator; bool binding_mode_indicator;
bool wrap_scroll; bool wrap_scroll;
@ -64,6 +75,16 @@ uint32_t parse_position(const char *position);
*/ */
char *parse_font(const char *font); char *parse_font(const char *font);
/**
* Parse display mode dock|hide|invisible.
*/
enum display_mode_types parse_display_mode(const char *display_mode);
/**
* Parse hidden state show|hide.
*/
enum hidden_states parse_hidden_state(const char *hidden_state);
/** /**
* Initialize default sway config. * Initialize default sway config.
*/ */

View file

@ -68,7 +68,6 @@ static void free_bar(struct bar_config *bar) {
return; return;
} }
free(bar->display_mode); free(bar->display_mode);
free(bar->mode);
free(bar->hidden_state); free(bar->hidden_state);
free(bar->status_command); free(bar->status_command);
free(bar->font); free(bar->font);
@ -1337,7 +1336,6 @@ struct bar_config *default_bar_config(void) {
} }
if (!(bar->display_mode = strdup("dock"))) goto cleanup; if (!(bar->display_mode = strdup("dock"))) goto cleanup;
if (!(bar->hidden_state = strdup("hide"))) goto cleanup; if (!(bar->hidden_state = strdup("hide"))) goto cleanup;
bar->mode = NULL;
bar->modifier = WLC_BIT_MOD_LOGO; bar->modifier = WLC_BIT_MOD_LOGO;
bar->outputs = NULL; bar->outputs = NULL;
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;

View file

@ -352,11 +352,6 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(json, "id", json_object_new_string(bar->id)); json_object_object_add(json, "id", json_object_new_string(bar->id));
json_object_object_add(json, "tray_output", NULL); json_object_object_add(json, "tray_output", NULL);
json_object_object_add(json, "mode", json_object_new_string(bar->display_mode)); json_object_object_add(json, "mode", json_object_new_string(bar->display_mode));
if (!bar->mode) {
json_object_object_add(json, "binding_mode", json_object_new_string("default"));
} else {
json_object_object_add(json, "binding_mode", json_object_new_string(bar->mode));
}
json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state));
json_object_object_add(json, "modifier", json_object_new_string(get_modifier_name_by_mask(bar->modifier))); json_object_object_add(json, "modifier", json_object_new_string(get_modifier_name_by_mask(bar->modifier)));
switch (bar->position) { switch (bar->position) {

View file

@ -30,6 +30,28 @@ char *parse_font(const char *font) {
return new_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 *init_config() {
struct config *config = calloc(1, sizeof(struct config)); struct config *config = calloc(1, sizeof(struct config));
config->status_command = NULL; config->status_command = NULL;
@ -37,8 +59,8 @@ struct config *init_config() {
config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
config->font = strdup("monospace 10"); config->font = strdup("monospace 10");
config->mode = NULL; config->mode = NULL;
config->display_mode = NULL; config->display_mode = MODE_DOCK;
config->hidden_state = NULL; config->hidden_state = BAR_SHOW;
config->sep_symbol = NULL; config->sep_symbol = NULL;
config->strip_workspace_numbers = false; config->strip_workspace_numbers = false;
config->binding_mode_indicator = true; 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) { if (display_mode) {
free(config->display_mode); config->display_mode = parse_display_mode(strdup(json_object_get_string(display_mode)));
config->display_mode = strdup(json_object_get_string(display_mode));
} }
if (hidden_state) { if (hidden_state) {
free(config->hidden_state); config->hidden_state = parse_hidden_state(strdup(json_object_get_string(hidden_state)));
config->hidden_state = strdup(json_object_get_string(hidden_state));
} }
if (position) { if (position) {
@ -337,11 +335,15 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
json_object_put(outputs); json_object_put(outputs);
// Will need to be redone for display mode toggling compatibility // Will need to be redone for display mode toggling compatibility
// Will require setting bar->config->hidden_state to "show" as default // Will require setting bar->config->hidden_state to "show" as default
const char *subscribe_json = strcmp(bar->config->display_mode, "hide") == 0 ? json_object *subscribe_json = json_object_new_array();
"[ \"workspace\", \"mode\", \"modifier\" ]" json_object_array_add(subscribe_json, json_object_new_string("workspace"));
: "[ \"workspace\", \"mode\" ]"; json_object_array_add(subscribe_json, json_object_new_string("mode"));
len = strlen(subscribe_json); if (bar->config->display_mode == MODE_HIDE) {
res = ipc_single_command(bar->ipc_event_socketfd, IPC_SUBSCRIBE, subscribe_json, &len); 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); free(res);
ipc_update_workspaces(bar); ipc_update_workspaces(bar);
@ -390,11 +392,10 @@ bool handle_ipc_event(struct bar *bar) {
json_object *json_change; json_object *json_change;
if (json_object_object_get_ex(result, "change", &json_change)) { if (json_object_object_get_ex(result, "change", &json_change)) {
const char *change = json_object_get_string(json_change); const char *change = json_object_get_string(json_change);
free(bar->config->hidden_state);
if (strcmp(change, "pressed") == 0) { if (strcmp(change, "pressed") == 0) {
bar->config->hidden_state = strdup("show"); bar->config->hidden_state = BAR_SHOW;
} else { //must be "released" } else { //must be "released"
bar->config->hidden_state = strdup("hide"); bar->config->hidden_state = BAR_HIDDEN;
} }
} else { } else {

View file

@ -288,7 +288,7 @@ void render(struct output *output, struct config *config, struct status_line *li
cairo_restore(cairo); cairo_restore(cairo);
// Could also be done by always rendering then conditionally clearing and drawing alpha // Could also be done by always rendering then conditionally clearing and drawing alpha
// That may be preferable down the line // 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); cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);