diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 76 |
1 files changed, 58 insertions, 18 deletions
diff --git a/sway/commands.c b/sway/commands.c index 053f40fc..f6c3b094 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -67,9 +67,11 @@ static sway_cmd cmd_ws_auto_back_and_forth; static sway_cmd bar_cmd_bindsym; static sway_cmd bar_cmd_mode; +static sway_cmd bar_cmd_modifier; static sway_cmd bar_cmd_hidden_state; static sway_cmd bar_cmd_id; static sway_cmd bar_cmd_position; +static sway_cmd bar_cmd_status_command; static sway_cmd bar_cmd_strip_workspace_numbers; static sway_cmd bar_cmd_tray_output; static sway_cmd bar_cmd_tray_padding; @@ -1126,22 +1128,8 @@ static struct cmd_results *cmd_bar(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); } - // Create new bar from default bar config - struct bar_config *bar = NULL; - bar = malloc(sizeof*bar); - bar->mode = strdup(config->bar.mode); - bar->hidden_state = strdup(config->bar.hidden_state); - bar->modifier = config->bar.modifier; - bar->position = config->bar.position; - bar->bindings = create_list(); - bar->status_command = strdup(config->bar.status_command); - bar->font = strdup(config->bar.font); - bar->bar_height = config->bar.bar_height; - bar->workspace_buttons = config->bar.workspace_buttons; - bar->strip_workspace_numbers = config->bar.strip_workspace_numbers; - bar->binding_mode_indicator = config->bar.binding_mode_indicator; - bar->tray_padding = config->bar.tray_padding; - list_add(config->bars, bar); + // Create new bar with default values + struct bar_config *bar = default_bar_config(); // set bar id int i; @@ -1658,6 +1646,41 @@ static struct cmd_results *bar_cmd_id(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *bar_cmd_modifier(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (!config->current_bar) { + return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined."); + } + + uint32_t mod = 0; + + list_t *split = split_string(argv[0], "+"); + for (int i = 0; i < split->length; ++i) { + int j; + bool is_mod = false; + for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { + if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { + mod |= modifiers[j].mod; + is_mod = true; + break; + } + } + if (!is_mod) { + free_flat_list(split); + return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); + } + } + free_flat_list(split); + + config->current_bar->modifier = mod; + sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *bar_cmd_position(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { @@ -1685,6 +1708,23 @@ static struct cmd_results *bar_cmd_position(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *bar_cmd_status_command(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (!config->current_bar) { + return cmd_results_new(CMD_FAILURE, "status_command", "No bar defined."); + } + + free(config->current_bar->status_command); + config->current_bar->status_command = join_args(argv, argc); + sway_log(L_DEBUG, "Feeding bar with status command: %s", config->current_bar->status_command); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { @@ -1769,11 +1809,11 @@ static struct cmd_handler bar_handlers[] = { { "hidden_state", bar_cmd_hidden_state }, { "id", bar_cmd_id }, { "mode", bar_cmd_mode }, - { "modifier", NULL }, + { "modifier", bar_cmd_modifier }, { "output", NULL }, { "position", bar_cmd_position }, { "seperator_symbol", NULL }, - { "status_command", NULL }, + { "status_command", bar_cmd_status_command }, { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, { "tray_output", bar_cmd_tray_output }, { "tray_padding", bar_cmd_tray_padding }, |