]> git.sur5r.net Git - i3/i3/commitdiff
Add strip_workspace_name 3167/head
authorhwangcc23 <hwangcc@csie.nctu.edu.tw>
Sat, 10 Mar 2018 04:49:09 +0000 (12:49 +0800)
committerhwangcc23 <hwangcc@csie.nctu.edu.tw>
Sun, 11 Mar 2018 04:17:42 +0000 (12:17 +0800)
See the issue #3163 (https://github.com/i3/i3/issues/3163).

Add strip_workspace_name to strip off the workspace name.

docs/userguide
i3bar/include/configuration.h
i3bar/src/config.c
i3bar/src/workspaces.c
include/config_directives.h
include/configuration.h
parser-specs/config.spec
src/config_directives.c
src/ipc.c
testcases/t/201-config-parser.t

index ba314af111a62493477dad54d4f030d743fdd0b4..850b035134ce7ad9f5ebb83572da36e5aba177fa 100644 (file)
@@ -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
 
 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", ...
 
 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
 The default is to display the full name within the workspace button.
 
 *Syntax*:
 ------------------------------
 strip_workspace_numbers yes|no
+strip_workspace_name yes|no
 ------------------------------
 
 *Example*:
 ------------------------------
 
 *Example*:
index 61cac7f6bdcab344de7cbaaa9dfc5f1a8c4fc1f3..e60d74836c34aa33104ceffd29b74ddff4545bc4 100644 (file)
@@ -52,6 +52,7 @@ typedef struct config_t {
     bool disable_binding_mode_indicator;
     bool disable_ws;
     bool strip_ws_numbers;
     bool disable_binding_mode_indicator;
     bool disable_ws;
     bool strip_ws_numbers;
+    bool strip_ws_name;
     char *bar_id;
     char *command;
     char *fontname;
     char *bar_id;
     char *command;
     char *fontname;
index a58b9bf80c06b69425872bfe74eb69602a2d8215..59a44aee912b9a9b30ea99392cab662dda43dc03 100644 (file)
@@ -297,6 +297,12 @@ static int config_boolean_cb(void *params_, int val) {
         return 1;
     }
 
         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;
     if (!strcmp(cur_key, "verbose")) {
         DLOG("verbose = %d\n", val);
         config.verbose = val;
index 233249893ecf10fc96e3d598d9cee64779b0837b..7285d1503eb3cf57a3ad2213d4c3659164b40260 100644 (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);
 
         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);
             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;
 
             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);
         } else {
             /* Default case: just save the name */
             params->workspaces_walk->name = i3string_from_markup_with_length(ws_name, len);
index 187b550c994230ebfc47ac72379af0fe7f3e03d1..852325ba0e2d6b3a7f71685c9ec663d79c291345 100644 (file)
@@ -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_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);
 CFGFUN(bar_start);
 CFGFUN(bar_finish);
index ac8001590a9ff37f7f5086d25a9bed4a2d39a140..87897aafcd7137592e0d1e4725d29de2cdbeb9e1 100644 (file)
@@ -331,6 +331,10 @@ struct Barconfig {
      * 'strip_workspace_numbers yes'. */
     bool strip_workspace_numbers;
 
      * '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;
     /** 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;
index 60a1fc67a329294d0ca33f0aa2b6d2c8c81b74f2..9cbc782bfde7eaf42de3ab485a4eea1b63c0cfd9 100644 (file)
@@ -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
   '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
   '}'
   '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
 
   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
 state BAR_VERBOSE:
   value = word
       -> call cfg_bar_verbose($value); BAR
index ad6d65b5fe368c11b52925ac22cf58ee582c973c..da1fb580514278c324f82513f7aa524577d54d5a 100644 (file)
@@ -627,6 +627,10 @@ CFGFUN(bar_strip_workspace_numbers, const char *value) {
     current_bar->strip_workspace_numbers = eval_boolstr(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));
 CFGFUN(bar_start) {
     current_bar = scalloc(1, sizeof(struct Barconfig));
     TAILQ_INIT(&(current_bar->bar_bindings));
index a1a72b1ac8ba620136fd9f8d3cced898465d69f0..6b6383ec1ace2649bfc81546b2f8f79558d9e5da 100644 (file)
--- 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_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);
 
     ystr("binding_mode_indicator");
     y(bool, !config->hide_binding_mode_indicator);
 
index 6857b6211c2645ad456afeaf1521e09e063664d9..1e7ebfc43f76ed1b1dc963ee4e787944e1756eec 100644 (file)
@@ -725,7 +725,7 @@ EOT
 $expected = <<'EOT';
 cfg_bar_start()
 cfg_bar_output(LVDS-1)
 $expected = <<'EOT';
 cfg_bar_start()
 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', '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: <end>, '#', '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 <stdin>)
 ERROR: CONFIG: Line   1: bar {
 ERROR: CONFIG: Line   2:     output LVDS-1
 ERROR: CONFIG: (in file <stdin>)
 ERROR: CONFIG: Line   1: bar {
 ERROR: CONFIG: Line   2:     output LVDS-1