X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=plugins%2Fmenu%2Ffifo_menu.c;h=c096a9d3ac7975143d180e20f415c1051c82eef3;hb=1045079482453424f8320de99639390e3020eb72;hp=a05989f8964accd3981122609cb25eacf90ae027;hpb=22ff8c587d815c021cad13f46094a31cc79243cf;p=chaz%2Fopenbox diff --git a/plugins/menu/fifo_menu.c b/plugins/menu/fifo_menu.c index a05989f8..c096a9d3 100644 --- a/plugins/menu/fifo_menu.c +++ b/plugins/menu/fifo_menu.c @@ -1,3 +1,25 @@ +/* + * $Header$ + * + * FFIO menu plugin + * Provides a menu from a FIFO located in ~/.openbox/fifo_menu/id + * Example: + * rc3: + * + * Menu format + * + * + * + * + * bsetbg "/home/woodblock/.openbox/backgrounds/GLOVE.png" + * + * + * + * + * + * If the attribute pid="true" is in the + */ + #include #include #include @@ -12,11 +34,12 @@ static char *PLUGIN_NAME = "fifo_menu"; -typedef struct Fifo_Menu_Data{ +typedef struct Fifo_Menu_Data { char *fifo; char *buf; /* buffer to hold partially read menu */ unsigned long buflen; /* how many bytes are in the buffer */ int fd; /* file descriptor to read menu from */ + gboolean use_pid; event_fd_handler *handler; } Fifo_Menu_Data; @@ -78,24 +101,24 @@ void fifo_menu_handler(int fd, void *d) { num_realloc); if (num_read == 0) { /* eof */ - unsigned long count = 0; - char *found = NULL; + ObParseInst *i; + xmlDocPtr doc; + xmlNodePtr node; menu->invalid = TRUE; menu_clear(menu); FIFO_MENU_DATA(menu)->buf[FIFO_MENU_DATA(menu)->buflen] = '\0'; - xmlDocPtr doc = xmlParseMemory(FIFO_MENU_DATA(menu)->buf, - FIFO_MENU_DATA(menu)->buflen); + i = parse_startup(); - xmlNodePtr node = xmlDocGetRootElement(doc); + if (parse_load_mem(FIFO_MENU_DATA(menu)->buf, + FIFO_MENU_DATA(menu)->buflen, + "fifo_menu", &doc, &node)) + parse_menu_full(i, doc, node, menu, FALSE); + + parse_shutdown(i); - if (!xmlStrcasecmp(node->name, (const xmlChar*) "fifo")) { - if ((node = parse_find_node("item", node->xmlChildrenNode))) - parse_menu_full(doc, node, menu, FALSE); - } - fifo_menu_clean_up(menu); event_remove_fd(FIFO_MENU_DATA(menu)->handler->fd); @@ -131,14 +154,17 @@ void plugin_destroy (ObMenu *m) FIFO_MENU_DATA(m)->fifo = NULL; } + if (FIFO_MENU_DATA(m)->buf != NULL) { + g_free(FIFO_MENU_DATA(m)->buf); + FIFO_MENU_DATA(m)->buf = NULL; + } + g_free(m->plugin_data); menu_free(m->name); } void *plugin_create(PluginMenuCreateData *data) - - { char *fifo; char *dir; @@ -146,18 +172,27 @@ void *plugin_create(PluginMenuCreateData *data) Fifo_Menu_Data *d; ObMenu *m; char *label = NULL, *id = NULL; + char *attr_pid = NULL; d = g_new(Fifo_Menu_Data, 1); parse_attr_string("id", data->node, &id); parse_attr_string("label", data->node, &label); - + + if (parse_attr_string("pid", data->node, &attr_pid) && + g_strcasecmp(attr_pid, "true") == 0) { + d->use_pid = TRUE; + } else + d->use_pid = FALSE; + m = menu_new( (label != NULL ? label : ""), - (id != NULL ? id : PLUGIN_NAME), - data->parent); - menu_add_entry(data->parent, menu_entry_new_submenu( - (label != NULL ? label : ""), - m)); + (id != NULL ? id : PLUGIN_NAME), + data->parent); + + if (data->parent) + menu_add_entry(data->parent, menu_entry_new_submenu( + (label != NULL ? label : ""), + m)); g_free(label); g_free(id); @@ -172,6 +207,7 @@ void *plugin_create(PluginMenuCreateData *data) m->plugin_data = (void *)d; + dir = g_build_filename(g_get_home_dir(), ".openbox", PLUGIN_NAME, NULL); @@ -185,9 +221,19 @@ void *plugin_create(PluginMenuCreateData *data) return NULL; } - fifo = g_build_filename(g_get_home_dir(), ".openbox", - PLUGIN_NAME, - m->name, NULL); + if (d->use_pid) + { + char *pid = g_strdup_printf("%s.%d", m->name, getpid()); + fifo = g_build_filename(g_get_home_dir(), ".openbox", + PLUGIN_NAME, + pid, NULL); + g_free(pid); + } else { + fifo = g_build_filename(g_get_home_dir(), ".openbox", + PLUGIN_NAME, + m->name, NULL); + } + if (mkfifo(fifo, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | /* let umask do its thing */ S_IROTH | S_IWOTH) == -1 && errno != EEXIST) {