From: hwangcc23 Date: Sat, 10 Mar 2018 04:49:09 +0000 (+0800) Subject: Add strip_workspace_name X-Git-Tag: 4.16~135^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F3167%2Fhead;p=i3%2Fi3 Add strip_workspace_name See the issue #3163 (https://github.com/i3/i3/issues/3163). Add strip_workspace_name to strip off the workspace name. --- diff --git a/docs/userguide b/docs/userguide index ba314af1..850b0351 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1594,7 +1594,7 @@ bar { } ------------------------ -=== Strip workspace numbers +=== Strip workspace numbers/name Specifies whether workspace numbers should be displayed within the workspace buttons. This is useful if you want to have a named workspace that stays in @@ -1605,11 +1605,15 @@ the form "[n]:[NAME]" will display only the name. You could use this, for instance, to display Roman numerals rather than digits by naming your workspaces to "1:I", "2:II", "3:III", "4:IV", ... +When +strip_workspace_name+ is set to +yes+, any workspace that has a name of +the form "[n]:[NAME]" will display only the number. + The default is to display the full name within the workspace button. *Syntax*: ------------------------------ strip_workspace_numbers yes|no +strip_workspace_name yes|no ------------------------------ *Example*: diff --git a/i3bar/include/configuration.h b/i3bar/include/configuration.h index 61cac7f6..e60d7483 100644 --- a/i3bar/include/configuration.h +++ b/i3bar/include/configuration.h @@ -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; diff --git a/i3bar/src/config.c b/i3bar/src/config.c index a58b9bf8..59a44aee 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -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; diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index 23324989..7285d150 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -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); diff --git a/include/config_directives.h b/include/config_directives.h index 187b550c..852325ba 100644 --- a/include/config_directives.h +++ b/include/config_directives.h @@ -96,5 +96,6 @@ CFGFUN(bar_status_command, const char *command); CFGFUN(bar_binding_mode_indicator, const char *value); CFGFUN(bar_workspace_buttons, const char *value); CFGFUN(bar_strip_workspace_numbers, const char *value); +CFGFUN(bar_strip_workspace_name, const char *value); CFGFUN(bar_start); CFGFUN(bar_finish); diff --git a/include/configuration.h b/include/configuration.h index ac800159..87897aaf 100644 --- a/include/configuration.h +++ b/include/configuration.h @@ -331,6 +331,10 @@ struct Barconfig { * 'strip_workspace_numbers yes'. */ bool strip_workspace_numbers; + /** Strip workspace name? Configuration option is + * 'strip_workspace_name yes'. */ + bool strip_workspace_name; + /** Hide mode button? Configuration option is 'binding_mode_indicator no' * but we invert the bool for the same reason as hide_workspace_buttons.*/ bool hide_binding_mode_indicator; diff --git a/parser-specs/config.spec b/parser-specs/config.spec index 60a1fc67..9cbc782b 100644 --- a/parser-specs/config.spec +++ b/parser-specs/config.spec @@ -455,6 +455,7 @@ state BAR: 'binding_mode_indicator' -> BAR_BINDING_MODE_INDICATOR 'workspace_buttons' -> BAR_WORKSPACE_BUTTONS 'strip_workspace_numbers' -> BAR_STRIP_WORKSPACE_NUMBERS + 'strip_workspace_name' -> BAR_STRIP_WORKSPACE_NAME 'verbose' -> BAR_VERBOSE 'colors' -> BAR_COLORS_BRACE '}' @@ -555,6 +556,10 @@ state BAR_STRIP_WORKSPACE_NUMBERS: value = word -> call cfg_bar_strip_workspace_numbers($value); BAR +state BAR_STRIP_WORKSPACE_NAME: + value = word + -> call cfg_bar_strip_workspace_name($value); BAR + state BAR_VERBOSE: value = word -> call cfg_bar_verbose($value); BAR diff --git a/src/config_directives.c b/src/config_directives.c index ad6d65b5..da1fb580 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -627,6 +627,10 @@ CFGFUN(bar_strip_workspace_numbers, const char *value) { current_bar->strip_workspace_numbers = eval_boolstr(value); } +CFGFUN(bar_strip_workspace_name, const char *value) { + current_bar->strip_workspace_name = eval_boolstr(value); +} + CFGFUN(bar_start) { current_bar = scalloc(1, sizeof(struct Barconfig)); TAILQ_INIT(&(current_bar->bar_bindings)); diff --git a/src/ipc.c b/src/ipc.c index a1a72b1a..6b6383ec 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -709,6 +709,9 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) { ystr("strip_workspace_numbers"); y(bool, config->strip_workspace_numbers); + ystr("strip_workspace_name"); + y(bool, config->strip_workspace_name); + ystr("binding_mode_indicator"); y(bool, !config->hide_binding_mode_indicator); diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t index 6857b621..1e7ebfc4 100644 --- a/testcases/t/201-config-parser.t +++ b/testcases/t/201-config-parser.t @@ -725,7 +725,7 @@ EOT $expected = <<'EOT'; cfg_bar_start() cfg_bar_output(LVDS-1) -ERROR: CONFIG: Expected one of these tokens: , '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'tray_padding', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'verbose', 'colors', '}' +ERROR: CONFIG: Expected one of these tokens: , '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'tray_padding', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'strip_workspace_name', 'verbose', 'colors', '}' ERROR: CONFIG: (in file ) ERROR: CONFIG: Line 1: bar { ERROR: CONFIG: Line 2: output LVDS-1