Convert the focus parsing section to the new config parser
authorDana Jansens <danakj@orodu.net>
Mon, 8 Aug 2011 17:18:52 +0000 (13:18 -0400)
committerDana Jansens <danakj@orodu.net>
Mon, 8 Aug 2011 19:15:31 +0000 (15:15 -0400)
openbox/config.c
openbox/config.h
openbox/config_parser.c
openbox/config_parser.h
openbox/openbox.c

index 5b7caad178843d19c561d5b59cb5113dd06d2db2..f3b161dee4de8380c3d8b382fa456a5d9c5fb891 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 #include "config.h"
-#include "config_value.h"
+#include "config_parser.h"
 #include "keyboard.h"
 #include "mouse.h"
 #include "action.h"
@@ -540,28 +540,6 @@ static void parse_mouse(xmlNodePtr node, gpointer d)
     }
 }
 
-static void parse_focus(xmlNodePtr node, gpointer d)
-{
-    xmlNodePtr n;
-
-    node = node->children;
-
-    if ((n = obt_xml_find_sibling(node, "focusNew")))
-        config_focus_new = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "followMouse")))
-        config_focus_follow = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "focusDelay")))
-        config_focus_delay = obt_xml_node_int(n);
-    if ((n = obt_xml_find_sibling(node, "raiseOnFocus")))
-        config_focus_raise = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "focusLast")))
-        config_focus_last = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "underMouse")))
-        config_focus_under_mouse = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "unfocusOnLeave")))
-        config_unfocus_leave = obt_xml_node_bool(n);
-}
-
 static void parse_placement(xmlNodePtr node, gpointer d)
 {
     xmlNodePtr n;
@@ -1011,17 +989,19 @@ static void bind_default_mouse(void)
     action_parser_unref(p);
 }
 
-void config_startup(ObtXmlInst *i)
+#define BOOL config_parser_bool
+#define INT config_parser_int
+#define STRING config_parser_string
+
+void config_startup(ObConfigParser *p, ObtXmlInst *i)
 {
-    config_focus_new = TRUE;
-    config_focus_follow = FALSE;
-    config_focus_delay = 0;
-    config_focus_raise = FALSE;
-    config_focus_last = TRUE;
-    config_focus_under_mouse = FALSE;
-    config_unfocus_leave = FALSE;
-
-    obt_xml_register(i, "focus", parse_focus, NULL);
+    BOOL(p, "focus/focusNew", "yes", &config_focus_new);
+    BOOL(p, "focus/followMouse", "no", &config_focus_follow);
+    INT(p, "focus/focusDelay", "0", &config_focus_delay);
+    BOOL(p, "focus/raiseOnFocus", "no", &config_focus_raise);
+    BOOL(p, "focus/focusLast", "yes", &config_focus_last);
+    BOOL(p, "focus/underMouse", "no", &config_focus_under_mouse);
+    BOOL(p, "focus/unfocusOnLeave", "no", &config_unfocus_leave);
 
     config_place_policy = OB_PLACE_POLICY_SMART;
     config_place_center = TRUE;
index 834193de66c42a3b36f8c7cce39abde2c5a1e6f2..cae09e59965ad267e99c503cf468475f13d82cfc 100644 (file)
@@ -33,6 +33,8 @@
 
 #include <glib.h>
 
+struct _ObConfigParser;
+
 typedef struct _ObAppSettings ObAppSettings;
 
 struct _ObAppSettings
@@ -204,7 +206,7 @@ extern GSList *config_menu_files;
 /*! Per app settings */
 extern GSList *config_per_app_settings;
 
-void config_startup(ObtXmlInst *i);
+void config_startup(struct _ObConfigParser *p, ObtXmlInst *i);
 void config_shutdown(void);
 
 /*! Create an ObAppSettings structure with the default values */
index cd9a6e18b4aad36f612dc2cb27d3a64b9990d168..941216b3ca7ec0ba0bd8b0b4914d5c8210efdbc3 100644 (file)
@@ -151,7 +151,7 @@ void config_parser_bool(ObConfigParser *p,
 }
 
 void config_parser_int(ObConfigParser *p,
-                       const gchar *name, const gchar *def, gint *v)
+                       const gchar *name, const gchar *def, guint *v)
 {
     ObConfigValue *cv = config_value_new_string(def);
     add(p, name, cv, OB_CONFIG_VALUE_INTEGER, (ObConfigValueDataPtr)v);
@@ -338,15 +338,6 @@ void config_parser_options(void)
         obt_xml_new_file(i, "openbox_config");
     root = obt_xml_root(i);
 
-    n = obt_xml_tree_get_node("focus");
-    config_focus_new = read_bool(n, "focusnew", TRUE);
-    config_focus_follow = read_bool(n, "followmouse", FALSE);
-    config_focus_delay = read_int(n, "focusdelay", 0);
-    config_focus_raise = read_bool(n, "raiseonfocus", FALSE);
-    config_focus_last = read_bool(n, "focuslast", TRUE);
-    config_focus_under_mouse = read_bool(n, "undermouse", FALSE);
-    config_unfocus_leave = read_bool(n, "unfocusonleave", FALSE);
-
     n = obt_xml_tree_get_node("placement");
     config_place_policy = read_enum(
         n, "policy",
index 50b6db5bd0bc01bf25701001d211de8f6dc0a682..877cc2d51c9770c1e0e5b09168c70ae4da10326f 100644 (file)
@@ -35,7 +35,7 @@ void config_parser_unref(ObConfigParser *p);
 void config_parser_bool(ObConfigParser *p,
                         const gchar *name, const gchar *def, gboolean *v);
 void config_parser_int(ObConfigParser *p,
-                       const gchar *name, const gchar *def, gint *v);
+                       const gchar *name, const gchar *def, guint *v);
 void config_parser_string(ObConfigParser *p,
                           const gchar *name, const gchar *def,
                           const gchar **v);
index 14d0bd279a0d5067121448ea177a4dfee2622ed1..a27106b46e18c2bb7fe23e73a60790ad6decc601 100644 (file)
@@ -41,6 +41,7 @@
 #include "grab.h"
 #include "group.h"
 #include "config.h"
+#include "config_parser.h"
 #include "ping.h"
 #include "prompt.h"
 #include "gettext.h"
@@ -230,17 +231,19 @@ gint main(gint argc, gchar **argv)
             if (reconfigure) obt_keyboard_reload();
 
             {
+                ObConfigParser *p;
                 ObtXmlInst *i;
 
                 /* startup the parsing so everything can register sections
                    of the rc */
+                p = config_parser_new();
                 i = obt_xml_instance_new();
 
                 /* register all the available actions and filters */
                 action_startup(reconfigure);
                 action_filter_startup(reconfigure);
                 /* start up config which sets up with the parser */
-                config_startup(i);
+                config_startup(p, i);
 
                 /* parse/load user options */
                 if ((config_file &&
@@ -248,6 +251,7 @@ gint main(gint argc, gchar **argv)
                     obt_xml_load_config_file(i, "openbox", "rc",
                                              "openbox_config"))
                 {
+                    config_parser_read(p, i);
                     obt_xml_tree_from_root(i);
                     obt_xml_close(i);
                 }
@@ -268,6 +272,7 @@ gint main(gint argc, gchar **argv)
 
                 /* we're done with parsing now, kill it */
                 obt_xml_instance_unref(i);
+                config_parser_unref(p);
             }
 
             /* load the theme specified in the rc file */