mode supports multi token names

master
taiyu 9 years ago
parent 799ff640f8
commit 6388241abb

@ -13,7 +13,6 @@ struct cmd_handler {
} config_type; } config_type;
}; };
struct cmd_handler *find_handler(char *line);
bool handle_command(char *command); bool handle_command(char *command);
// Handles commands during config // Handles commands during config
bool config_command(char *command); bool config_command(char *command);

@ -368,26 +368,27 @@ static bool cmd_mode(int argc, char **argv) {
if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) {
return false; 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; struct sway_mode *mode = NULL;
// Find mode // Find mode
int i, len = config->modes->length; int i, len = config->modes->length;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
struct sway_mode *find = config->modes->items[i]; struct sway_mode *find = config->modes->items[i];
if (strcasecmp(find->name, mode_name)==0) { if (strcasecmp(find->name, mode_name) == 0) {
mode = find; mode = find;
break; break;
} }
} }
// Create mode if it doesnt exist // Create mode if it doesnt exist
if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) { if (!mode && mode_make) {
mode = malloc(sizeof*mode); mode = malloc(sizeof*mode);
mode->name = strdup(mode_name); mode->name = strdup(mode_name);
mode->bindings = create_list(); mode->bindings = create_list();
list_add(config->modes, mode); list_add(config->modes, mode);
} }
if (!mode) { if (!mode) {
sway_log(L_ERROR, "Invalide mode `%s'", mode_name); sway_log(L_ERROR, "Unknown mode `%s'", mode_name);
return false; return false;
} }
sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); 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) { char **split_args(const char *start, int *argc) {
*argc = 0; *argc = 0;
int alloc = 2; int alloc = 2;
char **parts = malloc(sizeof(char *) * alloc); char **argv = malloc(sizeof(char *) * alloc);
bool in_token = false; bool in_token = false;
bool in_string = false; bool in_string = false;
bool in_char = false; bool in_char = false;
@ -132,15 +132,16 @@ char **split_args(const char *start, int *argc) {
token[end - start] = '\0'; token[end - start] = '\0';
strip_quotes(token); strip_quotes(token);
unescape_string(token); unescape_string(token);
parts[*argc] = token; argv[*argc] = token;
if (++*argc == alloc) { if (++*argc + 1 == alloc) {
parts = realloc(parts, (alloc *= 2) * sizeof(char *)); argv = realloc(argv, (alloc *= 2) * sizeof(char *));
} }
} }
in_token = false; in_token = false;
escaped = false; escaped = false;
} }
return parts; argv[*argc] = NULL;
return argv;
} }
void free_argv(int argc, char **argv) { void free_argv(int argc, char **argv) {

Loading…
Cancel
Save