diff options
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/container.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 40 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/container.c | 10 | ||||
-rw-r--r-- | sway/layout.c | 16 |
6 files changed, 63 insertions, 10 deletions
diff --git a/include/config.h b/include/config.h index 9243bf35..c47eb683 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -41,6 +41,9 @@ struct sway_config { | |||
41 | bool active; | 41 | bool active; |
42 | bool failed; | 42 | bool failed; |
43 | bool reloading; | 43 | bool reloading; |
44 | |||
45 | int gaps_inner; | ||
46 | int gaps_outer; | ||
44 | }; | 47 | }; |
45 | 48 | ||
46 | bool load_config(void); | 49 | bool load_config(void); |
diff --git a/include/container.h b/include/container.h index 186ee8b6..6d64b490 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -48,6 +48,8 @@ struct sway_container { | |||
48 | 48 | ||
49 | char *name; | 49 | char *name; |
50 | 50 | ||
51 | int gaps; | ||
52 | |||
51 | list_t *children; | 53 | list_t *children; |
52 | list_t *floating; | 54 | list_t *floating; |
53 | 55 | ||
diff --git a/sway/commands.c b/sway/commands.c index 51de7a50..f716efa3 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <errno.h> | ||
6 | #include <string.h> | 7 | #include <string.h> |
7 | #include <unistd.h> | 8 | #include <unistd.h> |
8 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -281,6 +282,44 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * | |||
281 | return true; | 282 | return true; |
282 | } | 283 | } |
283 | 284 | ||
285 | static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | ||
286 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { | ||
287 | return false; | ||
288 | } | ||
289 | |||
290 | if (argc == 1) { | ||
291 | char *end; | ||
292 | int amount = (int)strtol(argv[0], &end, 10); | ||
293 | if (errno == ERANGE || amount == 0) { | ||
294 | errno = 0; | ||
295 | return false; | ||
296 | } | ||
297 | if (config->gaps_inner == 0) { | ||
298 | config->gaps_inner = amount; | ||
299 | } | ||
300 | if (config->gaps_outer == 0) { | ||
301 | config->gaps_outer = amount; | ||
302 | } | ||
303 | } else if (argc == 2) { | ||
304 | char *end; | ||
305 | int amount = (int)strtol(argv[1], &end, 10); | ||
306 | if (errno == ERANGE || amount == 0) { | ||
307 | errno = 0; | ||
308 | return false; | ||
309 | } | ||
310 | if (strcmp(argv[0], "inner") == 0) { | ||
311 | config->gaps_inner = amount; | ||
312 | } else if (strcmp(argv[0], "outer") == 0) { | ||
313 | config->gaps_outer = amount; | ||
314 | } else { | ||
315 | return false; | ||
316 | } | ||
317 | } else { | ||
318 | return false; | ||
319 | } | ||
320 | return true; | ||
321 | } | ||
322 | |||
284 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { | 323 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { |
285 | swayc_t *view = get_focused_container(&root_container); | 324 | swayc_t *view = get_focused_container(&root_container); |
286 | wlc_view_close(view->handle); | 325 | wlc_view_close(view->handle); |
@@ -484,6 +523,7 @@ static struct cmd_handler handlers[] = { | |||
484 | { "focus", cmd_focus }, | 523 | { "focus", cmd_focus }, |
485 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 524 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
486 | { "fullscreen", cmd_fullscreen }, | 525 | { "fullscreen", cmd_fullscreen }, |
526 | { "gaps", cmd_gaps }, | ||
487 | { "kill", cmd_kill }, | 527 | { "kill", cmd_kill }, |
488 | { "layout", cmd_layout }, | 528 | { "layout", cmd_layout }, |
489 | { "log_colors", cmd_log_colors }, | 529 | { "log_colors", cmd_log_colors }, |
diff --git a/sway/config.c b/sway/config.c index 6d39839d..b0b66315 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -170,6 +170,8 @@ void config_defaults(struct sway_config *config) { | |||
170 | config->reloading = false; | 170 | config->reloading = false; |
171 | config->active = false; | 171 | config->active = false; |
172 | config->failed = false; | 172 | config->failed = false; |
173 | config->gaps_inner = 0; | ||
174 | config->gaps_outer = 0; | ||
173 | } | 175 | } |
174 | 176 | ||
175 | bool read_config(FILE *file, bool is_active) { | 177 | bool read_config(FILE *file, bool is_active) { |
diff --git a/sway/container.c b/sway/container.c index e679e823..68511156 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -43,8 +43,10 @@ swayc_t *new_output(wlc_handle handle) { | |||
43 | sway_log(L_DEBUG, "Added output %lu:%s", handle, name); | 43 | sway_log(L_DEBUG, "Added output %lu:%s", handle, name); |
44 | 44 | ||
45 | swayc_t *output = new_swayc(C_OUTPUT); | 45 | swayc_t *output = new_swayc(C_OUTPUT); |
46 | output->width = size->w; | 46 | output->x = (config->gaps_outer + config->gaps_inner) / 2; |
47 | output->height = size->h; | 47 | output->y = (config->gaps_outer + config->gaps_inner) / 2; |
48 | output->width = size->w - (config->gaps_outer + config->gaps_inner); | ||
49 | output->height = size->h - (config->gaps_outer + config->gaps_inner); | ||
48 | output->handle = handle; | 50 | output->handle = handle; |
49 | output->name = name ? strdup(name) : NULL; | 51 | output->name = name ? strdup(name) : NULL; |
50 | 52 | ||
@@ -81,6 +83,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
81 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 83 | swayc_t *workspace = new_swayc(C_WORKSPACE); |
82 | 84 | ||
83 | workspace->layout = L_HORIZ; // TODO: default layout | 85 | workspace->layout = L_HORIZ; // TODO: default layout |
86 | workspace->x = output->x; | ||
87 | workspace->y = output->y; | ||
84 | workspace->width = output->width; | 88 | workspace->width = output->width; |
85 | workspace->height = output->height; | 89 | workspace->height = output->height; |
86 | workspace->name = strdup(name); | 90 | workspace->name = strdup(name); |
@@ -143,6 +147,8 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
143 | view->visible = true; | 147 | view->visible = true; |
144 | view->is_focused = true; | 148 | view->is_focused = true; |
145 | 149 | ||
150 | view->gaps = config->gaps_inner; | ||
151 | |||
146 | view->desired_width = -1; | 152 | view->desired_width = -1; |
147 | view->desired_height = -1; | 153 | view->desired_height = -1; |
148 | 154 | ||
diff --git a/sway/layout.c b/sway/layout.c index e2ea46a7..737477f7 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -133,12 +133,12 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
133 | { | 133 | { |
134 | struct wlc_geometry geometry = { | 134 | struct wlc_geometry geometry = { |
135 | .origin = { | 135 | .origin = { |
136 | .x = container->x, | 136 | .x = container->x + container->gaps / 2, |
137 | .y = container->y | 137 | .y = container->y + container->gaps / 2 |
138 | }, | 138 | }, |
139 | .size = { | 139 | .size = { |
140 | .w = width, | 140 | .w = width - container->gaps, |
141 | .h = height | 141 | .h = height - container->gaps |
142 | } | 142 | } |
143 | }; | 143 | }; |
144 | if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { | 144 | if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { |
@@ -146,10 +146,10 @@ void arrange_windows(swayc_t *container, int width, int height) { | |||
146 | while (parent->type != C_OUTPUT) { | 146 | while (parent->type != C_OUTPUT) { |
147 | parent = parent->parent; | 147 | parent = parent->parent; |
148 | } | 148 | } |
149 | geometry.origin.x = 0; | 149 | geometry.origin.x = container->gaps / 2; |
150 | geometry.origin.y = 0; | 150 | geometry.origin.y = container->gaps / 2; |
151 | geometry.size.w = parent->width; | 151 | geometry.size.w = parent->width - container->gaps; |
152 | geometry.size.h = parent->height; | 152 | geometry.size.h = parent->height - container->gaps; |
153 | wlc_view_set_geometry(container->handle, &geometry); | 153 | wlc_view_set_geometry(container->handle, &geometry); |
154 | wlc_view_bring_to_front(container->handle); | 154 | wlc_view_bring_to_front(container->handle); |
155 | } else { | 155 | } else { |