mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-06-17 14:33:18 -04:00
opt: optimzie fair layout caculate
This commit is contained in:
parent
3a01e84c04
commit
655eae79a8
2 changed files with 219 additions and 113 deletions
|
|
@ -367,10 +367,9 @@ void vertical_fair(Monitor *m) {
|
|||
int32_t cur_gappov = enablegaps ? m->gappov : 0;
|
||||
int32_t cur_gappoh = enablegaps ? m->gappoh : 0;
|
||||
|
||||
cur_gappiv = config.smartgaps && n == 1 ? 0 : cur_gappiv;
|
||||
cur_gappih = config.smartgaps && n == 1 ? 0 : cur_gappih;
|
||||
cur_gappov = config.smartgaps && n == 1 ? 0 : cur_gappov;
|
||||
cur_gappoh = config.smartgaps && n == 1 ? 0 : cur_gappoh;
|
||||
if (config.smartgaps && n == 1) {
|
||||
cur_gappiv = cur_gappih = cur_gappov = cur_gappoh = 0;
|
||||
}
|
||||
|
||||
int32_t rows;
|
||||
for (rows = 0; rows <= n; rows++) {
|
||||
|
|
@ -384,56 +383,124 @@ void vertical_fair(Monitor *m) {
|
|||
int32_t first_group_count = first_group_rows * base_cols;
|
||||
int32_t max_cols = base_cols + (remainder > 0 ? 1 : 0);
|
||||
|
||||
Client *arr[n];
|
||||
int32_t arr_idx = 0;
|
||||
wl_list_for_each(c, &clients, link) {
|
||||
if (VISIBLEON(c, m) && ISTILED(c)) {
|
||||
arr[arr_idx++] = c;
|
||||
if (arr_idx >= n)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float row_pers[rows];
|
||||
float col_pers[max_cols];
|
||||
for (i = 0; i < rows; i++)
|
||||
row_pers[i] = 1.0f;
|
||||
row_pers[i] = 0.0f;
|
||||
for (i = 0; i < max_cols; i++)
|
||||
col_pers[i] = 1.0f;
|
||||
col_pers[i] = 0.0f;
|
||||
|
||||
i = 0;
|
||||
wl_list_for_each(c, &clients, link) {
|
||||
if (!VISIBLEON(c, m) || !ISTILED(c))
|
||||
continue;
|
||||
int32_t row_idx, col_idx;
|
||||
if (i < first_group_count) {
|
||||
row_idx = i / base_cols;
|
||||
col_idx = i % base_cols;
|
||||
} else {
|
||||
int32_t offset = i - first_group_count;
|
||||
row_idx = first_group_rows + (offset / (base_cols + 1));
|
||||
col_idx = offset % (base_cols + 1);
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
c = arr[i];
|
||||
int32_t row_idx =
|
||||
(i < first_group_count)
|
||||
? (i / base_cols)
|
||||
: (first_group_rows + (i - first_group_count) / max_cols);
|
||||
int32_t col_idx = (i < first_group_count)
|
||||
? (i % base_cols)
|
||||
: ((i - first_group_count) % max_cols);
|
||||
|
||||
if (col_idx == 0)
|
||||
row_pers[row_idx] =
|
||||
(c->grid_row_per > 0.0f) ? c->grid_row_per : 1.0f;
|
||||
if (row_idx == 0)
|
||||
col_pers[col_idx] =
|
||||
(c->grid_col_per > 0.0f) ? c->grid_col_per : 1.0f;
|
||||
i++;
|
||||
if (c->grid_row_idx == row_idx && c->grid_row_per > 0.0f)
|
||||
row_pers[row_idx] = c->grid_row_per;
|
||||
if (c->grid_col_idx == col_idx && c->grid_col_per > 0.0f)
|
||||
col_pers[col_idx] = c->grid_col_per;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
c = arr[i];
|
||||
int32_t row_idx =
|
||||
(i < first_group_count)
|
||||
? (i / base_cols)
|
||||
: (first_group_rows + (i - first_group_count) / max_cols);
|
||||
int32_t col_idx = (i < first_group_count)
|
||||
? (i % base_cols)
|
||||
: ((i - first_group_count) % max_cols);
|
||||
|
||||
if (row_pers[row_idx] == 0.0f && c->grid_row_per > 0.0f)
|
||||
row_pers[row_idx] = c->grid_row_per;
|
||||
if (col_pers[col_idx] == 0.0f && c->grid_col_per > 0.0f)
|
||||
col_pers[col_idx] = c->grid_col_per;
|
||||
}
|
||||
|
||||
float sum_row = 0.0f;
|
||||
for (i = 0; i < rows; i++)
|
||||
for (i = 0; i < rows; i++) {
|
||||
if (row_pers[i] == 0.0f)
|
||||
row_pers[i] = 1.0f;
|
||||
sum_row += row_pers[i];
|
||||
}
|
||||
for (i = 0; i < max_cols; i++) {
|
||||
if (col_pers[i] == 0.0f)
|
||||
col_pers[i] = 1.0f;
|
||||
}
|
||||
|
||||
float row_y[rows], row_h[rows];
|
||||
float avail_h = m->w.height - 2 * cur_gappov - (rows - 1) * cur_gappiv;
|
||||
float next_y = m->w.y + cur_gappov;
|
||||
for (i = 0; i < rows; i++) {
|
||||
row_y[i] = next_y;
|
||||
row_h[i] = (i == rows - 1)
|
||||
? (m->w.y + m->w.height - cur_gappov - next_y)
|
||||
: (avail_h * (row_pers[i] / sum_row));
|
||||
next_y += row_h[i] + cur_gappiv;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
wl_list_for_each(c, &clients, link) {
|
||||
if (!VISIBLEON(c, m) || !ISTILED(c))
|
||||
continue;
|
||||
float col_x_base[base_cols], col_w_base[base_cols];
|
||||
float sum_col_base = 0.0f;
|
||||
for (i = 0; i < base_cols; i++)
|
||||
sum_col_base += col_pers[i];
|
||||
float avail_w_base =
|
||||
m->w.width - 2 * cur_gappoh - (base_cols - 1) * cur_gappih;
|
||||
float next_x = m->w.x + cur_gappoh;
|
||||
for (i = 0; i < base_cols; i++) {
|
||||
col_x_base[i] = next_x;
|
||||
col_w_base[i] = (i == base_cols - 1)
|
||||
? (m->w.x + m->w.width - cur_gappoh - next_x)
|
||||
: (avail_w_base * (col_pers[i] / sum_col_base));
|
||||
next_x += col_w_base[i] + cur_gappih;
|
||||
}
|
||||
|
||||
float col_x_max[max_cols], col_w_max[max_cols];
|
||||
if (remainder > 0) {
|
||||
float sum_col_max = 0.0f;
|
||||
for (i = 0; i < max_cols; i++)
|
||||
sum_col_max += col_pers[i];
|
||||
float avail_w_max =
|
||||
m->w.width - 2 * cur_gappoh - (max_cols - 1) * cur_gappih;
|
||||
next_x = m->w.x + cur_gappoh;
|
||||
for (i = 0; i < max_cols; i++) {
|
||||
col_x_max[i] = next_x;
|
||||
col_w_max[i] = (i == max_cols - 1)
|
||||
? (m->w.x + m->w.width - cur_gappoh - next_x)
|
||||
: (avail_w_max * (col_pers[i] / sum_col_max));
|
||||
next_x += col_w_max[i] + cur_gappih;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
c = arr[i];
|
||||
int32_t row_idx, col_idx;
|
||||
float fl_cx, fl_cy, fl_cw, fl_ch;
|
||||
|
||||
int32_t row_idx, col_idx, cols_in_this_row;
|
||||
if (i < first_group_count) {
|
||||
row_idx = i / base_cols;
|
||||
col_idx = i % base_cols;
|
||||
cols_in_this_row = base_cols;
|
||||
fl_cx = col_x_base[col_idx];
|
||||
fl_cw = col_w_base[col_idx];
|
||||
} else {
|
||||
int32_t offset = i - first_group_count;
|
||||
row_idx = first_group_rows + (offset / (base_cols + 1));
|
||||
col_idx = offset % (base_cols + 1);
|
||||
cols_in_this_row = base_cols + 1;
|
||||
row_idx = first_group_rows + (offset / max_cols);
|
||||
col_idx = offset % max_cols;
|
||||
fl_cx = col_x_max[col_idx];
|
||||
fl_cw = col_w_max[col_idx];
|
||||
}
|
||||
|
||||
c->grid_row_per = row_pers[row_idx];
|
||||
|
|
@ -441,25 +508,8 @@ void vertical_fair(Monitor *m) {
|
|||
c->grid_row_idx = row_idx;
|
||||
c->grid_col_idx = col_idx;
|
||||
|
||||
float fl_cy = m->w.y + cur_gappov;
|
||||
for (int j = 0; j < row_idx; j++)
|
||||
fl_cy += avail_h * (row_pers[j] / sum_row) + cur_gappiv;
|
||||
float fl_ch = (row_idx == rows - 1)
|
||||
? (m->w.y + m->w.height - cur_gappov - fl_cy)
|
||||
: avail_h * (row_pers[row_idx] / sum_row);
|
||||
|
||||
float sum_col_this_row = 0.0f;
|
||||
for (int j = 0; j < cols_in_this_row; j++)
|
||||
sum_col_this_row += col_pers[j];
|
||||
|
||||
float avail_w =
|
||||
m->w.width - 2 * cur_gappoh - (cols_in_this_row - 1) * cur_gappih;
|
||||
float fl_cx = m->w.x + cur_gappoh;
|
||||
for (int j = 0; j < col_idx; j++)
|
||||
fl_cx += avail_w * (col_pers[j] / sum_col_this_row) + cur_gappih;
|
||||
float fl_cw = (col_idx == cols_in_this_row - 1)
|
||||
? (m->w.x + m->w.width - cur_gappoh - fl_cx)
|
||||
: avail_w * (col_pers[col_idx] / sum_col_this_row);
|
||||
fl_cy = row_y[row_idx];
|
||||
fl_ch = row_h[row_idx];
|
||||
|
||||
resize(c,
|
||||
(struct wlr_box){.x = (int32_t)fl_cx,
|
||||
|
|
@ -467,6 +517,5 @@ void vertical_fair(Monitor *m) {
|
|||
.width = (int32_t)fl_cw,
|
||||
.height = (int32_t)fl_ch},
|
||||
0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue