mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
mode supports multi token names
This commit is contained in:
parent
799ff640f8
commit
6388241abb
|
@ -13,7 +13,6 @@ struct cmd_handler {
|
|||
} config_type;
|
||||
};
|
||||
|
||||
struct cmd_handler *find_handler(char *line);
|
||||
bool handle_command(char *command);
|
||||
// Handles commands during config
|
||||
bool config_command(char *command);
|
||||
|
|
|
@ -368,7 +368,8 @@ static bool cmd_mode(int argc, char **argv) {
|
|||
if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) {
|
||||
return false;
|
||||
}
|
||||
const char *mode_name = argv[0];
|
||||
bool mode_make = strcmp(argv[argc-1], "{") == 0;
|
||||
const char *mode_name = join_args(argv, argc - mode_make);
|
||||
struct sway_mode *mode = NULL;
|
||||
// Find mode
|
||||
int i, len = config->modes->length;
|
||||
|
@ -380,14 +381,14 @@ static bool cmd_mode(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
// Create mode if it doesnt exist
|
||||
if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) {
|
||||
if (!mode && mode_make) {
|
||||
mode = malloc(sizeof*mode);
|
||||
mode->name = strdup(mode_name);
|
||||
mode->bindings = create_list();
|
||||
list_add(config->modes, mode);
|
||||
}
|
||||
if (!mode) {
|
||||
sway_log(L_ERROR, "Invalide mode `%s'", mode_name);
|
||||
sway_log(L_ERROR, "Unknown mode `%s'", mode_name);
|
||||
return false;
|
||||
}
|
||||
sway_log(L_DEBUG, "Switching to mode `%s'",mode->name);
|
||||
|
|
|
@ -99,7 +99,7 @@ void free_flat_list(list_t *list) {
|
|||
char **split_args(const char *start, int *argc) {
|
||||
*argc = 0;
|
||||
int alloc = 2;
|
||||
char **parts = malloc(sizeof(char *) * alloc);
|
||||
char **argv = malloc(sizeof(char *) * alloc);
|
||||
bool in_token = false;
|
||||
bool in_string = false;
|
||||
bool in_char = false;
|
||||
|
@ -132,15 +132,16 @@ char **split_args(const char *start, int *argc) {
|
|||
token[end - start] = '\0';
|
||||
strip_quotes(token);
|
||||
unescape_string(token);
|
||||
parts[*argc] = token;
|
||||
if (++*argc == alloc) {
|
||||
parts = realloc(parts, (alloc *= 2) * sizeof(char *));
|
||||
argv[*argc] = token;
|
||||
if (++*argc + 1 == alloc) {
|
||||
argv = realloc(argv, (alloc *= 2) * sizeof(char *));
|
||||
}
|
||||
}
|
||||
in_token = false;
|
||||
escaped = false;
|
||||
}
|
||||
return parts;
|
||||
argv[*argc] = NULL;
|
||||
return argv;
|
||||
}
|
||||
|
||||
void free_argv(int argc, char **argv) {
|
||||
|
|
Loading…
Reference in a new issue