diff options
Diffstat (limited to 'sway/commands/mode.c')
-rw-r--r-- | sway/commands/mode.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/sway/commands/mode.c b/sway/commands/mode.c index d2985c54..c30a8bac 100644 --- a/sway/commands/mode.c +++ b/sway/commands/mode.c @@ -15,43 +15,45 @@ struct cmd_results *cmd_mode(int argc, char **argv) { } const char *mode_name = argv[0]; - bool mode_make = (argc == 2 && strcmp(argv[1], "{") == 0); - if (mode_make) { - if (!config->reading) - return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file."); + bool new_mode = (argc == 2 && strcmp(argv[1], "{") == 0); + if (new_mode && !config->reading) { + return cmd_results_new(CMD_FAILURE, + "mode", "Can only be used in config file."); } struct sway_mode *mode = NULL; // Find mode - int i, len = config->modes->length; - for (i = 0; i < len; ++i) { - struct sway_mode *find = config->modes->items[i]; - if (strcasecmp(find->name, mode_name) == 0) { - mode = find; + for (int i = 0; i < config->modes->length; ++i) { + struct sway_mode *test = config->modes->items[i]; + if (strcasecmp(test->name, mode_name) == 0) { + mode = test; break; } } // Create mode if it doesn't exist - if (!mode && mode_make) { - mode = malloc(sizeof(struct sway_mode)); + if (!mode && new_mode) { + mode = calloc(1, sizeof(struct sway_mode)); if (!mode) { - return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode"); + return cmd_results_new(CMD_FAILURE, + "mode", "Unable to allocate mode"); } mode->name = strdup(mode_name); - mode->bindings = create_list(); + mode->keysym_bindings = create_list(); + mode->keycode_bindings = create_list(); list_add(config->modes, mode); } if (!mode) { - error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name); + error = cmd_results_new(CMD_INVALID, + "mode", "Unknown mode `%s'", mode_name); return error; } - if ((config->reading && mode_make) || (!config->reading && !mode_make)) { - sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); + if ((config->reading && new_mode) || (!config->reading && !new_mode)) { + wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name); } // Set current mode config->current_mode = mode; - if (!mode_make) { + if (!new_mode) { // trigger IPC mode event ipc_event_mode(config->current_mode->name); } - return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); + return cmd_results_new(new_mode ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); } |