Merge pull request #3167 from hwangcc23/fix-3163

Add strip_workspace_name
This commit is contained in:
Ingo Bürk
2018-03-11 16:33:10 +01:00
committed by GitHub
10 changed files with 40 additions and 9 deletions

View File

@ -52,6 +52,7 @@ typedef struct config_t {
bool disable_binding_mode_indicator;
bool disable_ws;
bool strip_ws_numbers;
bool strip_ws_name;
char *bar_id;
char *command;
char *fontname;

View File

@ -297,6 +297,12 @@ static int config_boolean_cb(void *params_, int val) {
return 1;
}
if (!strcmp(cur_key, "strip_workspace_name")) {
DLOG("strip_workspace_name = %d\n", val);
config.strip_ws_name = val;
return 1;
}
if (!strcmp(cur_key, "verbose")) {
DLOG("verbose = %d\n", val);
config.verbose = val;

View File

@ -106,8 +106,8 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, size_t
const char *ws_name = (const char *)val;
params->workspaces_walk->canonical_name = sstrndup(ws_name, len);
if (config.strip_ws_numbers && params->workspaces_walk->num >= 0) {
/* Special case: strip off the workspace number */
if ((config.strip_ws_numbers || config.strip_ws_name) && params->workspaces_walk->num >= 0) {
/* Special case: strip off the workspace number/name */
static char ws_num[10];
snprintf(ws_num, sizeof(ws_num), "%d", params->workspaces_walk->num);
@ -119,11 +119,14 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, size_t
if (offset && ws_name[offset] == ':')
offset += 1;
/* Offset may be equal to length, in which case display the number */
params->workspaces_walk->name = (offset < len
? i3string_from_markup_with_length(ws_name + offset, len - offset)
: i3string_from_markup(ws_num));
if (config.strip_ws_numbers) {
/* Offset may be equal to length, in which case display the number */
params->workspaces_walk->name = (offset < len
? i3string_from_markup_with_length(ws_name + offset, len - offset)
: i3string_from_markup(ws_num));
} else {
params->workspaces_walk->name = i3string_from_markup(ws_num);
}
} else {
/* Default case: just save the name */
params->workspaces_walk->name = i3string_from_markup_with_length(ws_name, len);