diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c index 4a3ebf9e..bc182cee 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -43,6 +43,7 @@ static sway_cmd cmd_assign; static sway_cmd cmd_bar; static sway_cmd cmd_bindcode; static sway_cmd cmd_bindsym; +static sway_cmd cmd_border; static sway_cmd cmd_debuglog; static sway_cmd cmd_exec; static sway_cmd cmd_exec_always; @@ -346,6 +347,55 @@ static struct cmd_results *cmd_bindcode(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *cmd_border(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (argc > 2) { + return cmd_results_new(CMD_FAILURE, "border", + "Expected 'border <normal|pixel|none|toggle> [<n>]"); + } + + enum swayc_border_types border = config->border; + + if (strcasecmp(argv[0], "none") == 0) { + border = B_NONE; + } else if (strcasecmp(argv[0], "normal") == 0) { + border = B_NORMAL; + } else if (strcasecmp(argv[0], "pixel") == 0) { + border = B_PIXEL; + } else if (strcasecmp(argv[0], "toggle") == 0) { + switch (config->border) { + case B_NONE: + border = B_PIXEL; + break; + case B_NORMAL: + border = B_NONE; + break; + case B_PIXEL: + border = B_NORMAL; + break; + } + } else { + return cmd_results_new(CMD_FAILURE, "border", + "Expected 'border <normal|pixel|none|toggle>"); + } + + if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { + int thickness = (int)strtol(argv[1], NULL, 10); + if (errno == ERANGE || thickness < 0) { + errno = 0; + return cmd_results_new(CMD_INVALID, "border", "Number is out out of range."); + } + config->border_thickness = thickness; + } + + config->border = border; + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *cmd_exec_always(int argc, char **argv) { struct cmd_results *error = NULL; if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL); @@ -2074,6 +2124,7 @@ static struct cmd_handler handlers[] = { { "bar", cmd_bar }, { "bindcode", cmd_bindcode }, { "bindsym", cmd_bindsym }, + { "border", cmd_border }, { "debuglog", cmd_debuglog }, { "default_orientation", cmd_orientation }, { "exec", cmd_exec }, |