]> git.sur5r.net Git - i3/i3/blobdiff - src/commands.c
Merge pull request #1521 from Airblader/feature-use-refactored-function
[i3/i3] / src / commands.c
index 49005ba7d5421c98f80041cbb1fdf1088bdcd63a..f5f8d05c7c9a1befe8b9ea4112edc93dcdca8aed 100644 (file)
             y(map_close);                   \
         }                                   \
     } while (0)
-#define yerror(message)                     \
-    do {                                    \
-        if (cmd_output->json_gen != NULL) { \
-            y(map_open);                    \
-            ystr("success");                \
-            y(bool, false);                 \
-            ystr("error");                  \
-            ystr(message);                  \
-            y(map_close);                   \
-        }                                   \
+#define yerror(format, ...)                             \
+    do {                                                \
+        if (cmd_output->json_gen != NULL) {             \
+            char *message;                              \
+            sasprintf(&message, format, ##__VA_ARGS__); \
+            y(map_open);                                \
+            ystr("success");                            \
+            y(bool, false);                             \
+            ystr("error");                              \
+            ystr(message);                              \
+            y(map_close);                               \
+            free(message);                              \
+        }                                               \
     } while (0)
 
 /** When the command did not include match criteria (!), we use the currently
@@ -552,8 +555,7 @@ void cmd_move_con_to_workspace_number(I3_CMD, char *which) {
 
     if (parsed_num == -1) {
         LOG("Could not parse initial part of \"%s\" as a number.\n", which);
-        // TODO: better error message
-        yerror("Could not parse number");
+        yerror("Could not parse number \"%s\"", which);
         return;
     }
 
@@ -878,11 +880,15 @@ void cmd_nop(I3_CMD, char *comment) {
 void cmd_append_layout(I3_CMD, char *path) {
     LOG("Appending layout \"%s\"\n", path);
 
+    /* Make sure we allow paths like '~/.i3/layout.json' */
+    path = resolve_tilde(path);
+
     json_content_t content = json_determine_content(path);
     LOG("JSON content = %d\n", content);
     if (content == JSON_CONTENT_UNKNOWN) {
         ELOG("Could not determine the contents of \"%s\", not loading.\n", path);
-        ysuccess(false);
+        yerror("Could not determine the contents of \"%s\".", path);
+        free(path);
         return;
     }
 
@@ -924,6 +930,7 @@ void cmd_append_layout(I3_CMD, char *path) {
     if (content == JSON_CONTENT_WORKSPACE)
         ipc_send_workspace_event("restored", parent, NULL);
 
+    free(path);
     cmd_output->needs_tree_render = true;
 }
 
@@ -980,8 +987,7 @@ void cmd_workspace_number(I3_CMD, char *which) {
 
     if (parsed_num == -1) {
         LOG("Could not parse initial part of \"%s\" as a number.\n", which);
-        // TODO: better error message
-        yerror("Could not parse number");
+        yerror("Could not parse number \"%s\"", which);
         return;
     }
 
@@ -1149,28 +1155,13 @@ void cmd_move_con_to_output(I3_CMD, char *name) {
 
     HANDLE_EMPTY_MATCH;
 
-    /* get the output */
     Output *current_output = NULL;
-    Output *output;
-
     // TODO: fix the handling of criteria
     TAILQ_FOREACH(current, &owindows, owindows)
     current_output = get_output_of_con(current->con);
-
     assert(current_output != NULL);
 
-    // TODO: clean this up with commands.spec as soon as we switched away from the lex/yacc command parser
-    if (strcasecmp(name, "up") == 0)
-        output = get_output_next_wrap(D_UP, current_output);
-    else if (strcasecmp(name, "down") == 0)
-        output = get_output_next_wrap(D_DOWN, current_output);
-    else if (strcasecmp(name, "left") == 0)
-        output = get_output_next_wrap(D_LEFT, current_output);
-    else if (strcasecmp(name, "right") == 0)
-        output = get_output_next_wrap(D_RIGHT, current_output);
-    else
-        output = get_output_by_name(name);
-
+    Output *output = get_output_from_string(current_output, name);
     if (!output) {
         LOG("No such output found.\n");
         ysuccess(false);
@@ -1891,10 +1882,7 @@ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
     }
 
     if (!workspace) {
-        // TODO: we should include the old workspace name here and use yajl for
-        // generating the reply.
-        // TODO: better error message
-        yerror("Old workspace not found");
+        yerror("Old workspace \"%s\" not found", old_name);
         return;
     }
 
@@ -1904,10 +1892,7 @@ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
                !strcasecmp(child->name, new_name));
 
     if (check_dest != NULL) {
-        // TODO: we should include the new workspace name here and use yajl for
-        // generating the reply.
-        // TODO: better error message
-        yerror("New workspace already exists");
+        yerror("New workspace \"%s\" already exists", new_name);
         return;
     }