diff --git a/inc/arrange.h b/inc/arrange.h index 53c92ea..8bcc9a5 100644 --- a/inc/arrange.h +++ b/inc/arrange.h @@ -49,6 +49,7 @@ void arrange_wide(const struct Demand *demand, // append many new Box to views with full usable area void arrange_monocle(const struct Demand *demand, + const struct Tag* const tag, struct SList **views); // recursively append new Box to views as per stack diff --git a/src/arrange.c b/src/arrange.c index e0ef598..a7b8d00 100644 --- a/src/arrange.c +++ b/src/arrange.c @@ -286,12 +286,18 @@ void arrange_wide(const struct Demand *demand, } void arrange_monocle(const struct Demand *demand, + const struct Tag* const tag, struct SList **views) { if (!demand || !views) return; - struct Box usable = { 0, 0, demand->usable_width, demand->usable_height }; + uint32_t outer_gap = tag->smart_gaps ? 0 : tag->outer_gaps; + struct Box usable = { + .x = outer_gap, .y = outer_gap, + .width = demand->usable_width - 2 * outer_gap, + .height = demand->usable_height - 2 * outer_gap, + }; for (uint32_t i = 0; i < demand->view_count; i++) { struct Box *this = calloc(1, sizeof(struct Box)); diff --git a/src/layout.c b/src/layout.c index 98f4bec..67c5741 100644 --- a/src/layout.c +++ b/src/layout.c @@ -149,7 +149,7 @@ struct SList *layout(const struct Demand *demand, const struct Tag *tag) { arrange_views(demand, tag->stack, E, N, num_after, num_after, tag->inner_gaps, box_after, box_after, &views); break; case MONOCLE: - arrange_monocle(demand, &views); + arrange_monocle(demand, tag, &views); break; case WIDE: // left stack dwindle left up diff --git a/tst/tst-arrange.c b/tst/tst-arrange.c index 2f061ce..d02b0d4 100644 --- a/tst/tst-arrange.c +++ b/tst/tst-arrange.c @@ -2,10 +2,13 @@ #include "asserts.h" #include +#include #include +#include "enum.h" #include "layout.h" #include "slist.h" +#include "tag.h" #include "arrange.h" @@ -28,8 +31,9 @@ int after_each(void **state) { void arrange_monocle__many(void **state) { struct SList *stack = NULL; struct Demand demand = { .view_count = 2, .usable_width = 5, .usable_height = 3 }; + struct Tag tag = { .layout_cur = MONOCLE, }; - arrange_monocle(&demand, &stack); + arrange_monocle(&demand, &tag, &stack); assert_int_equal(slist_length(stack), 2); @@ -39,9 +43,31 @@ void arrange_monocle__many(void **state) { slist_free_vals(&stack, NULL); } +void arrange_monocle__many_with_gaps(void **state) { + struct SList *stack = NULL; + struct Demand demand = { .view_count = 2, .usable_width = 5, .usable_height = 3 }; + struct Tag tag = { .layout_cur = MONOCLE, .smart_gaps = false, + .inner_gaps = 0, .outer_gaps = 1, }; + struct Tag smart_tag = { .layout_cur = MONOCLE, .smart_gaps = true, + .inner_gaps = 0, .outer_gaps = 1, }; + + arrange_monocle(&demand, &tag, &stack); + assert_int_equal(slist_length(stack), 2); + assert_box_equal(slist_at(stack, 1), 1, 1, 3, 1); + assert_box_equal(slist_at(stack, 0), 1, 1, 3, 1); + slist_free_vals(&stack, NULL); + + arrange_monocle(&demand, &smart_tag, &stack); + assert_int_equal(slist_length(stack), 2); + assert_box_equal(slist_at(stack, 0), 0, 0, 5, 3); + assert_box_equal(slist_at(stack, 1), 0, 0, 5, 3); + slist_free_vals(&stack, NULL); +} + int main(void) { const struct CMUnitTest tests[] = { TEST(arrange_monocle__many), + TEST(arrange_monocle__many_with_gaps), }; return RUN(tests);