diff options
Diffstat (limited to 'openbox')
| -rw-r--r-- | openbox/Makefile.am | 12 | ||||
| -rw-r--r-- | openbox/action.c | 50 | ||||
| -rw-r--r-- | openbox/action.h | 2 | ||||
| -rw-r--r-- | openbox/config.c | 2 | ||||
| -rw-r--r-- | openbox/focus.c | 1 | ||||
| -rw-r--r-- | openbox/openbox.c | 7 | ||||
| -rw-r--r-- | openbox/parse.c | 243 | ||||
| -rw-r--r-- | openbox/parse.h | 38 | ||||
| -rw-r--r-- | openbox/plugin.c | 8 |
9 files changed, 66 insertions, 297 deletions
diff --git a/openbox/Makefile.am b/openbox/Makefile.am index ecb72969..fc9f4ae3 100644 --- a/openbox/Makefile.am +++ b/openbox/Makefile.am @@ -1,15 +1,15 @@ localedir=$(datadir)/locale -plugindir=$(libdir)/openbox/plugins rcdir=$(datadir)/openbox +plugindir=$(libdir)/openbox/plugins binary=openbox3 -url=http://icculus.org/openbox +url=http://openbox.org/ CPPFLAGS=$(X_CFLAGS) $(XFT_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS) \ $(LIBSN_CFLAGS) $(GL_CFLAGS) $(XML_CFLAGS) @CPPFLAGS@ \ -DLOCALEDIR=\"$(localedir)\" \ - -DRCDIR=\"$(rcdir)\" \ -DPLUGINDIR=\"$(plugindir)\" \ + -DRCDIR=\"$(rcdir)\" \ -DG_LOG_DOMAIN=\"Openbox\" \ -DBINARY=\"$(binary)\" @@ -20,9 +20,9 @@ LIBS=$(X_LIBS) $(XFT_LIBS) $(XINERAMA_LIBS) $(XKB_LIBS) $(XRANDR_LIBS) \ bin_PROGRAMS=$(binary) -openbox3_LDADD=-lobrender -L../render +openbox3_LDADD=-lobrender -L../render -lobparser -L../parser openbox3_LDFLAGS=-export-dynamic -openbox3_SOURCES=action.c client.c config.c parse.c \ +openbox3_SOURCES=action.c client.c config.c \ extensions.c focus.c frame.c grab.c menu.c menu_render.c \ openbox.c framerender.c plugin.c prop.c screen.c \ stacking.c dispatch.c event.c group.c timer.c xerror.c \ @@ -32,7 +32,7 @@ noinst_HEADERS=action.h client.h config.h dispatch.h event.h extensions.h \ focus.h frame.h framerender.h geom.h gettext.h grab.h group.h \ menu.h openbox.h plugin.h prop.h screen.h \ stacking.h timer.h xerror.h moveresize.h startup.h popup.h \ - dock.h window.h parse.h + dock.h window.h MAINTAINERCLEANFILES=Makefile.in diff --git a/openbox/action.c b/openbox/action.c index 9015939e..2dde0f0b 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -548,6 +548,56 @@ Action *action_from_string(char *name) return a; } +Action *action_parse(xmlDocPtr doc, xmlNodePtr node) +{ + char *actname; + Action *act = NULL; + xmlNodePtr n; + + if (parse_attr_string("name", node, &actname)) { + if ((act = action_from_string(actname))) { + if (act->func == action_execute || act->func == action_restart) { + if ((n = parse_find_node("execute", node->xmlChildrenNode))) + act->data.execute.path = parse_string(doc, n); + } else if (act->func == action_showmenu) { + if ((n = parse_find_node("menu", node->xmlChildrenNode))) + act->data.showmenu.name = parse_string(doc, n); + } else if (act->func == action_desktop) { + if ((n = parse_find_node("desktop", node->xmlChildrenNode))) + act->data.desktop.desk = parse_int(doc, n); + if (act->data.desktop.desk > 0) act->data.desktop.desk--; + } else if (act->func == action_send_to_desktop) { + if ((n = parse_find_node("desktop", node->xmlChildrenNode))) + act->data.sendto.desk = parse_int(doc, n); + if (act->data.sendto.desk > 0) act->data.sendto.desk--; + } else if (act->func == action_move_relative_horz || + act->func == action_move_relative_vert || + act->func == action_resize_relative_horz || + act->func == action_resize_relative_vert) { + if ((n = parse_find_node("delta", node->xmlChildrenNode))) + act->data.relative.delta = parse_int(doc, n); + } else if (act->func == action_desktop_right || + act->func == action_desktop_left || + act->func == action_desktop_up || + act->func == action_desktop_down) { + if ((n = parse_find_node("wrap", node->xmlChildrenNode))) { + g_message("WRAP %d", parse_bool(doc, n)); + act->data.desktopdir.wrap = parse_bool(doc, n); + } + } else if (act->func == action_send_to_desktop_right || + act->func == action_send_to_desktop_left || + act->func == action_send_to_desktop_up || + act->func == action_send_to_desktop_down) { + if ((n = parse_find_node("wrap", node->xmlChildrenNode))) + act->data.sendtodir.wrap = parse_bool(doc, n); + if ((n = parse_find_node("follow", node->xmlChildrenNode))) + act->data.sendtodir.follow = parse_bool(doc, n); + } + } + } + return act; +} + void action_execute(union ActionData *data) { GError *e = NULL; diff --git a/openbox/action.h b/openbox/action.h index 5630f8f4..6c1c4d32 100644 --- a/openbox/action.h +++ b/openbox/action.h @@ -2,6 +2,7 @@ #define __action_h #include "client.h" +#include "parser/parse.h" /* These have to all have a Client* at the top even if they don't use it, so that I can set it blindly later on. So every function will have a Client* @@ -120,6 +121,7 @@ Action *action_new(void (*func)(union ActionData *data)); */ Action *action_from_string(char *name); +Action *action_parse(xmlDocPtr doc, xmlNodePtr node); void action_free(Action *a); /* Execute */ diff --git a/openbox/config.c b/openbox/config.c index c3fa786c..491097e4 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -1,5 +1,5 @@ #include "config.h" -#include "parse.h" +#include "parser/parse.h" gboolean config_focus_new; gboolean config_focus_follow; diff --git a/openbox/focus.c b/openbox/focus.c index 1de349ba..de98d63b 100644 --- a/openbox/focus.c +++ b/openbox/focus.c @@ -10,7 +10,6 @@ #include "prop.h" #include "dispatch.h" #include "focus.h" -#include "parse.h" #include "stacking.h" #include "popup.h" diff --git a/openbox/openbox.c b/openbox/openbox.c index 2b4dddce..0455e88c 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -12,13 +12,13 @@ #include "moveresize.h" #include "frame.h" #include "extensions.h" -#include "parse.h" #include "grab.h" #include "plugin.h" #include "timer.h" #include "group.h" #include "config.h" #include "gettext.h" +#include "parser/parse.h" #include "render/render.h" #include "render/font.h" #include "render/theme.h" @@ -66,6 +66,8 @@ int main(int argc, char **argv) sigset_t sigset; char *path; char *theme; + xmlDocPtr doc; + xmlNodePtr node; ob_state = State_Starting; @@ -180,7 +182,8 @@ int main(int argc, char **argv) /* set up the kernel config shit */ config_startup(); /* parse/load user options */ - parse_config(); + if (parse_load_rc(&doc, &node)) + parse_tree(doc, node->xmlChildrenNode, NULL); /* we're done with parsing now, kill it */ parse_shutdown(); diff --git a/openbox/parse.c b/openbox/parse.c deleted file mode 100644 index 8f9c82fb..00000000 --- a/openbox/parse.c +++ /dev/null @@ -1,243 +0,0 @@ -#include "parse.h" -#include <glib.h> - -struct Callback { - char *tag; - ParseCallback func; - void *data; -}; - -static GHashTable *callbacks; -static xmlDocPtr doc_config = NULL; - -static void destfunc(struct Callback *c) -{ - g_free(c->tag); - g_free(c); -} - -void parse_startup() -{ - callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, - (GDestroyNotify)destfunc); -} - -void parse_shutdown() -{ - xmlFree(doc_config); - doc_config = NULL; - - g_hash_table_destroy(callbacks); -} - -void parse_register(const char *tag, ParseCallback func, void *data) -{ - struct Callback *c; - - if ((c = g_hash_table_lookup(callbacks, tag))) { - g_warning("tag '%s' already registered", tag); - return; - } - - c = g_new(struct Callback, 1); - c->tag = g_strdup(tag); - c->func = func; - c->data = data; - g_hash_table_insert(callbacks, c->tag, c); -} - -void parse_config() -{ - char *path; - xmlNodePtr node = NULL; - - xmlLineNumbersDefault(1); - - path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL); - if ((doc_config = xmlParseFile(path))) { - node = xmlDocGetRootElement(doc_config); - if (!node) { - xmlFreeDoc(doc_config); - doc_config = NULL; - g_warning("%s is an empty document", path); - } else { - if (xmlStrcasecmp(node->name, (const xmlChar*)"openbox_config")) { - xmlFreeDoc(doc_config); - doc_config = NULL; - g_warning("document %s is of wrong type. root node is " - "not 'openbox_config'", path); - } - } - } - g_free(path); - if (!doc_config) { - path = g_build_filename(RCDIR, "rc3", NULL); - if ((doc_config = xmlParseFile(path))) { - node = xmlDocGetRootElement(doc_config); - if (!node) { - xmlFreeDoc(doc_config); - doc_config = NULL; - g_warning("%s is an empty document", path); - } else { - if (xmlStrcasecmp(node->name, - (const xmlChar*)"openbox_config")) { - xmlFreeDoc(doc_config); - doc_config = NULL; - g_warning("document %s is of wrong type. root node is " - "not 'openbox_config'", path); - } - } - } - g_free(path); - } - if (!doc_config) { - g_message("unable to find a valid config file, using defaults"); - } else { - parse_tree(doc_config, node->xmlChildrenNode, NULL); - } -} - -void parse_tree(xmlDocPtr doc, xmlNodePtr node, void *nothing) -{ - while (node) { - struct Callback *c = g_hash_table_lookup(callbacks, node->name); - - if (c) - c->func(doc, node->xmlChildrenNode, c->data); - - node = node->next; - } -} - -char *parse_string(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE); - char *s = g_strdup((char*)c); - xmlFree(c); - return s; -} - -int parse_int(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE); - int i = atoi((char*)c); - xmlFree(c); - return i; -} - -gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE); - gboolean b = FALSE; - if (!xmlStrcasecmp(c, (const xmlChar*) "true")) - b = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "yes")) - b = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "on")) - b = TRUE; - xmlFree(c); - return b; -} - -gboolean parse_contains(const char *val, xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE); - gboolean r; - r = !xmlStrcasecmp(c, (const xmlChar*) val); - xmlFree(c); - return r; -} - -xmlNodePtr parse_find_node(const char *tag, xmlNodePtr node) -{ - while (node) { - if (!xmlStrcasecmp(node->name, (const xmlChar*) tag)) - return node; - node = node->next; - } - return NULL; -} - -gboolean parse_attr_int(const char *name, xmlNodePtr node, int *value) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) { - *value = atoi((char*)c); - r = TRUE; - } - xmlFree(c); - return r; -} - -gboolean parse_attr_string(const char *name, xmlNodePtr node, char **value) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) { - *value = g_strdup((char*)c); - r = TRUE; - } - xmlFree(c); - return r; -} - -Action *parse_action(xmlDocPtr doc, xmlNodePtr node) -{ - char *actname; - Action *act = NULL; - xmlNodePtr n; - - if (parse_attr_string("name", node, &actname)) { - if ((act = action_from_string(actname))) { - if (act->func == action_execute || act->func == action_restart) { - if ((n = parse_find_node("execute", node->xmlChildrenNode))) - act->data.execute.path = parse_string(doc, n); - } else if (act->func == action_showmenu) { - if ((n = parse_find_node("menu", node->xmlChildrenNode))) - act->data.showmenu.name = parse_string(doc, n); - } else if (act->func == action_desktop) { - if ((n = parse_find_node("desktop", node->xmlChildrenNode))) - act->data.desktop.desk = parse_int(doc, n); - if (act->data.desktop.desk > 0) act->data.desktop.desk--; - } else if (act->func == action_send_to_desktop) { - if ((n = parse_find_node("desktop", node->xmlChildrenNode))) - act->data.sendto.desk = parse_int(doc, n); - if (act->data.sendto.desk > 0) act->data.sendto.desk--; - } else if (act->func == action_move_relative_horz || - act->func == action_move_relative_vert || - act->func == action_resize_relative_horz || - act->func == action_resize_relative_vert) { - if ((n = parse_find_node("delta", node->xmlChildrenNode))) - act->data.relative.delta = parse_int(doc, n); - } else if (act->func == action_desktop_right || - act->func == action_desktop_left || - act->func == action_desktop_up || - act->func == action_desktop_down) { - if ((n = parse_find_node("wrap", node->xmlChildrenNode))) { - g_message("WRAP %d", parse_bool(doc, n)); - act->data.desktopdir.wrap = parse_bool(doc, n); - } - } else if (act->func == action_send_to_desktop_right || - act->func == action_send_to_desktop_left || - act->func == action_send_to_desktop_up || - act->func == action_send_to_desktop_down) { - if ((n = parse_find_node("wrap", node->xmlChildrenNode))) - act->data.sendtodir.wrap = parse_bool(doc, n); - if ((n = parse_find_node("follow", node->xmlChildrenNode))) - act->data.sendtodir.follow = parse_bool(doc, n); - } - } - } - return act; -} - -gboolean parse_attr_contains(const char *val, xmlNodePtr node, - const char *name) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r; - r = !xmlStrcasecmp(c, (const xmlChar*) val); - xmlFree(c); - return r; -} diff --git a/openbox/parse.h b/openbox/parse.h deleted file mode 100644 index 199e8104..00000000 --- a/openbox/parse.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __parse_h -#define __parse_h - -#include "action.h" - -#include <libxml/parser.h> -#include <glib.h> - -typedef void (*ParseCallback)(xmlDocPtr doc, xmlNodePtr node, void *data); - -void parse_startup(); -void parse_shutdown(); - -void parse_register(const char *tag, ParseCallback func, void *data); - -void parse_config(); - -void parse_tree(xmlDocPtr doc, xmlNodePtr node, void *nothing); - - -/* helpers */ - -xmlNodePtr parse_find_node(const char *tag, xmlNodePtr node); - -char *parse_string(xmlDocPtr doc, xmlNodePtr node); -int parse_int(xmlDocPtr doc, xmlNodePtr node); -gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node); - -gboolean parse_contains(const char *val, xmlDocPtr doc, xmlNodePtr node); -gboolean parse_attr_contains(const char *val, xmlNodePtr node, - const char *name); - -gboolean parse_attr_string(const char *name, xmlNodePtr node, char **value); -gboolean parse_attr_int(const char *name, xmlNodePtr node, int *value); - -Action *parse_action(xmlDocPtr doc, xmlNodePtr node); - -#endif diff --git a/openbox/plugin.c b/openbox/plugin.c index a47052e4..747bde6f 100644 --- a/openbox/plugin.c +++ b/openbox/plugin.c @@ -1,12 +1,8 @@ +#include "plugins/interface.h" + #include <glib.h> #include <gmodule.h> -typedef void (*PluginSetupConfig)(); -typedef void (*PluginStartup)(); -typedef void (*PluginShutdown)(); -typedef void *(*PluginCreate)(/* TODO */); -typedef void (*PluginDestroy)(void *); - typedef struct { GModule *module; char *name; |
