diff options
author | S. Christoffer Eliesen <[email protected]> | 2015-10-22 14:14:13 +0200 |
---|---|---|
committer | S. Christoffer Eliesen <[email protected]> | 2015-10-22 23:36:24 +0200 |
commit | af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92 (patch) | |
tree | 013c1860550bb3c190095fd0633c08aca16838d1 /sway/handlers.c | |
parent | 544c6c412a3e432cb88a4454d0ccfab2856fac8c (diff) |
ipc,commands,config: Replace cmd_status enum with cmd_results struct.
In i3 the ipc reply will contain a human readable error message, and
this patch replicates that behaviour.
However, that error message is also useful for logging, which this
patch takes advantage of.
E.g. instead of logging errors directly in commands.c/checkargs, it is
fed back to the caller which eventually ends up logging everything with
maximum context available (config.c/read_config).
So instead of logging e.g. "Error on line 'exit'" it will now log:
"Error on line 'exit': Can't execute from config."
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index 6120e663..24105130 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -341,7 +341,11 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier } if (match) { if (state == WLC_KEY_STATE_PRESSED) { - handle_command(binding->command); + struct cmd_results *res = handle_command(binding->command); + if (res->status != CMD_SUCCESS) { + sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); + } + free_cmd_results(res); return EVENT_HANDLED; } else if (state == WLC_KEY_STATE_RELEASED) { // TODO: --released @@ -544,8 +548,13 @@ static void handle_wlc_ready(void) { // Execute commands until there are none left config->active = true; while (config->cmd_queue->length) { - handle_command(config->cmd_queue->items[0]); - free(config->cmd_queue->items[0]); + char *line = config->cmd_queue->items[0]; + struct cmd_results *res = handle_command(line); + if (res->status != CMD_SUCCESS) { + sway_log(L_ERROR, "Error on line '%s': %s", line, res->error); + } + free_cmd_results(res); + free(line); list_del(config->cmd_queue, 0); } } |