aboutsummaryrefslogtreecommitdiff
path: root/sway/old/commands/border.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/old/commands/border.c')
-rw-r--r--sway/old/commands/border.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/old/commands/border.c b/sway/old/commands/border.c
new file mode 100644
index 00000000..c888622e
--- /dev/null
+++ b/sway/old/commands/border.c
@@ -0,0 +1,65 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/container.h"
+#include "sway/focus.h"
+
+struct cmd_results *cmd_border(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if (!config->active) {
+ return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running.");
+ }
+ if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ if (argc > 2) {
+ return cmd_results_new(CMD_INVALID, "border",
+ "Expected 'border <normal|pixel|none|toggle> [<n>]");
+ }
+
+ swayc_t *view = current_container;
+ enum swayc_border_types border = view->border_type;
+ int thickness = view->border_thickness;
+
+ 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 (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_INVALID, "border",
+ "Expected 'border <normal|pixel|none|toggle>");
+ }
+
+ if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
+ thickness = (int)strtol(argv[1], NULL, 10);
+ if (errno == ERANGE || thickness < 0) {
+ errno = 0;
+ return cmd_results_new(CMD_INVALID, "border", "Number is out of range.");
+ }
+ }
+
+ if (view) {
+ view->border_type = border;
+ view->border_thickness = thickness;
+ update_geometry(view);
+ }
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}