mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-06-20 17:35:39 +02:00
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:
parent
cd307c4a4c
commit
8775497cae
1 changed files with 8 additions and 14 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue