module/dwl: correctly handle the title

Uupdate the title when process a new batch of info instead of call
strtok_r and looping until `string` is NULL.

This fixes an issue where only the last part of the title was kept.
This commit is contained in:
Leonardo Hernández Hernández 2022-12-24 13:31:17 -06:00 committed by Daniel Eklöf
parent e4edbd26c6
commit 02d281df58
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 11 additions and 4 deletions

View file

@ -32,9 +32,11 @@
* Documentation for the `cpu` module; `interval` has been renamed to * Documentation for the `cpu` module; `interval` has been renamed to
`poll-interval` ([#241][241]). `poll-interval` ([#241][241]).
* battery: module was not thread safe. * battery: module was not thread safe.
* dwl module reporting only the last part of the title ([#251][251])
[239]: https://codeberg.org/dnkl/yambar/issues/239 [239]: https://codeberg.org/dnkl/yambar/issues/239
[241]: https://codeberg.org/dnkl/yambar/issues/241 [241]: https://codeberg.org/dnkl/yambar/issues/241
[251]: https://codeberg.org/dnkl/yambar/pulls/251
### Security ### Security

View file

@ -168,9 +168,15 @@ process_line(char *line, struct module *module)
} }
/* action */ /* action */
else if (index == 2) { else if (index == 2) {
if (strcmp(string, "title") == 0) if (strcmp(string, "title") == 0) {
line_mode = LINE_MODE_TITLE; line_mode = LINE_MODE_TITLE;
else if (strcmp(string, "fullscreen") == 0) /* Update the title here, to avoid allocate and free memory on
* every iteration (the line is separated by spaces, then we
* join it again) a bit suboptimal, isn't it?) */
free(private->title);
private->title = strdup(save_pointer);
break;
} else if (strcmp(string, "fullscreen") == 0)
line_mode = LINE_MODE_FULLSCREEN; line_mode = LINE_MODE_FULLSCREEN;
else if (strcmp(string, "floating") == 0) else if (strcmp(string, "floating") == 0)
line_mode = LINE_MODE_FLOATING; line_mode = LINE_MODE_FLOATING;
@ -222,8 +228,7 @@ process_line(char *line, struct module *module)
} else } else
switch (line_mode) { switch (line_mode) {
case LINE_MODE_TITLE: case LINE_MODE_TITLE:
free(private->title); assert(false); /* unreachable */
private->title = strdup(string);
break; break;
case LINE_MODE_FULLSCREEN: case LINE_MODE_FULLSCREEN:
private->fullscreen = (strcmp(string, "0") != 0); private->fullscreen = (strcmp(string, "0") != 0);