rcxml: fix broken titlebar layout with multiple <layout> entries

Before this commit, when we have multiple <theme><titlebar><layout>
entries like below, duplicated button types can be inserted to
rc.title_buttons_{left,right} and the button could go outside of the
window:
    <theme>
      <titlebar><layout>icon:iconify,max,close</layout></titlebar>
      <titlebar><layout>icon:iconify,max,close</layout></titlebar>
    </theme>

This commit fixes by clearing those lists when the parser encounters
<theme><titlebar><layout>.
This commit is contained in:
tokyo4j 2025-04-12 20:31:04 +09:00 committed by Johan Malm
parent be3ca8df7a
commit fcf230e692

View file

@ -201,9 +201,26 @@ fill_section(const char *content, struct wl_list *list, uint32_t *found_buttons)
g_strfreev(identifiers); g_strfreev(identifiers);
} }
static void
clear_title_layout(void)
{
struct title_button *button, *button_tmp;
wl_list_for_each_safe(button, button_tmp, &rc.title_buttons_left, link) {
wl_list_remove(&button->link);
zfree(button);
}
wl_list_for_each_safe(button, button_tmp, &rc.title_buttons_right, link) {
wl_list_remove(&button->link);
zfree(button);
}
rc.title_layout_loaded = false;
}
static void static void
fill_title_layout(char *content) fill_title_layout(char *content)
{ {
clear_title_layout();
struct wl_list *sections[] = { struct wl_list *sections[] = {
&rc.title_buttons_left, &rc.title_buttons_left,
&rc.title_buttons_right, &rc.title_buttons_right,
@ -1978,15 +1995,7 @@ rcxml_finish(void)
zfree(rc.workspace_config.prefix); zfree(rc.workspace_config.prefix);
zfree(rc.tablet.output_name); zfree(rc.tablet.output_name);
struct title_button *p, *p_tmp; clear_title_layout();
wl_list_for_each_safe(p, p_tmp, &rc.title_buttons_left, link) {
wl_list_remove(&p->link);
zfree(p);
}
wl_list_for_each_safe(p, p_tmp, &rc.title_buttons_right, link) {
wl_list_remove(&p->link);
zfree(p);
}
struct usable_area_override *area, *area_tmp; struct usable_area_override *area, *area_tmp;
wl_list_for_each_safe(area, area_tmp, &rc.usable_area_overrides, link) { wl_list_for_each_safe(area, area_tmp, &rc.usable_area_overrides, link) {