X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=plugins%2Fmenu%2Ffifo_menu.c;h=c096a9d3ac7975143d180e20f415c1051c82eef3;hb=a88e58e227385b0d53772c059a708b1a9e7866f1;hp=e50810789898e5c2a92d6c2d8b51dc32f3a1ac9a;hpb=00960995a291c32d56bf3ab1eeae4e24af54be5c;p=chaz%2Fopenbox diff --git a/plugins/menu/fifo_menu.c b/plugins/menu/fifo_menu.c index e5081078..c096a9d3 100644 --- a/plugins/menu/fifo_menu.c +++ b/plugins/menu/fifo_menu.c @@ -1,28 +1,53 @@ +/* + * $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 #include #include #include +#include +#include #include "kernel/menu.h" #include "kernel/event.h" 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; -#define FIFO_MENU(m) ((Menu *)m) -#define FIFO_MENU_DATA(m) ((Fifo_Menu_Data *)((Menu *)m)->plugin_data) +#define FIFO_MENU(m) ((ObMenu *)m) +#define FIFO_MENU_DATA(m) ((Fifo_Menu_Data *)((ObMenu *)m)->plugin_data) -void fifo_menu_clean_up(Menu *m) { +void fifo_menu_clean_up(ObMenu *m) { if (FIFO_MENU_DATA(m)->buf != NULL) { g_free(FIFO_MENU_DATA(m)->buf); FIFO_MENU_DATA(m)->buf = NULL; @@ -40,12 +65,15 @@ void plugin_startup() { } void plugin_shutdown() { } -void fifo_menu_handler(int fd, Menu *menu) { +void fifo_menu_handler(int fd, void *d) { + ObMenu *menu = d; char *tmpbuf = NULL; unsigned long num_read; #ifdef DEBUG /* because gdb is dumb */ +#if 0 Fifo_Menu_Data *d = FIFO_MENU_DATA(menu); +#endif #endif /* if the menu is shown this will go into busy loop :( @@ -68,34 +96,36 @@ void fifo_menu_handler(int fd, Menu *menu) { FIFO_MENU_DATA(menu)->buf = tmpbuf; num_read = read(fd, - FIFO_MENU_DATA(menu)->buf + FIFO_MENU_DATA(menu)->buflen, + FIFO_MENU_DATA(menu)->buf + + FIFO_MENU_DATA(menu)->buflen, 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); - /* TEMP: list them */ - while (NULL != - (found = strchr(&FIFO_MENU_DATA(menu)->buf[count], '\n'))) { - FIFO_MENU_DATA(menu)->buf - [found - FIFO_MENU_DATA(menu)->buf] = '\0'; - menu_add_entry(menu, - menu_entry_new_separator - (&FIFO_MENU_DATA(menu)->buf[count])); - count = found - FIFO_MENU_DATA(menu)->buf + 1; - } - FIFO_MENU_DATA(menu)->buf[FIFO_MENU_DATA(menu)->buflen] = '\0'; - fifo_menu_clean_up(menu); + i = parse_startup(); + + 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); + + fifo_menu_clean_up(menu); + event_remove_fd(FIFO_MENU_DATA(menu)->handler->fd); if ((FIFO_MENU_DATA(menu)->fd = - open(FIFO_MENU_DATA(menu)->fifo, O_NONBLOCK | O_RDONLY)) == -1) { + open(FIFO_MENU_DATA(menu)->fifo, + O_NONBLOCK | O_RDONLY)) == -1) { g_warning("Can't reopen FIFO"); fifo_menu_clean_up(menu); return; @@ -111,7 +141,7 @@ void fifo_menu_handler(int fd, Menu *menu) { } } -void plugin_destroy (Menu *m) +void plugin_destroy (ObMenu *m) { fifo_menu_clean_up(m); if (FIFO_MENU_DATA(m)->handler != NULL) { @@ -124,20 +154,48 @@ void plugin_destroy (Menu *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() /* TODO: need config */ +void *plugin_create(PluginMenuCreateData *data) { char *fifo; char *dir; event_fd_handler *h; + 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); - Fifo_Menu_Data *d = g_new(Fifo_Menu_Data, 1); - Menu *m = menu_new("", PLUGIN_NAME, NULL); + 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); + + if (data->parent) + menu_add_entry(data->parent, menu_entry_new_submenu( + (label != NULL ? label : ""), + m)); + g_free(label); + g_free(id); d->fd = -1; d->buf = NULL; d->buflen = 0; @@ -149,7 +207,9 @@ void *plugin_create() /* TODO: need config */ m->plugin_data = (void *)d; - dir = g_build_filename(g_get_home_dir(), ".openbox", PLUGIN_NAME, NULL); + + dir = g_build_filename(g_get_home_dir(), ".openbox", + PLUGIN_NAME, NULL); if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == -1 && errno != EEXIST) { /* technically, if ~/.openbox/fifo_menu exists and isn't a directory @@ -161,8 +221,19 @@ void *plugin_create() /* TODO: need config */ 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) {