diff --git a/CHANGELOG.md b/CHANGELOG.md index a99a9c1..4420f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,9 +32,11 @@ * Documentation for the `cpu` module; `interval` has been renamed to `poll-interval` ([#241][241]). * 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 [241]: https://codeberg.org/dnkl/yambar/issues/241 +[251]: https://codeberg.org/dnkl/yambar/pulls/251 ### Security diff --git a/modules/dwl.c b/modules/dwl.c index 00b4cb8..5fa1023 100644 --- a/modules/dwl.c +++ b/modules/dwl.c @@ -168,9 +168,15 @@ process_line(char *line, struct module *module) } /* action */ else if (index == 2) { - if (strcmp(string, "title") == 0) + if (strcmp(string, "title") == 0) { 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; else if (strcmp(string, "floating") == 0) line_mode = LINE_MODE_FLOATING; @@ -222,8 +228,7 @@ process_line(char *line, struct module *module) } else switch (line_mode) { case LINE_MODE_TITLE: - free(private->title); - private->title = strdup(string); + assert(false); /* unreachable */ break; case LINE_MODE_FULLSCREEN: private->fullscreen = (strcmp(string, "0") != 0);