mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-28 22:23:42 +01:00
Add framework for switching command sets
This will allow the bar {} block to have a different command set (and also bar { colors { } }.
This commit is contained in:
parent
4f89735fc4
commit
44d0f731c3
3 changed files with 30 additions and 7 deletions
|
@ -41,7 +41,7 @@ struct cmd_results *handle_command(char *command);
|
|||
*
|
||||
* Do not use this under normal conditions.
|
||||
*/
|
||||
struct cmd_results *config_command(char *command);
|
||||
struct cmd_results *config_command(char *command, enum cmd_status block);
|
||||
|
||||
/**
|
||||
* Allocates a cmd_results object.
|
||||
|
|
|
@ -1463,15 +1463,38 @@ static struct cmd_handler handlers[] = {
|
|||
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
|
||||
};
|
||||
|
||||
static struct cmd_handler bar_handlers[] = {
|
||||
{ "binding_mode_indicator", NULL },
|
||||
{ "bindsym", NULL },
|
||||
{ "colors", NULL },
|
||||
{ "font", NULL },
|
||||
{ "hidden_state", NULL },
|
||||
{ "id", NULL },
|
||||
{ "mode", NULL },
|
||||
{ "modifier", NULL },
|
||||
{ "output", NULL },
|
||||
{ "position", NULL },
|
||||
{ "seperator_symbol", NULL },
|
||||
{ "status_command", NULL },
|
||||
{ "strip_workspace_numbers", NULL },
|
||||
{ "tray_output", NULL },
|
||||
{ "tray_padding", NULL },
|
||||
{ "workspace_buttons", NULL },
|
||||
};
|
||||
|
||||
static int handler_compare(const void *_a, const void *_b) {
|
||||
const struct cmd_handler *a = _a;
|
||||
const struct cmd_handler *b = _b;
|
||||
return strcasecmp(a->command, b->command);
|
||||
}
|
||||
|
||||
static struct cmd_handler *find_handler(char *line) {
|
||||
static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
||||
struct cmd_handler *h = handlers;
|
||||
if (block == CMD_BLOCK_BAR) {
|
||||
h = bar_handlers;
|
||||
}
|
||||
struct cmd_handler d = { .command=line };
|
||||
struct cmd_handler *res = bsearch(&d, handlers,
|
||||
struct cmd_handler *res = bsearch(&d, h,
|
||||
sizeof(handlers) / sizeof(struct cmd_handler),
|
||||
sizeof(struct cmd_handler), handler_compare);
|
||||
return res;
|
||||
|
@ -1537,7 +1560,7 @@ struct cmd_results *handle_command(char *_exec) {
|
|||
if (argc>1 && (*argv[1] == '\"' || *argv[1] == '\'')) {
|
||||
strip_quotes(argv[1]);
|
||||
}
|
||||
struct cmd_handler *handler = find_handler(argv[0]);
|
||||
struct cmd_handler *handler = find_handler(argv[0], CMD_BLOCK_END);
|
||||
if (!handler) {
|
||||
if (results) {
|
||||
free_cmd_results(results);
|
||||
|
@ -1574,7 +1597,7 @@ struct cmd_results *handle_command(char *_exec) {
|
|||
// be chained together)
|
||||
// 4) handle_command handles all state internally while config_command has some
|
||||
// state handled outside (notably the block mode, in read_config)
|
||||
struct cmd_results *config_command(char *exec) {
|
||||
struct cmd_results *config_command(char *exec, enum cmd_status block) {
|
||||
struct cmd_results *results = NULL;
|
||||
int argc;
|
||||
char **argv = split_args(exec, &argc);
|
||||
|
@ -1589,7 +1612,7 @@ struct cmd_results *config_command(char *exec) {
|
|||
results = cmd_results_new(CMD_BLOCK_END, NULL, NULL);
|
||||
goto cleanup;
|
||||
}
|
||||
struct cmd_handler *handler = find_handler(argv[0]);
|
||||
struct cmd_handler *handler = find_handler(argv[0], block);
|
||||
if (!handler) {
|
||||
char *input = argv[0] ? argv[0] : "(empty)";
|
||||
results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command");
|
||||
|
|
|
@ -224,7 +224,7 @@ bool read_config(FILE *file, bool is_active) {
|
|||
if (line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
struct cmd_results *res = config_command(line);
|
||||
struct cmd_results *res = config_command(line, block);
|
||||
switch(res->status) {
|
||||
case CMD_FAILURE:
|
||||
case CMD_INVALID:
|
||||
|
|
Loading…
Reference in a new issue