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