2015-08-05 21:30:40 +00:00
|
|
|
#ifndef _SWAY_COMMANDS_H
|
|
|
|
#define _SWAY_COMMANDS_H
|
|
|
|
#include <stdbool.h>
|
2015-10-22 12:14:13 +00:00
|
|
|
#include <json-c/json.h>
|
2015-10-26 11:20:32 +00:00
|
|
|
#include <wlc/wlc.h>
|
2015-08-05 21:30:40 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Indicates the result of a command's execution.
|
|
|
|
*/
|
|
|
|
enum cmd_status {
|
|
|
|
CMD_SUCCESS, /**< The command was successful */
|
|
|
|
CMD_FAILURE, /**< The command resulted in an error */
|
|
|
|
CMD_INVALID, /**< Unknown command or parser error */
|
|
|
|
CMD_DEFER, /**< Command execution deferred */
|
2015-09-15 02:59:25 +00:00
|
|
|
// Config Blocks
|
|
|
|
CMD_BLOCK_END,
|
|
|
|
CMD_BLOCK_MODE,
|
2015-11-29 22:02:09 +00:00
|
|
|
CMD_BLOCK_BAR,
|
2016-01-17 10:53:37 +00:00
|
|
|
CMD_BLOCK_BAR_COLORS,
|
|
|
|
CMD_BLOCK_INPUT
|
2015-08-05 21:30:40 +00:00
|
|
|
};
|
|
|
|
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Stores the result of executing a command.
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
struct cmd_results {
|
|
|
|
enum cmd_status status;
|
2015-10-23 11:03:14 +00:00
|
|
|
char *input;
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Human friendly error message, or NULL on success
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
char *error;
|
|
|
|
};
|
|
|
|
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Parse and handles a command.
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
struct cmd_results *handle_command(char *command);
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Parse and handles a command during config file loading.
|
|
|
|
*
|
|
|
|
* Do not use this under normal conditions.
|
|
|
|
*/
|
2015-11-29 22:20:27 +00:00
|
|
|
struct cmd_results *config_command(char *command, enum cmd_status block);
|
2015-10-22 12:14:13 +00:00
|
|
|
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Allocates a cmd_results object.
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...);
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Frees a cmd_results object.
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
void free_cmd_results(struct cmd_results *results);
|
2015-11-08 17:06:12 +00:00
|
|
|
/**
|
|
|
|
* Serializes cmd_results to a JSON string.
|
|
|
|
*
|
|
|
|
* Free the JSON string later on.
|
|
|
|
*/
|
2015-10-22 12:14:13 +00:00
|
|
|
const char *cmd_results_to_json(struct cmd_results *results);
|
2015-08-05 21:30:40 +00:00
|
|
|
|
2016-05-23 12:42:03 +00:00
|
|
|
void remove_view_from_scratchpad(swayc_t *);
|
2015-08-30 02:14:13 +00:00
|
|
|
|
2015-08-05 21:30:40 +00:00
|
|
|
#endif
|