module/dwl: update the title when process a new batch of info

instead of call strtok_r and looping until `string` is NULL
This commit is contained in:
Leonardo Hernández Hernández 2022-12-26 14:53:18 -06:00
parent cd307c4a4c
commit 8775497cae
No known key found for this signature in database
GPG key ID: E538897EE11B9624

View file

@ -170,9 +170,12 @@ process_line(char *line, struct module *module)
else if (index == 2) {
if (strcmp(string, "title") == 0) {
line_mode = LINE_MODE_TITLE;
/* cleanup title for every new batch */
/* 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 = NULL;
private->title = strdup(save_pointer);
break;
} else if (strcmp(string, "fullscreen") == 0)
line_mode = LINE_MODE_FULLSCREEN;
else if (strcmp(string, "floating") == 0)
@ -222,20 +225,11 @@ process_line(char *line, struct module *module)
dwl_tag->urgent = mask & urgent;
}
}
} else if (line_mode == LINE_MODE_TITLE) {
if (!private->title) {
private->title = strdup(string);
} else {
char *buf = NULL;
if (asprintf(&buf, "%s %s", private->title, string) < 0) {
LOG_ERRNO("asprintf");
break;
}
free(private->title);
private->title = buf;
}
} else
switch (line_mode) {
case LINE_MODE_TITLE:
assert(false); /* unreachable */
break;
case LINE_MODE_FULLSCREEN:
private->fullscreen = (strcmp(string, "0") != 0);
break;