aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/gaps.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
commit733993a651c71f7e2198d505960d6bbd31e0e107 (patch)
treee51732c5872b624e73355f9e5b3f762101f3cd0d /sway/commands/gaps.c
parentInitial (awful) pass on xdg shell support (diff)
downloadsway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz
sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst
sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip
Move everything to sway/old/
Diffstat (limited to 'sway/commands/gaps.c')
-rw-r--r--sway/commands/gaps.c166
1 files changed, 0 insertions, 166 deletions
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
deleted file mode 100644
index 0a48592d..00000000
--- a/sway/commands/gaps.c
+++ /dev/null
@@ -1,166 +0,0 @@
1#include <ctype.h>
2#include <errno.h>
3#include <stdlib.h>
4#include <string.h>
5#include <strings.h>
6#include "sway/commands.h"
7#include "sway/container.h"
8#include "sway/focus.h"
9#include "sway/layout.h"
10
11struct cmd_results *cmd_gaps(int argc, char **argv) {
12 struct cmd_results *error = NULL;
13 if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) {
14 return error;
15 }
16 const char *expected_syntax =
17 "Expected 'gaps edge_gaps <on|off|toggle>' or "
18 "'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'";
19 const char *amount_str = argv[0];
20 // gaps amount
21 if (argc >= 1 && isdigit(*amount_str)) {
22 int amount = (int)strtol(amount_str, NULL, 10);
23 if (errno == ERANGE) {
24 errno = 0;
25 return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range.");
26 }
27 config->gaps_inner = config->gaps_outer = amount;
28 arrange_windows(&root_container, -1, -1);
29 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
30 }
31 // gaps inner|outer n
32 else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) {
33 int amount = (int)strtol(amount_str, NULL, 10);
34 if (errno == ERANGE) {
35 errno = 0;
36 return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range.");
37 }
38 const char *target_str = argv[0];
39 if (strcasecmp(target_str, "inner") == 0) {
40 config->gaps_inner = amount;
41 } else if (strcasecmp(target_str, "outer") == 0) {
42 config->gaps_outer = amount;
43 }
44 arrange_windows(&root_container, -1, -1);
45 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
46 } else if (argc == 2 && strcasecmp(argv[0], "edge_gaps") == 0) {
47 // gaps edge_gaps <on|off|toggle>
48 if (strcasecmp(argv[1], "toggle") == 0) {
49 if (config->reading) {
50 return cmd_results_new(CMD_FAILURE, "gaps edge_gaps toggle",
51 "Can't be used in config file.");
52 }
53 config->edge_gaps = !config->edge_gaps;
54 } else {
55 config->edge_gaps =
56 (strcasecmp(argv[1], "yes") == 0 || strcasecmp(argv[1], "on") == 0);
57 }
58 arrange_windows(&root_container, -1, -1);
59 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
60 }
61 // gaps inner|outer current|all set|plus|minus n
62 if (argc < 4 || config->reading) {
63 return cmd_results_new(CMD_INVALID, "gaps", expected_syntax);
64 }
65 // gaps inner|outer ...
66 const char *inout_str = argv[0];
67 enum {INNER, OUTER} inout;
68 if (strcasecmp(inout_str, "inner") == 0) {
69 inout = INNER;
70 } else if (strcasecmp(inout_str, "outer") == 0) {
71 inout = OUTER;
72 } else {
73 return cmd_results_new(CMD_INVALID, "gaps", expected_syntax);
74 }
75
76 // gaps ... current|all ...
77 const char *target_str = argv[1];
78 enum {CURRENT, WORKSPACE, ALL} target;
79 if (strcasecmp(target_str, "current") == 0) {
80 target = CURRENT;
81 } else if (strcasecmp(target_str, "all") == 0) {
82 target = ALL;
83 } else if (strcasecmp(target_str, "workspace") == 0) {
84 if (inout == OUTER) {
85 target = CURRENT;
86 } else {
87 // Set gap for views in workspace
88 target = WORKSPACE;
89 }
90 } else {
91 return cmd_results_new(CMD_INVALID, "gaps", expected_syntax);
92 }
93
94 // gaps ... n
95 amount_str = argv[3];
96 int amount = (int)strtol(amount_str, NULL, 10);
97 if (errno == ERANGE) {
98 errno = 0;
99 return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range.");
100 }
101
102 // gaps ... set|plus|minus ...
103 const char *method_str = argv[2];
104 enum {SET, ADD} method;
105 if (strcasecmp(method_str, "set") == 0) {
106 method = SET;
107 } else if (strcasecmp(method_str, "plus") == 0) {
108 method = ADD;
109 } else if (strcasecmp(method_str, "minus") == 0) {
110 method = ADD;
111 amount *= -1;
112 } else {
113 return cmd_results_new(CMD_INVALID, "gaps", expected_syntax);
114 }
115
116 if (target == CURRENT) {
117 swayc_t *cont;
118 if (inout == OUTER) {
119 if ((cont = swayc_active_workspace()) == NULL) {
120 return cmd_results_new(CMD_FAILURE, "gaps", "There's no active workspace.");
121 }
122 } else {
123 if ((cont = get_focused_view(&root_container))->type != C_VIEW) {
124 return cmd_results_new(CMD_FAILURE, "gaps", "Currently focused item is not a view.");
125 }
126 }
127 cont->gaps = swayc_gap(cont);
128 if (method == SET) {
129 cont->gaps = amount;
130 } else if ((cont->gaps += amount) < 0) {
131 cont->gaps = 0;
132 }
133 arrange_windows(cont->parent, -1, -1);
134 } else if (inout == OUTER) {
135 //resize all workspace.
136 int i,j;
137 for (i = 0; i < root_container.children->length; ++i) {
138 swayc_t *op = root_container.children->items[i];
139 for (j = 0; j < op->children->length; ++j) {
140 swayc_t *ws = op->children->items[j];
141 if (method == SET) {
142 ws->gaps = amount;
143 } else if ((ws->gaps += amount) < 0) {
144 ws->gaps = 0;
145 }
146 }
147 }
148 arrange_windows(&root_container, -1, -1);
149 } else {
150 // Resize gaps for all views in workspace
151 swayc_t *top;
152 if (target == WORKSPACE) {
153 if ((top = swayc_active_workspace()) == NULL) {
154 return cmd_results_new(CMD_FAILURE, "gaps", "There's currently no active workspace.");
155 }
156 } else {
157 top = &root_container;
158 }
159 int top_gap = top->gaps;
160 container_map(top, method == SET ? set_gaps : add_gaps, &amount);
161 top->gaps = top_gap;
162 arrange_windows(top, -1, -1);
163 }
164
165 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
166}