-#else
-static int workspaces_string_cb(void *params_, const unsigned char *val, unsigned int len) {
-#endif
- struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
-
- char *output_name;
-
- if (!strcmp(params->cur_key, "name")) {
- /* Save the name */
- params->workspaces_walk->name = smalloc(sizeof(const unsigned char) * (len + 1));
- strncpy(params->workspaces_walk->name, (const char*) val, len);
- params->workspaces_walk->name[len] = '\0';
-
- /* Convert the name to ucs2, save its length in glyphs and calculate its rendered width */
- size_t ucs2_len;
- xcb_char2b_t *ucs2_name = (xcb_char2b_t*) convert_utf8_to_ucs2(params->workspaces_walk->name, &ucs2_len);
- params->workspaces_walk->ucs2_name = ucs2_name;
- params->workspaces_walk->name_glyphs = ucs2_len;
- params->workspaces_walk->name_width =
- predict_text_width((char *)params->workspaces_walk->ucs2_name,
- params->workspaces_walk->name_glyphs, true);
-
- DLOG("Got Workspace %s, name_width: %d, glyphs: %d\n",
- params->workspaces_walk->name,
- params->workspaces_walk->name_width,
- params->workspaces_walk->name_glyphs);
- FREE(params->cur_key);
-
- return 1;
+ struct workspaces_json_params *params = (struct workspaces_json_params *)params_;
+
+ char *output_name;
+
+ if (!strcmp(params->cur_key, "name")) {
+ 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 */
+ size_t 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);