]> Dogcows Code - chaz/openbox/commitdiff
when a pipe menu is killed, kill all its submenus as well
authorDana Jansens <danakj@orodu.net>
Thu, 4 Sep 2003 15:30:34 +0000 (15:30 +0000)
committerDana Jansens <danakj@orodu.net>
Thu, 4 Sep 2003 15:30:34 +0000 (15:30 +0000)
openbox/menu.c
openbox/menu.h

index c52f30131b5b76d212ff6836061142d820ddf07b..d00ef05e0c40b17b520caa678f54f9be9a83fb4d 100644 (file)
@@ -18,6 +18,7 @@ typedef struct _ObMenuParseState ObMenuParseState;
 struct _ObMenuParseState
 {
     GSList *menus;
+    ObMenu *pipe_creator;
 };
 
 static GHashTable *menu_hash = NULL;
@@ -78,6 +79,7 @@ void menu_startup(gboolean reconfig)
     menu_parse_inst = parse_startup();
 
     menu_parse_state.menus = NULL;
+    menu_parse_state.pipe_creator = NULL;
     parse_register(menu_parse_inst, "menu", parse_menu, &menu_parse_state);
     parse_register(menu_parse_inst, "item", parse_menu_item,
                    &menu_parse_state);
@@ -117,6 +119,12 @@ void menu_shutdown(gboolean reconfig)
     menu_hash = NULL;
 }
 
+static gboolean menu_pipe_submenu(gpointer key, gpointer val, gpointer data)
+{
+    ObMenu *menu = val;
+    return menu->pipe_creator == data;
+}
+
 void menu_pipe_execute(ObMenu *self)
 {
     xmlDocPtr doc;
@@ -137,14 +145,19 @@ void menu_pipe_execute(ObMenu *self)
     if (parse_load_mem(output, strlen(output),
                        "openbox_pipe_menu", &doc, &node))
     {
+        g_hash_table_foreach_remove(menu_hash, menu_pipe_submenu, self);
         menu_clear_entries(self);
 
+        menu_parse_state.pipe_creator = self;
         menu_parse_state.menus = g_slist_prepend(NULL, self);
         parse_tree(menu_parse_inst, doc, node->xmlChildrenNode);
         menu_parse_state.menus = g_slist_remove(menu_parse_state.menus, self);
+        menu_parse_state.pipe_creator = NULL;
         xmlFreeDoc(doc);
 
         g_assert(menu_parse_state.menus == NULL);
+    } else {
+        g_warning("Invalid output from pipe-menu: %s", self->execute);
     }
 }
 
@@ -204,6 +217,7 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
             goto parse_menu_fail;
 
         if ((menu = menu_new(name, title, NULL))) {
+            menu->pipe_creator = state->pipe_creator;
             if (parse_attr_string("execute", node, &script)) {
                 menu->execute = ob_expand_tilde(script);
             } else {
index 0c946dd64c0c43fd252a58b60f7ea1fab2515a6e..f6c334172c13cbb8c2ee0fa596f8316e52726c1a 100644 (file)
@@ -42,6 +42,9 @@ struct _ObMenu
     ObMenuUpdateFunc update_func;
     ObMenuExecuteFunc execute_func;
     ObMenuDestroyFunc destroy_func;
+
+    /* Pipe-menu parent, we get destroyed when it is destroyed */
+    ObMenu *pipe_creator;
 };
 
 typedef enum
This page took 0.028762 seconds and 4 git commands to generate.