From 22ff8c587d815c021cad13f46094a31cc79243cf Mon Sep 17 00:00:00 2001 From: Scott Moynes Date: Thu, 17 Jul 2003 01:40:27 +0000 Subject: Menu parsing updates for plugins. FIFO menus are the only plugin that takes advantage of this. Example: This creates a FIFO ~/.openbox/fifo_menu/fonk to which you can send menus to. The menus sent to it must be like etc... I think. If my memory serves me right. It is all hideous, but I just wanted to experiment and see if it was possible. --- openbox/menu.c | 51 +++++++++++++++++++++++++++++++++++++-------------- openbox/menu.h | 11 ++++++++++- openbox/plugin.c | 4 ++-- openbox/plugin.h | 2 +- 4 files changed, 50 insertions(+), 18 deletions(-) (limited to 'openbox') diff --git a/openbox/menu.c b/openbox/menu.c index a8a51117..e2c55c6d 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -17,29 +17,52 @@ GSList *menu_visible = NULL; ButtonPressMask | ButtonReleaseMask) static void parse_menu(xmlDocPtr doc, xmlNodePtr node, void *data) +{ + parse_menu_full(doc, node, data, TRUE); +} + + +void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, + gboolean newmenu) { Action *act; xmlNodePtr nact; - gchar *id = NULL, *title = NULL, *label = NULL; - ObMenu *menu, *parent; - if (!parse_attr_string("id", node->parent, &id)) - goto parse_menu_fail; - if (!parse_attr_string("label", node->parent, &title)) - goto parse_menu_fail; + gchar *id = NULL, *title = NULL, *label = NULL, *plugin; + ObMenu *menu = NULL, *parent; + + if (newmenu == TRUE) { + if (!parse_attr_string("id", node->parent, &id)) + goto parse_menu_fail; + if (!parse_attr_string("label", node->parent, &title)) + goto parse_menu_fail; - g_message("menu label %s", title); + g_message("menu label %s", title); - menu = menu_new(title, id, data ? *((ObMenu**)data) : NULL); - if (data) - *((ObMenu**)data) = menu; + menu = menu_new(title, id, data ? *((ObMenu**)data) : NULL); + if (data) + *((ObMenu**)data) = menu; + } else { + menu = (ObMenu *)data; + } + while (node) { if (!xmlStrcasecmp(node->name, (const xmlChar*) "menu")) { - parent = menu; - parse_menu(doc, node->xmlChildrenNode, &parent); - menu_add_entry(menu, menu_entry_new_submenu(parent->label, - parent)); + if (parse_attr_string("plugin", node, &plugin)) { + PluginMenuCreateData data = { + .doc = doc, + .node = node, + .parent = menu + }; + parent = plugin_create(plugin, &data); + } else { + parent = menu; + parse_menu(doc, node->xmlChildrenNode, &parent); + menu_add_entry(menu, menu_entry_new_submenu(parent->label, + parent)); + } + } else if (!xmlStrcasecmp(node->name, (const xmlChar*) "item")) { if (parse_attr_string("label", node, &label)) { diff --git a/openbox/menu.h b/openbox/menu.h index 72a7ed24..2f3f9ac2 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -96,7 +96,14 @@ struct _ObMenuEntry RrAppearance *a_hilite; gint y; gint min_w; -}; +} MenuEntry; + +typedef struct PluginMenuCreateData{ + xmlDocPtr doc; + xmlNodePtr node; + ObMenu *parent; +} PluginMenuCreateData; + void menu_startup(); void menu_shutdown(); @@ -147,5 +154,7 @@ void menu_entry_fire(ObMenuEntry *self); void menu_render(ObMenu *self); void menu_render_full(ObMenu *self); +//so plugins can call it? +void parse_menu_full(xmlDocPtr doc, xmlNodePtr node, void *data, gboolean new); void menu_control_mouseover(ObMenuEntry *entry, gboolean enter); #endif diff --git a/openbox/plugin.c b/openbox/plugin.c index 747bde6f..cd17d215 100644 --- a/openbox/plugin.c +++ b/openbox/plugin.c @@ -176,7 +176,7 @@ void plugin_loadall() } } -void *plugin_create(char *name /* TODO */) +void *plugin_create(char *name, void *data) { Plugin *p = (Plugin *)g_datalist_get_data(&plugins, name); @@ -190,7 +190,7 @@ void *plugin_create(char *name /* TODO */) return NULL; } - return p->create(); + return p->create(data); } void plugin_destroy(char *name, void *data) diff --git a/openbox/plugin.h b/openbox/plugin.h index 733f564b..38da2086 100644 --- a/openbox/plugin.h +++ b/openbox/plugin.h @@ -14,7 +14,7 @@ gboolean plugin_open_reopen(char *name); void plugin_close(char *name); /* call plugin's generic constructor */ -void *plugin_create(char *name /* TODO */); +void *plugin_create(char *name, void *data); /* free memory allocated by plugin_create() */ void plugin_destroy(char *name, void *object); -- cgit v1.2.3