diff --git a/include/config.h b/include/config.h index fe69e3100..a35cfd0a8 100644 --- a/include/config.h +++ b/include/config.h @@ -203,6 +203,8 @@ struct sway_config { list_t *config_chain; const char *current_config; + enum swayc_border_types border; + int border_thickness; enum edge_border_types hide_edge_borders; // border colors diff --git a/include/container.h b/include/container.h index 815898d7a..07514c8a5 100644 --- a/include/container.h +++ b/include/container.h @@ -8,7 +8,7 @@ typedef struct sway_container swayc_t; /** * Different kinds of containers. - * + * * This enum is in order. A container will never be inside of a container below * it on this list. */ @@ -37,9 +37,9 @@ enum swayc_layouts { }; enum swayc_border_types { - B_NONE, /**< No border */ - B_PIXEL, /**< 1px border */ - B_NORMAL /**< Normal border with title bar */ + B_NONE, /**< No border */ + B_PIXEL, /**< 1px border */ + B_NORMAL /**< Normal border with title bar */ }; /** diff --git a/sway/commands.c b/sway/commands.c index 4a3ebf9ec..bc182ceeb 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 []"); + } + + 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 "); + } + + 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 }, diff --git a/sway/config.c b/sway/config.c index 565acd057..193cfad26 100644 --- a/sway/config.c +++ b/sway/config.c @@ -182,6 +182,9 @@ static void config_defaults(struct sway_config *config) { config->config_chain = create_list(); config->current_config = NULL; + // borders + config->border = B_NORMAL; + config->border_thickness = 2; config->hide_edge_borders = E_NONE; // border colors diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 13d304bbb..2eb0276cb 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -43,6 +43,15 @@ The following commands may only be used in the configuration file. The following commands cannot be used directly in the configuration file. They are expected to be used with **bindsym** or at runtime through **swaymsg**(1). +**border** []:: + Set border style for windows. _normal_ includes a border of thickness _n_ and + a title bar. _pixel_ is just the border without title bar. Default is _normal_ + with border thickness 2. + +**border** :: + Set border style to _none_ or _toggle_ between the available border styles: + _normal_, _pixel_, _none_. + **exit**:: Exit sway and end your Wayland session.