}
------------------------
+=== Strip workspace numbers
+
+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
+order on the bar according to its number without displaying the number prefix.
+
+When +strip_workspace_numbers+ is set to +yes+, any workspace that has a name of
+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", ...
+
+The default is to display the full name within the workspace button.
+
+*Syntax*:
+----------------------------------
+strip_workspace_numbers <yes|no>
+----------------------------------
+
+*Example*:
+----------------------------
+bar {
+ strip_workspace_numbers yes
+}
+----------------------------
+
=== Binding Mode indicator
Specifies whether the current binding mode indicator should be shown or not.
struct xcb_color_strings_t colors;
bool disable_binding_mode_indicator;
bool disable_ws;
+ bool strip_ws_numbers;
char *bar_id;
char *command;
char *fontname;
struct i3_ws {
int num; /* The internal number of the ws */
- i3String *name; /* The name of the ws */
+ char *canonical_name; /* The true name of the ws according to the ipc */
+ i3String *name; /* The name of the ws that is displayed on the bar */
int name_width; /* The rendered width of the name */
bool visible; /* If the ws is currently visible on an output */
bool focused; /* If the ws is currently focused */
return 1;
}
+ if (!strcmp(cur_key, "strip_workspace_numbers")) {
+ DLOG("strip_workspace_numbers = %d\n", val);
+ config.strip_ws_numbers = val;
+ return 1;
+ }
+
if (!strcmp(cur_key, "verbose")) {
DLOG("verbose = %d\n", val);
config.verbose = val;
char *output_name;
if (!strcmp(params->cur_key, "name")) {
- /* Save the name */
- params->workspaces_walk->name = i3string_from_utf8_with_length((const char *)val, len);
+ const char *ws_name = (const char*)val;
+ params->workspaces_walk->canonical_name = strndup(ws_name, len);
+
+ if (config.strip_ws_numbers && params->workspaces_walk->num >= 0) {
+ /* Special case: strip off the workspace number */
+ static char ws_num[10];
+
+ snprintf(ws_num, sizeof(ws_num), "%d", params->workspaces_walk->num);
+
+ /* Calculate the length of the number str in the name */
+ int offset = strspn(ws_name, ws_num);
+
+ /* Also strip off the conventional ws name delimiter */
+ 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_utf8_with_length(ws_name + offset, len - offset)
+ : i3string_from_utf8(ws_num));
+
+ } else {
+ /* Default case: just save the name */
+ params->workspaces_walk->name = i3string_from_utf8_with_length(ws_name, len);
+ }
/* Save its rendered width */
params->workspaces_walk->name_width =
predict_text_width(params->workspaces_walk->name);
- DLOG("Got Workspace %s, name_width: %d, glyphs: %zu\n",
+ DLOG("Got Workspace canonical: %s, name: '%s', name_width: %d, glyphs: %zu\n",
+ params->workspaces_walk->canonical_name,
i3string_as_utf8(params->workspaces_walk->name),
params->workspaces_walk->name_width,
i3string_get_num_glyphs(params->workspaces_walk->name));
if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) {
TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
I3STRING_FREE(ws_walk->name);
+ FREE(ws_walk->canonical_name);
}
FREE_TAILQ(outputs_walk->workspaces, i3_ws);
}
* buffer, then we copy character by character. */
int num_quotes = 0;
size_t namelen = 0;
- const char *utf8_name = i3string_as_utf8(cur_ws->name);
+ const char *utf8_name = cur_ws->canonical_name;
for (const char *walk = utf8_name; *walk != '\0'; walk++) {
if (*walk == '"')
num_quotes++;
* zero. */
bool hide_workspace_buttons;
+ /** Strip workspace numbers? Configuration option is
+ * 'strip_workspace_numbers yes'. */
+ bool strip_workspace_numbers;
+
/** 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;
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_finish);
'font' -> BAR_FONT
'binding_mode_indicator' -> BAR_BINDING_MODE_INDICATOR
'workspace_buttons' -> BAR_WORKSPACE_BUTTONS
+ 'strip_workspace_numbers' -> BAR_STRIP_WORKSPACE_NUMBERS
'verbose' -> BAR_VERBOSE
'colors' -> BAR_COLORS_BRACE
'}'
value = word
-> call cfg_bar_workspace_buttons($value); BAR
+state BAR_STRIP_WORKSPACE_NUMBERS:
+ value = word
+ -> call cfg_bar_strip_workspace_numbers($value); BAR
+
state BAR_VERBOSE:
value = word
-> call cfg_bar_verbose($value); BAR
current_bar.hide_workspace_buttons = !eval_boolstr(value);
}
+CFGFUN(bar_strip_workspace_numbers, const char *value) {
+ current_bar.strip_workspace_numbers = eval_boolstr(value);
+}
+
CFGFUN(bar_finish) {
DLOG("\t new bar configuration finished, saving.\n");
/* Generate a unique ID for this bar if not already configured */
ystr("workspace_buttons");
y(bool, !config->hide_workspace_buttons);
+ ystr("strip_workspace_numbers");
+ y(bool, config->strip_workspace_numbers);
+
ystr("binding_mode_indicator");
y(bool, !config->hide_binding_mode_indicator);
$expected = <<'EOT';
cfg_bar_output(LVDS-1)
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'binding_mode_indicator', 'workspace_buttons', 'verbose', 'colors', '}'
+ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'verbose', 'colors', '}'
ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: bar {
ERROR: CONFIG: Line 2: output LVDS-1