diff options
author | emersion <contact@emersion.fr> | 2018-05-01 15:31:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-01 15:31:02 +0100 |
commit | 0e51c7be449dd68025d5acd8c634f8dcacb10a16 (patch) | |
tree | c2c7e713a150c7f9a947b100e0fa4c56efb5c3b2 /sway/commands | |
parent | bf0603cd2d905554cc57d121b56b6708bb1d382b (diff) | |
parent | cb07434913b89580a4025824cb181733b2db1eb7 (diff) | |
download | sway-0e51c7be449dd68025d5acd8c634f8dcacb10a16.tar.xz |
Merge pull request #1874 from RyanDwyer/borders
Implement borders
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/border.c | 48 | ||||
-rw-r--r-- | sway/commands/client.c | 79 | ||||
-rw-r--r-- | sway/commands/default_border.c | 27 |
3 files changed, 154 insertions, 0 deletions
diff --git a/sway/commands/border.c b/sway/commands/border.c new file mode 100644 index 00000000..1eb06a21 --- /dev/null +++ b/sway/commands/border.c @@ -0,0 +1,48 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/input/cursor.h" +#include "sway/input/input-manager.h" +#include "sway/tree/container.h" +#include "sway/tree/view.h" + +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; + } + + struct sway_container *container = + config->handler_context.current_container; + if (container->type != C_VIEW) { + return cmd_results_new(CMD_INVALID, "border", + "Only views can have borders"); + } + struct sway_view *view = container->sway_view; + + if (strcmp(argv[0], "none") == 0) { + view->border = B_NONE; + } else if (strcmp(argv[0], "normal") == 0) { + view->border = B_NORMAL; + } else if (strcmp(argv[0], "pixel") == 0) { + view->border = B_PIXEL; + if (argc == 2) { + view->border_thickness = atoi(argv[1]); + } + } else if (strcmp(argv[0], "toggle") == 0) { + view->border = (view->border + 1) % 3; + } else { + return cmd_results_new(CMD_INVALID, "border", + "Expected 'border <none|normal|pixel|toggle>' " + "or 'border pixel <px>'"); + } + + view_autoconfigure(view); + + struct sway_seat *seat = input_manager_current_seat(input_manager); + if (seat->cursor) { + cursor_send_pointer_motion(seat->cursor, 0); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/client.c b/sway/commands/client.c new file mode 100644 index 00000000..156ff95c --- /dev/null +++ b/sway/commands/client.c @@ -0,0 +1,79 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/container.h" + +static bool parse_color(char *hexstring, float dest[static 4]) { + if (hexstring[0] != '#') { + return false; + } + + if (strlen(hexstring) != 7) { + return false; + } + + ++hexstring; + char *end; + uint32_t decimal = strtol(hexstring, &end, 16); + + if (*end != '\0') { + return false; + } + + dest[0] = ((decimal >> 16) & 0xff) / 255.0; + dest[1] = ((decimal >> 8) & 0xff) / 255.0; + dest[2] = (decimal & 0xff) / 255.0; + dest[3] = 1.0; + return true; +} + +static struct cmd_results *handle_command(int argc, char **argv, + struct border_colors *class, char *cmd_name) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 5))) { + return error; + } + + if (!parse_color(argv[0], class->border)) { + return cmd_results_new(CMD_INVALID, cmd_name, + "Unable to parse border color"); + } + + if (!parse_color(argv[1], class->background)) { + return cmd_results_new(CMD_INVALID, cmd_name, + "Unable to parse background color"); + } + + if (!parse_color(argv[2], class->text)) { + return cmd_results_new(CMD_INVALID, cmd_name, + "Unable to parse text color"); + } + + if (!parse_color(argv[3], class->indicator)) { + return cmd_results_new(CMD_INVALID, cmd_name, + "Unable to parse indicator color"); + } + + if (!parse_color(argv[4], class->child_border)) { + return cmd_results_new(CMD_INVALID, cmd_name, + "Unable to parse child border color"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + +struct cmd_results *cmd_client_focused(int argc, char **argv) { + return handle_command(argc, argv, &config->border_colors.focused, "client.focused"); +} + +struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) { + return handle_command(argc, argv, &config->border_colors.focused_inactive, "client.focused_inactive"); +} + +struct cmd_results *cmd_client_unfocused(int argc, char **argv) { + return handle_command(argc, argv, &config->border_colors.unfocused, "client.unfocused"); +} + +struct cmd_results *cmd_client_urgent(int argc, char **argv) { + return handle_command(argc, argv, &config->border_colors.urgent, "client.urgent"); +} diff --git a/sway/commands/default_border.c b/sway/commands/default_border.c new file mode 100644 index 00000000..fcd2c075 --- /dev/null +++ b/sway/commands/default_border.c @@ -0,0 +1,27 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/container.h" + +struct cmd_results *cmd_default_border(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "default_border", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (strcmp(argv[0], "none") == 0) { + config->border = B_NONE; + } else if (strcmp(argv[0], "normal") == 0) { + config->border = B_NORMAL; + } else if (strcmp(argv[0], "pixel") == 0) { + config->border = B_PIXEL; + if (argc == 2) { + config->border_thickness = atoi(argv[1]); + } + } else { + return cmd_results_new(CMD_INVALID, "default_border", + "Expected 'default_border <none|normal|pixel>' or 'default_border pixel <px>'"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} |