]> git.sur5r.net Git - i3/i3/blobdiff - src/util.c
Implement mapping from string to layout as extra function
[i3/i3] / src / util.c
index cfe4c953db029c1333e4f9ed90396cb8d79c58a6..b6f45fdef56ff710f1f96d60222d12a47eaca223 100644 (file)
@@ -66,6 +66,31 @@ __attribute__((pure)) bool name_is_digits(const char *name) {
     return true;
 }
 
+/**
+ * Set 'out' to the layout_t value for the given layout. The function
+ * returns true on success or false if the passed string is not a valid
+ * layout name.
+ *
+ */
+bool layout_from_name(const char *layout_str, layout_t *out) {
+    if (strcmp(layout_str, "default") == 0) {
+        *out = L_DEFAULT;
+    } else if (strcasecmp(layout_str, "stacked") == 0 ||
+               strcasecmp(layout_str, "stacking") == 0) {
+        *out = L_STACKED;
+    } else if (strcasecmp(layout_str, "tabbed") == 0) {
+        *out = L_TABBED;
+    } else if (strcasecmp(layout_str, "splitv") == 0) {
+        *out = L_SPLITV;
+    } else if (strcasecmp(layout_str, "splith") == 0) {
+        *out = L_SPLITH;
+    } else {
+        return false;
+    }
+
+    return true;
+}
+
 /*
  * Parses the workspace name as a number. Returns -1 if the workspace should be
  * interpreted as a "named workspace".