Skip to content

Commit

Permalink
#533 translate 0x0a and 0x0d when outputting window titles through th…
Browse files Browse the repository at this point in the history
…e query system
  • Loading branch information
koekeishiya committed May 22, 2020
1 parent dcd88f1 commit dbdc5a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased]
- Properly clear focus-follows-mouse cache upon space change [#528](https://github.com/koekeishiya/yabai/issues/528)
- Revised process type restrictions and observation requirements to correctly track some applications that don't identify correctly [#529](https://github.com/koekeishiya/yabai/issues/529)
- Translate newline (0x0a) and carriage return (0x0d) when outputting window titles through the query system [#533](https://github.com/koekeishiya/yabai/issues/533)

## [3.0.1] - 2020-05-09
### Changed
Expand Down
29 changes: 22 additions & 7 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,42 @@ static inline bool string_equals(const char *a, const char *b)
return a && b && strcmp(a, b) == 0;
}

static inline char *string_escape_quote(char *s)
static inline char *string_escape(char *s)
{
if (!s) return NULL;

char *cursor = s;
int num_quotes = 0;
int num_replacements = 0;

while (*cursor) {
if (*cursor == '"') ++num_quotes;
if ((*cursor == '"') ||
(*cursor == '\n') ||
(*cursor == '\r')) {
++num_replacements;
}

++cursor;
}

if (!num_quotes) return NULL;
if (!num_replacements) return NULL;

int size_in_bytes = (int)(cursor - s) + num_quotes;
int size_in_bytes = (int)(cursor - s) + num_replacements;
char *result = malloc(sizeof(char) * (size_in_bytes+1));
result[size_in_bytes] = '\0';

for (char *dst = result, *cursor = s; *cursor; ++cursor) {
if (*cursor == '"') *dst++ = '\\';
*dst++ = *cursor;
if (*cursor == '"') {
*dst++ = '\\';
*dst++ = *cursor;
} else if (*cursor == '\n') {
*dst++ = '\\';
*dst++ = 'n';
} else if (*cursor == '\r') {
*dst++ = '\\';
*dst++ = 'r';
} else {
*dst++ = *cursor;
}
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ uint64_t *window_space_list(struct window *window, int *count)
void window_serialize(FILE *rsp, struct window *window)
{
char *title = window_title(window);
char *escaped_title = string_escape_quote(title);
char *escaped_title = string_escape(title);
CGRect frame = window_frame(window);
char *role = NULL;
char *subrole = NULL;
Expand Down

0 comments on commit dbdc5a6

Please sign in to comment.