diff --git a/CMakeLists.txt b/CMakeLists.txt index 799348f..5fc362f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ target_include_directories(${APP_NAME} ) target_link_libraries(${APP_NAME} + PRIVATE m PRIVATE ${deps_LIBRARIES} ) diff --git a/src/default_config.h b/src/default_config.h index d16d1e5..0eba302 100644 --- a/src/default_config.h +++ b/src/default_config.h @@ -41,6 +41,7 @@ static const keyboard_t key_list[] = { }; static const layout_t layout_list[] = { + {.symbol = "[]=", .arrange = tile}, {.symbol = "[M]", .arrange = monocle}, {.symbol = "><=", .arrange = nullptr}, }; diff --git a/src/layout.c b/src/layout.c index 4bc85f6..1e09aed 100644 --- a/src/layout.c +++ b/src/layout.c @@ -1,5 +1,6 @@ #include "layout.h" +#include #include #include "base.h" @@ -25,3 +26,68 @@ void monocle(tag_t *tag) { } logger("== monocle tag: %s end ==\n", tag->name); } + +void tile(tag_t *tag) { + logger("== tile tag: %s start ==\n", tag->name); + uint16_t amount = 0; + for (task_in_tag_t *task = tag->task_list; task; task = task->next) { + if (client_need_layout(task->client)) ++amount; + } + if (amount == 0) goto end; + + uint16_t columns = (uint32_t)floor(sqrt(amount)); + if (columns * (columns + 1) <= amount) ++columns; + + uint32_t rows_in_other_cols = amount / columns; + uint32_t rows_in_main_col; + while ((rows_in_main_col = amount - (columns - 1) * rows_in_other_cols) > + rows_in_other_cols) { + ++rows_in_other_cols; + } + + area_t *workarea = &tag->task_list->client->monitor->workarea; + + uint16_t width_avg = workarea->width / columns; + uint16_t width_for_main_col = workarea->width - (columns - 1) * width_avg; + uint16_t width_for_other_cols = width_avg; + + uint16_t i = 0, row = 0, col = 0, row_count, width, height; + int16_t x = workarea->x, y = workarea->y; + for (task_in_tag_t *task = tag->task_list; task; task = task->next) { + if (!client_need_layout(task->client)) continue; + + if (i < rows_in_main_col) { + row = i; + width = width_for_main_col; + row_count = rows_in_main_col; + } else { + width = width_for_other_cols; + row_count = rows_in_other_cols; + if (((i - rows_in_main_col) % row_count) == 0) { + col++; + row = 0; + x += col == 1 ? width_for_main_col : width_for_other_cols; + y = workarea->y; + } + } + + uint16_t h_avg = workarea->height / row_count; + uint16_t h_main = workarea->height - h_avg * (row_count - 1); + height = row == 0 ? h_main : h_avg; + task->geometry.x = x; + task->geometry.y = y; + task->geometry.width = width - task->client->border_width * 2; + task->geometry.height = height - task->client->border_width * 2; + y += height; + + ++i; + + logger( + "== window 0x%x: x: %d, y: %d, width: %u, height: %u, border width: %u\n", + task->client->window, task->geometry.x, task->geometry.y, + task->geometry.width, task->geometry.height, task->client->border_width); + } + +end: + logger("== tile tag: %s end\n", tag->name); +} diff --git a/src/layout.h b/src/layout.h index bace03e..f2b7189 100644 --- a/src/layout.h +++ b/src/layout.h @@ -3,3 +3,4 @@ #include "types.h" void monocle(tag_t *tag); +void tile(tag_t *tag);