summaryrefslogtreecommitdiffstats
path: root/include/commands.h
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-22 14:14:13 +0200
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-22 23:36:24 +0200
commitaf30a1b67c22aa54dad4e1a0ee3aacb537c4ab92 (patch)
tree013c1860550bb3c190095fd0633c08aca16838d1 /include/commands.h
parentipc: Return correct status in ipc reply. (diff)
downloadsway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.tar.gz
sway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.tar.zst
sway-af30a1b67c22aa54dad4e1a0ee3aacb537c4ab92.zip
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 'include/commands.h')
-rw-r--r--include/commands.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/include/commands.h b/include/commands.h
index 1b4cd9ca..1e0a1452 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -1,22 +1,34 @@
1#ifndef _SWAY_COMMANDS_H 1#ifndef _SWAY_COMMANDS_H
2#define _SWAY_COMMANDS_H 2#define _SWAY_COMMANDS_H
3#include <stdbool.h> 3#include <stdbool.h>
4#include <json-c/json.h>
4#include "config.h" 5#include "config.h"
5 6
6 7
7enum cmd_status { 8enum cmd_status {
8 CMD_SUCCESS, 9 CMD_SUCCESS,
9 CMD_FAILURE, 10 CMD_FAILURE, // was or at least could be executed
10 CMD_INVALID, 11 CMD_INVALID, // unknown or parse error
11 CMD_DEFER, 12 CMD_DEFER,
12 // Config Blocks 13 // Config Blocks
13 CMD_BLOCK_END, 14 CMD_BLOCK_END,
14 CMD_BLOCK_MODE, 15 CMD_BLOCK_MODE,
15}; 16};
16 17
17enum cmd_status handle_command(char *command); 18struct cmd_results {
19 enum cmd_status status;
20
21 const char *input;
22 char *error;
23};
24
25struct cmd_results *handle_command(char *command);
18// Handles commands during config 26// Handles commands during config
19enum cmd_status config_command(char *command); 27struct cmd_results *config_command(char *command);
28
29struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...);
30void free_cmd_results(struct cmd_results *results);
31const char *cmd_results_to_json(struct cmd_results *results);
20 32
21void remove_view_from_scratchpad(); 33void remove_view_from_scratchpad();
22 34