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
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;
}
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;
}
if (content == JSON_CONTENT_WORKSPACE)
ipc_send_workspace_event("restored", parent, NULL);
+ free(path);
cmd_output->needs_tree_render = true;
}
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;
}
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);
}
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;
}
!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;
}