aboutsummaryrefslogtreecommitdiff
path: root/swaybar/ipc.c
diff options
context:
space:
mode:
authorConnor E <38229097+c-edw@users.noreply.github.com>2018-11-17 16:11:28 +0000
committerConnor E <38229097+c-edw@users.noreply.github.com>2018-11-17 16:11:28 +0000
commit4bd46fb079fb5a32ee6eb2b297de273b261a9c71 (patch)
tree81dfd95a863ae17de78a6c69a14dd5698c6de862 /swaybar/ipc.c
parent001ec1f3fdd700c23fb6dc91018697130af225ff (diff)
Implement strip_workspace_name.
Diffstat (limited to 'swaybar/ipc.c')
-rw-r--r--swaybar/ipc.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 706f968d..db4360c1 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -153,9 +153,10 @@ static bool ipc_parse_config(
return false;
}
json_object *markup, *mode, *hidden_state, *position, *status_command;
- json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
- json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
- json_object *bindings;
+ json_object *font, *bar_height, *wrap_scroll, *workspace_buttons;
+ json_object *strip_workspace_numbers, *strip_workspace_name;
+ json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol;
+ json_object *outputs, *bindings;
json_object_object_get_ex(bar_config, "mode", &mode);
json_object_object_get_ex(bar_config, "hidden_state", &hidden_state);
json_object_object_get_ex(bar_config, "position", &position);
@@ -165,6 +166,7 @@ static bool ipc_parse_config(
json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll);
json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons);
json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers);
+ json_object_object_get_ex(bar_config, "strip_workspace_name", &strip_workspace_name);
json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator);
json_object_object_get_ex(bar_config, "verbose", &verbose);
json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol);
@@ -190,6 +192,9 @@ static bool ipc_parse_config(
if (strip_workspace_numbers) {
config->strip_workspace_numbers = json_object_get_boolean(strip_workspace_numbers);
}
+ if (strip_workspace_name) {
+ config->strip_workspace_name = json_object_get_boolean(strip_workspace_name);
+ }
if (binding_mode_indicator) {
config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator);
}
@@ -298,6 +303,24 @@ bool ipc_get_workspaces(struct swaybar *bar) {
calloc(1, sizeof(struct swaybar_workspace));
ws->num = json_object_get_int(num);
ws->name = strdup(json_object_get_string(name));
+ ws->label = strdup(ws->name);
+ // ws->num will be -1 if workspace name doesn't begin with int.
+ if (ws->num != -1) {
+ size_t len_offset = numlen(ws->num);
+ if (bar->config->strip_workspace_name) {
+ free(ws->label);
+ ws->label = malloc(len_offset + 1 * sizeof(char));
+ ws->label[len_offset] = '\0';
+ strncpy(ws->label, ws->name, len_offset);
+ } else if (bar->config->strip_workspace_numbers) {
+ len_offset += ws->label[len_offset] == ':';
+ if (strlen(ws->name) > len_offset) {
+ free(ws->label);
+ // Strip number prefix [1-?:] using len_offset.
+ ws->label = strdup(ws->name + len_offset);
+ }
+ }
+ }
ws->visible = json_object_get_boolean(visible);
ws->focused = json_object_get_boolean(focused);
if (ws->focused) {