mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 08:21:28 +00:00
Refactor parse_title_format
Don't read properties until needed, and do it with less lines of code.
This commit is contained in:
parent
b2c0ba5b18
commit
9df1432f56
|
@ -641,6 +641,14 @@ void view_child_destroy(struct sway_view_child *child) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t append_prop(char *buffer, const char *value) {
|
||||||
|
if (!value) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lenient_strcat(buffer, value);
|
||||||
|
return strlen(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate and return the length of the formatted title.
|
* Calculate and return the length of the formatted title.
|
||||||
* If buffer is not NULL, also populate the buffer with the formatted title.
|
* If buffer is not NULL, also populate the buffer with the formatted title.
|
||||||
|
@ -653,16 +661,6 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) {
|
||||||
}
|
}
|
||||||
return title ? strlen(title) : 0;
|
return title ? strlen(title) : 0;
|
||||||
}
|
}
|
||||||
const char *title = view_get_title(view);
|
|
||||||
const char *app_id = view_get_app_id(view);
|
|
||||||
const char *class = view_get_class(view);
|
|
||||||
const char *instance = view_get_instance(view);
|
|
||||||
const char *shell = view_get_shell(view);
|
|
||||||
size_t title_len = title ? strlen(title) : 0;
|
|
||||||
size_t app_id_len = app_id ? strlen(app_id) : 0;
|
|
||||||
size_t class_len = class ? strlen(class) : 0;
|
|
||||||
size_t instance_len = instance ? strlen(instance) : 0;
|
|
||||||
size_t shell_len = shell ? strlen(shell) : 0;
|
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char *format = view->title_format;
|
char *format = view->title_format;
|
||||||
|
@ -674,24 +672,19 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) {
|
||||||
format = next;
|
format = next;
|
||||||
|
|
||||||
if (strncmp(next, "%title", 6) == 0) {
|
if (strncmp(next, "%title", 6) == 0) {
|
||||||
lenient_strcat(buffer, title);
|
len += append_prop(buffer, view_get_title(view));
|
||||||
len += title_len;
|
|
||||||
format += 6;
|
format += 6;
|
||||||
} else if (strncmp(next, "%app_id", 7) == 0) {
|
} else if (strncmp(next, "%app_id", 7) == 0) {
|
||||||
lenient_strcat(buffer, app_id);
|
len += append_prop(buffer, view_get_app_id(view));
|
||||||
len += app_id_len;
|
|
||||||
format += 7;
|
format += 7;
|
||||||
} else if (strncmp(next, "%class", 6) == 0) {
|
} else if (strncmp(next, "%class", 6) == 0) {
|
||||||
lenient_strcat(buffer, class);
|
len += append_prop(buffer, view_get_class(view));
|
||||||
len += class_len;
|
|
||||||
format += 6;
|
format += 6;
|
||||||
} else if (strncmp(next, "%instance", 9) == 0) {
|
} else if (strncmp(next, "%instance", 9) == 0) {
|
||||||
lenient_strcat(buffer, instance);
|
len += append_prop(buffer, view_get_instance(view));
|
||||||
len += instance_len;
|
|
||||||
format += 9;
|
format += 9;
|
||||||
} else if (strncmp(next, "%shell", 6) == 0) {
|
} else if (strncmp(next, "%shell", 6) == 0) {
|
||||||
lenient_strcat(buffer, shell);
|
len += append_prop(buffer, view_get_shell(view));
|
||||||
len += shell_len;
|
|
||||||
format += 6;
|
format += 6;
|
||||||
} else {
|
} else {
|
||||||
lenient_strcat(buffer, "%");
|
lenient_strcat(buffer, "%");
|
||||||
|
|
Loading…
Reference in a new issue