mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
menu: reload on SIGHUP
This commit is contained in:
parent
dba27a1019
commit
f0d8eb0a60
4 changed files with 40 additions and 31 deletions
|
|
@ -21,7 +21,7 @@ struct menu {
|
|||
};
|
||||
|
||||
/* menu_create - create menu */
|
||||
void menu_init(struct server *server, struct menu *menu);
|
||||
void menu_init_rootmenu(struct server *server, struct menu *menu);
|
||||
void menu_finish(struct menu *menu);
|
||||
|
||||
/* menu_move - move to position (x, y) */
|
||||
|
|
@ -33,4 +33,7 @@ void menu_set_selected(struct menu *menu, int x, int y);
|
|||
/* menu_action_selected - select item at (x, y) */
|
||||
void menu_action_selected(struct server *server, struct menu *menu);
|
||||
|
||||
/* menu_reconfigure - reload theme and content */
|
||||
void menu_reconfigure(void);
|
||||
|
||||
#endif /* __LABWC_MENU_H */
|
||||
|
|
|
|||
|
|
@ -80,8 +80,7 @@ main(int argc, char *argv[])
|
|||
xbm_load(server.renderer);
|
||||
|
||||
struct menu rootmenu = { 0 };
|
||||
menu_init(&server, &rootmenu);
|
||||
server.rootmenu = &rootmenu;
|
||||
menu_init_rootmenu(&server, &rootmenu);
|
||||
|
||||
session_autostart_init();
|
||||
if (startup_cmd) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
static const char font[] = "Sans 8";
|
||||
|
||||
static struct server *g_server;
|
||||
static struct menu *g_menu;
|
||||
|
||||
/* state-machine variables for processing <item></item> */
|
||||
static bool in_item = false;
|
||||
|
|
@ -107,7 +106,8 @@ static void fill_item(char *nodename, char *content)
|
|||
* </item>
|
||||
*/
|
||||
if (!strcmp(nodename, "label")) {
|
||||
current_item = menuitem_create(g_server, g_menu, content);
|
||||
current_item = menuitem_create(
|
||||
g_server, g_server->rootmenu, content);
|
||||
}
|
||||
assert(current_item);
|
||||
if (!strcmp(nodename, "name.action")) {
|
||||
|
|
@ -187,20 +187,7 @@ xml_tree_walk(xmlNode *node)
|
|||
}
|
||||
|
||||
static void
|
||||
parse_xml(struct buf *b)
|
||||
{
|
||||
xmlDoc *d = xmlParseMemory(b->buf, b->len);
|
||||
if (!d) {
|
||||
warn("xmlParseMemory()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xml_tree_walk(xmlDocGetRootElement(d));
|
||||
xmlFreeDoc(d);
|
||||
xmlCleanupParser();
|
||||
}
|
||||
|
||||
static void
|
||||
menu_read(void)
|
||||
parse_xml(const char *filename)
|
||||
{
|
||||
FILE *stream;
|
||||
char *line = NULL;
|
||||
|
|
@ -211,7 +198,7 @@ menu_read(void)
|
|||
if (!strlen(config_dir())) {
|
||||
return;
|
||||
}
|
||||
snprintf(menuxml, sizeof(menuxml), "%s/menu.xml", config_dir());
|
||||
snprintf(menuxml, sizeof(menuxml), "%s/%s", config_dir(), filename);
|
||||
|
||||
stream = fopen(menuxml, "r");
|
||||
if (!stream) {
|
||||
|
|
@ -228,27 +215,33 @@ menu_read(void)
|
|||
}
|
||||
free(line);
|
||||
fclose(stream);
|
||||
parse_xml(&b);
|
||||
xmlDoc *d = xmlParseMemory(b.buf, b.len);
|
||||
if (!d) {
|
||||
warn("xmlParseMemory()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xml_tree_walk(xmlDocGetRootElement(d));
|
||||
xmlFreeDoc(d);
|
||||
xmlCleanupParser();
|
||||
free(b.buf);
|
||||
}
|
||||
|
||||
void
|
||||
menu_init(struct server *server, struct menu *menu)
|
||||
menu_init_rootmenu(struct server *server, struct menu *menu)
|
||||
{
|
||||
static bool has_run;
|
||||
|
||||
if (has_run) {
|
||||
goto not_first_run;
|
||||
if (!has_run) {
|
||||
LIBXML_TEST_VERSION
|
||||
wl_list_init(&menu->menuitems);
|
||||
g_server = server;
|
||||
server->rootmenu = menu;
|
||||
}
|
||||
LIBXML_TEST_VERSION
|
||||
wl_list_init(&menu->menuitems);
|
||||
g_server = server;
|
||||
g_menu = menu;
|
||||
|
||||
not_first_run:
|
||||
menu_read();
|
||||
parse_xml("menu.xml");
|
||||
|
||||
/* Default menu if no menu.xml found */
|
||||
if (!current_item) {
|
||||
if (wl_list_empty(&menu->menuitems)) {
|
||||
current_item = menuitem_create(server, menu, "Reconfigure");
|
||||
current_item->action = strdup("Reconfigure");
|
||||
current_item = menuitem_create(server, menu, "Exit");
|
||||
|
|
@ -311,3 +304,10 @@ menu_action_selected(struct server *server, struct menu *menu)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
menu_reconfigure(void)
|
||||
{
|
||||
menu_finish(g_server->rootmenu);
|
||||
menu_init_rootmenu(g_server, g_server->rootmenu);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ static struct wl_event_source *sighup_source;
|
|||
static struct wl_event_source *sigint_source;
|
||||
static struct wl_event_source *sigterm_source;
|
||||
|
||||
static struct server *g_server;
|
||||
|
||||
static void
|
||||
reload_config_and_theme(void)
|
||||
{
|
||||
|
|
@ -25,6 +27,8 @@ reload_config_and_theme(void)
|
|||
/* TODO: use rc.config_path */
|
||||
rcxml_read(NULL);
|
||||
theme_read(rc.theme_name);
|
||||
menu_reconfigure();
|
||||
damage_all_outputs(g_server);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -212,6 +216,9 @@ server_init(struct server *server)
|
|||
image->hotspot_y);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* used when handling SIGHUP */
|
||||
g_server = server;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue