tile 布局
This commit is contained in:
@@ -76,6 +76,7 @@ target_include_directories(${APP_NAME}
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${APP_NAME}
|
target_link_libraries(${APP_NAME}
|
||||||
|
PRIVATE m
|
||||||
PRIVATE ${deps_LIBRARIES}
|
PRIVATE ${deps_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ static const keyboard_t key_list[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const layout_t layout_list[] = {
|
static const layout_t layout_list[] = {
|
||||||
|
{.symbol = "[]=", .arrange = tile},
|
||||||
{.symbol = "[M]", .arrange = monocle},
|
{.symbol = "[M]", .arrange = monocle},
|
||||||
{.symbol = "><=", .arrange = nullptr},
|
{.symbol = "><=", .arrange = nullptr},
|
||||||
};
|
};
|
||||||
|
|||||||
66
src/layout.c
66
src/layout.c
@@ -1,5 +1,6 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
@@ -25,3 +26,68 @@ void monocle(tag_t *tag) {
|
|||||||
}
|
}
|
||||||
logger("== monocle tag: %s end ==\n", tag->name);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void monocle(tag_t *tag);
|
void monocle(tag_t *tag);
|
||||||
|
void tile(tag_t *tag);
|
||||||
|
|||||||
Reference in New Issue
Block a user