]> git.mdlowis.com Git - proto/labwc.git/commit
menu: add struct menu_parse_context to reduce static vars
authorJohn Lindgren <john@jlindgren.net>
Sat, 19 Jul 2025 03:06:20 +0000 (23:06 -0400)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Thu, 24 Jul 2025 06:35:29 +0000 (15:35 +0900)
commitd96656ccdcef7e3dd1fca5cde0608d4220b61585
tree602953ace5acb5158d4acaf4e324e86c4e5af514
parentcb79eccea1e259b1979ec4767922256defcda8f3
menu: add struct menu_parse_context to reduce static vars

The lifetime of the "current_" variables (current_menu, current_item,
current_item_action) is very difficult to understand from reading the
code. It appears that e.g. current_menu could still point to a previous
menu when starting to parse a new one, with unpredictable results.

Let's use a context struct when parsing, and consistently initialize
it when beginning to build a new menu.

Lightly tested with:

- default menus (no menu.xml)
- example static menu from labwc.github.io/getting-started.html
- an added "client-list-combined-menu" sub-menu
- pipe menu generated by `labwc-menu-generator -p`

v2: style fix
src/menu/menu.c