]> 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 67dc5c92206ac778d44df861d5c1b7c58bfe5071..b6f45fdef56ff710f1f96d60222d12a47eaca223 100644 (file)
@@ -1,5 +1,3 @@
-#undef I3__FILE__
-#define I3__FILE__ "util.c"
 /*
  * vim:ts=4:sw=4:expandtab
  *
@@ -68,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".
@@ -145,20 +168,6 @@ void exec_i3_utility(char *name, char *argv[]) {
     _exit(2);
 }
 
-/*
- * Checks a generic cookie for errors and quits with the given message if there
- * was an error.
- *
- */
-void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message) {
-    xcb_generic_error_t *error = xcb_request_check(conn, cookie);
-    if (error != NULL) {
-        fprintf(stderr, "ERROR: %s (X error %d)\n", err_message, error->error_code);
-        xcb_disconnect(conn);
-        exit(-1);
-    }
-}
-
 /*
  * Checks if the given path exists by calling stat().
  *
@@ -343,6 +352,7 @@ char *pango_escape_markup(char *input) {
 
     char *escaped = g_markup_escape_text(input, -1);
     FREE(input);
+
     return escaped;
 }