Skip to content

Commit

Permalink
gaps: apply gaps in monocle mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechou committed Apr 19, 2024
1 parent 2108e48 commit dfc5ad1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions inc/arrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/arrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion tst/tst-arrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#include "asserts.h"

#include <cmocka.h>
#include <stdbool.h>
#include <stddef.h>

#include "enum.h"
#include "layout.h"
#include "slist.h"
#include "tag.h"

#include "arrange.h"

Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit dfc5ad1

Please sign in to comment.