summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/container.h2
-rw-r--r--sway/commands.c7
-rw-r--r--sway/container.c20
-rw-r--r--sway/layout.c30
4 files changed, 30 insertions, 29 deletions
diff --git a/include/container.h b/include/container.h
index cfb2e868..f902950a 100644
--- a/include/container.h
+++ b/include/container.h
@@ -107,6 +107,8 @@ bool swayc_is_active(swayc_t *view);
107bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); 107bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
108// Is `child` a child of `parent` 108// Is `child` a child of `parent`
109bool swayc_is_child_of(swayc_t *child, swayc_t *parent); 109bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
110// Return gap of specified container
111int swayc_gap(swayc_t *container);
110 112
111// Mapping functions 113// Mapping functions
112 114
diff --git a/sway/commands.c b/sway/commands.c
index 6e74a442..cf3d5b3f 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -519,8 +519,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
519 } 519 }
520 520
521 if (argc == 1) { 521 if (argc == 1) {
522 char *end; 522 int amount = (int)strtol(argv[0], NULL, 10);
523 int amount = (int)strtol(argv[0], &end, 10);
524 if (errno == ERANGE || amount == 0) { 523 if (errno == ERANGE || amount == 0) {
525 errno = 0; 524 errno = 0;
526 return false; 525 return false;
@@ -532,8 +531,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
532 config->gaps_outer = amount; 531 config->gaps_outer = amount;
533 } 532 }
534 } else if (argc == 2) { 533 } else if (argc == 2) {
535 char *end; 534 int amount = (int)strtol(argv[1], NULL, 10);
536 int amount = (int)strtol(argv[1], &end, 10);
537 if (errno == ERANGE || amount == 0) { 535 if (errno == ERANGE || amount == 0) {
538 errno = 0; 536 errno = 0;
539 return false; 537 return false;
@@ -548,6 +546,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
548 } else { 546 } else {
549 return false; 547 return false;
550 } 548 }
549 arrange_windows(&root_container, -1, -1);
551 return true; 550 return true;
552} 551}
553 552
diff --git a/sway/container.c b/sway/container.c
index 442266ec..c922a6e6 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -14,6 +14,7 @@
14static swayc_t *new_swayc(enum swayc_types type) { 14static swayc_t *new_swayc(enum swayc_types type) {
15 swayc_t *c = calloc(1, sizeof(swayc_t)); 15 swayc_t *c = calloc(1, sizeof(swayc_t));
16 c->handle = -1; 16 c->handle = -1;
17 c->gaps = -1;
17 c->layout = L_NONE; 18 c->layout = L_NONE;
18 c->type = type; 19 c->type = type;
19 if (type != C_VIEW) { 20 if (type != C_VIEW) {
@@ -96,7 +97,6 @@ swayc_t *new_output(wlc_handle handle) {
96 } 97 }
97 output->handle = handle; 98 output->handle = handle;
98 output->name = name ? strdup(name) : NULL; 99 output->name = name ? strdup(name) : NULL;
99 output->gaps = config->gaps_outer;
100 100
101 // Find position for it 101 // Find position for it
102 if (oc && oc->x != -1 && oc->y != -1) { 102 if (oc && oc->x != -1 && oc->y != -1) {
@@ -244,8 +244,6 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
244 view->desired_width = geometry->size.w; 244 view->desired_width = geometry->size.w;
245 view->desired_height = geometry->size.h; 245 view->desired_height = geometry->size.h;
246 246
247 view->gaps = config->gaps_inner;
248
249 view->is_floating = false; 247 view->is_floating = false;
250 248
251 if (sibling->type == C_WORKSPACE) { 249 if (sibling->type == C_WORKSPACE) {
@@ -556,6 +554,16 @@ bool swayc_is_child_of(swayc_t *child, swayc_t *parent) {
556 return swayc_is_parent_of(parent, child); 554 return swayc_is_parent_of(parent, child);
557} 555}
558 556
557int swayc_gap(swayc_t *container) {
558 if (container->type == C_VIEW) {
559 return container->gaps >= 0 ? container->gaps : config->gaps_inner;
560 } else if (container->type == C_WORKSPACE) {
561 return container->gaps >= 0 ? container->gaps : config->gaps_outer;
562 } else {
563 return 0;
564 }
565}
566
559// Mapping 567// Mapping
560 568
561void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 569void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
@@ -650,10 +658,10 @@ void reset_gaps(swayc_t *view, void *data) {
650 if (!ASSERT_NONNULL(view)) { 658 if (!ASSERT_NONNULL(view)) {
651 return; 659 return;
652 } 660 }
653 if (view->type == C_OUTPUT) { 661 if (view->type == C_WORKSPACE) {
654 view->gaps = config->gaps_outer; 662 view->gaps = -1;
655 } 663 }
656 if (view->type == C_VIEW) { 664 if (view->type == C_VIEW) {
657 view->gaps = config->gaps_inner; 665 view->gaps = -1;
658 } 666 }
659} 667}
diff --git a/sway/layout.c b/sway/layout.c
index daef332a..18202cf2 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -319,14 +319,15 @@ void update_geometry(swayc_t *container) {
319 if (container->type != C_VIEW) { 319 if (container->type != C_VIEW) {
320 return; 320 return;
321 } 321 }
322 int gap = swayc_gap(container);
322 struct wlc_geometry geometry = { 323 struct wlc_geometry geometry = {
323 .origin = { 324 .origin = {
324 .x = container->x + (container->is_floating ? 0 : container->gaps / 2), 325 .x = container->x + (container->is_floating ? 0 : gap / 2),
325 .y = container->y + (container->is_floating ? 0 : container->gaps / 2) 326 .y = container->y + (container->is_floating ? 0 : gap / 2)
326 }, 327 },
327 .size = { 328 .size = {
328 .w = container->width - (container->is_floating ? 0 : container->gaps), 329 .w = container->width - (container->is_floating ? 0 : gap),
329 .h = container->height - (container->is_floating ? 0 : container->gaps) 330 .h = container->height - (container->is_floating ? 0 : gap)
330 } 331 }
331 }; 332 };
332 if (swayc_is_fullscreen(container)) { 333 if (swayc_is_fullscreen(container)) {
@@ -364,10 +365,11 @@ void arrange_windows(swayc_t *container, double width, double height) {
364 x = 0, y = 0; 365 x = 0, y = 0;
365 for (i = 0; i < container->children->length; ++i) { 366 for (i = 0; i < container->children->length; ++i) {
366 swayc_t *child = container->children->items[i]; 367 swayc_t *child = container->children->items[i];
367 child->x = x + container->gaps; 368 int gap = swayc_gap(child);
368 child->y = y + container->gaps; 369 child->x = x + gap;
369 child->width = width - container->gaps * 2; 370 child->y = y + gap;
370 child->height = height - container->gaps * 2; 371 child->width = width - gap * 2;
372 child->height = height - gap * 2;
371 sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); 373 sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y);
372 arrange_windows(child, -1, -1); 374 arrange_windows(child, -1, -1);
373 } 375 }
@@ -582,17 +584,7 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
582 layout_match = container->layout == L_VERT; 584 layout_match = container->layout == L_VERT;
583 } 585 }
584 if (container->type == C_VIEW) { 586 if (container->type == C_VIEW) {
585 struct wlc_geometry geometry = { 587 update_geometry(container);
586 .origin = {
587 .x = container->x + container->gaps / 2,
588 .y = container->y + container->gaps / 2
589 },
590 .size = {
591 .w = container->width - container->gaps,
592 .h = container->height - container->gaps
593 }
594 };
595 wlc_view_set_geometry(container->handle, edge, &geometry);
596 return; 588 return;
597 } 589 }
598 if (layout_match) { 590 if (layout_match) {