Convert the placement parsing section to the new config parser configparser github/configparser origin/configparser
authorDana Jansens <danakj@orodu.net>
Mon, 8 Aug 2011 18:47:09 +0000 (14:47 -0400)
committerDana Jansens <danakj@orodu.net>
Mon, 8 Aug 2011 19:15:31 +0000 (15:15 -0400)
data/rc.xml
openbox/config.c

index 7598a72ca300235cae281d9c9924f881c8f9f2df..41d407f69de0f9ffc124ab4ac037f8cd5b5cdfe7 100644 (file)
   <!-- with Smart placement on a multi-monitor system, try to place new windows
        on: 'Any' - any monitor, 'Mouse' - where the mouse is, 'Active' - where
        the active window is, 'Primary' - only on the primary monitor -->
-  <primaryMonitor>1</primaryMonitor>
+  <primaryMonitorType>Fixed</primaryMonitorType>
   <!-- The monitor where Openbox should place popup dialogs such as the
-       focus cycling popup, or the desktop switch popup.  It can be an index
-       from 1, specifying a particular monitor.  Or it can be one of the
-       following: 'Mouse' - where the mouse is, or
+       focus cycling popup, or the desktop switch popup.  It can be one of the
+       following: 'Fixed' - use the monitor in the primaryMonitor tag
+                  'Mouse' - where the mouse is, or
                   'Active' - where the active window is -->
+  <primaryMonitor>1</primaryMonitor>
+  <!-- The monitor where Openbox should place popup dialogs such as the
+       focus cycling popup, or the desktop switch popup.  It is an index
+       from 1, specifying a particular monitor. -->
 </placement>
 
 <theme>
index f3b161dee4de8380c3d8b382fa456a5d9c5fb891..aba079d31172162c67a62e7248aa4f0c6f55f470 100644 (file)
@@ -540,34 +540,6 @@ static void parse_mouse(xmlNodePtr node, gpointer d)
     }
 }
 
-static void parse_placement(xmlNodePtr node, gpointer d)
-{
-    xmlNodePtr n;
-
-    node = node->children;
-
-    if ((n = obt_xml_find_sibling(node, "policy")))
-        if (obt_xml_node_contains(n, "UnderMouse"))
-            config_place_policy = OB_PLACE_POLICY_MOUSE;
-    if ((n = obt_xml_find_sibling(node, "center")))
-        config_place_center = obt_xml_node_bool(n);
-    if ((n = obt_xml_find_sibling(node, "monitor"))) {
-        if (obt_xml_node_contains(n, "active"))
-            config_place_monitor = OB_PLACE_MONITOR_ACTIVE;
-        else if (obt_xml_node_contains(n, "mouse"))
-            config_place_monitor = OB_PLACE_MONITOR_MOUSE;
-        else if (obt_xml_node_contains(n, "any"))
-            config_place_monitor = OB_PLACE_MONITOR_ANY;
-    }
-    if ((n = obt_xml_find_sibling(node, "primaryMonitor"))) {
-        config_primary_monitor_index = obt_xml_node_int(n);
-        if (!config_primary_monitor_index) {
-            if (obt_xml_node_contains(n, "mouse"))
-                config_primary_monitor = OB_PLACE_MONITOR_MOUSE;
-        }
-    }
-}
-
 static void parse_margins(xmlNodePtr node, gpointer d)
 {
     xmlNodePtr n;
@@ -992,6 +964,7 @@ static void bind_default_mouse(void)
 #define BOOL config_parser_bool
 #define INT config_parser_int
 #define STRING config_parser_string
+#define ENUM config_parser_enum
 
 void config_startup(ObConfigParser *p, ObtXmlInst *i)
 {
@@ -1003,14 +976,34 @@ void config_startup(ObConfigParser *p, ObtXmlInst *i)
     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;
-    config_place_monitor = OB_PLACE_MONITOR_PRIMARY;
-
-    config_primary_monitor_index = 1;
-    config_primary_monitor = OB_PLACE_MONITOR_ACTIVE;
-
-    obt_xml_register(i, "placement", parse_placement, NULL);
+    {
+        static ObConfigValueEnum policies[] = {
+            {"smart", OB_PLACE_POLICY_SMART},
+            {"undermouse", OB_PLACE_POLICY_MOUSE},
+            {0, 0}};
+        ENUM(p, "placement/policy", "smart", &config_place_policy, policies);
+    }
+    BOOL(p, "placement/center", "true", &config_place_center);
+    {
+        static ObConfigValueEnum monitors[] = {
+            {"any", OB_PLACE_MONITOR_ANY},
+            {"active", OB_PLACE_MONITOR_ACTIVE},
+            {"mouse", OB_PLACE_MONITOR_MOUSE},
+            {"primary", OB_PLACE_MONITOR_PRIMARY},
+            {0, 0}};
+        ENUM(p, "placement/monitor", "primary", &config_place_monitor,
+             monitors);
+    }
+    INT(p, "placement/primaryMonitor", "1",
+        &config_primary_monitor_index);
+    {
+        static ObConfigValueEnum primaries[] = {
+            {"active", OB_PLACE_MONITOR_ACTIVE},
+            {"mouse", OB_PLACE_MONITOR_MOUSE},
+            {"fixed", 0}};
+        ENUM(p, "placement/primaryMonitorType", "fixed",
+             &config_primary_monitor, primaries);
+    }
 
     STRUT_PARTIAL_SET(config_margins, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);