polytreewm/src/dwm/spaghetti/layouts.c

359 lines
11 KiB
C
Raw Normal View History

2021-11-16 15:03:26 +00:00
#ifndef _DWM_LAYOUTS_C
#define _DWM_LAYOUTS_C
void centeredmaster(void *const arg)
{
Monitor *const m = arg;
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
2021-11-20 14:28:50 +00:00
const float master_area_factor = unit_get_master_area_factor(m->unit);
unsigned int mx = 0;
2021-12-04 17:26:32 +00:00
unsigned int mw = m->window_area_geom.sizes.w;
unsigned int tw = mw;
if (n > m->nmaster) {
/* go mfact box in the center if more than nmaster clients */
2021-11-20 21:56:08 +00:00
mw = m->nmaster
2021-12-04 17:26:32 +00:00
? m->window_area_geom.sizes.w * master_area_factor
2021-11-20 21:56:08 +00:00
: 0;
2021-12-04 17:26:32 +00:00
tw = m->window_area_geom.sizes.w - mw;
if (n - m->nmaster > 1) {
/* only one client */
2021-12-04 17:26:32 +00:00
mx = (m->window_area_geom.sizes.w - mw) / 2;
tw = (m->window_area_geom.sizes.w - mw) / 2;
}
}
2021-11-20 19:53:53 +00:00
const bool is_fullscreen = m->sel == NULL ? false : m->sel->state.is_fullscreen;
const int gap_size = helpers_gap_size(n, is_fullscreen, is_fullscreen);
const int border_width = helpers_border_width(n, is_fullscreen, is_fullscreen);
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
Client *c = nexttiled(m->clients);
unsigned int oty = 0, ety = 0, my = 0;
for (unsigned int i = 0; c; c = nexttiled(c->next), ++i) {
if (i < m->nmaster) {
// nmaster clients are stacked vertically,
// in the center of the screen
2021-11-20 19:11:06 +00:00
const unsigned int h =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.h - my)
2021-11-20 21:56:08 +00:00
/
(MIN(n, m->nmaster) - i);
const int left_gap = (n <= m->nmaster + 1) ? gap_size : top_left_half_gap;
const int top_gap = i == 0 ? gap_size : top_left_half_gap;
const int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
const int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + mx + left_gap,
m->window_area_geom.position.y + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_height =
2021-12-04 17:44:06 +00:00
win_geom_total_height(&c->state.geom);
2021-11-20 21:00:39 +00:00
my += total_height + top_gap + bottom_gap;
} else {
// stack clients are stacked vertically
if ((i - m->nmaster) % 2) {
2021-11-20 19:11:06 +00:00
const unsigned int h =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.h - ety) / ((1 + n - i) / 2);
const int left_gap = gap_size;
const int top_gap = (i == m->nmaster + 1) ? gap_size : top_left_half_gap;
const int right_gap = bottom_right_half_gap;
const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + left_gap,
m->window_area_geom.position.y + ety + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_height =
2021-12-04 17:44:06 +00:00
win_geom_total_height(&c->state.geom);
2021-11-20 21:00:39 +00:00
ety += total_height + top_gap + bottom_gap;
} else {
2021-11-20 19:11:06 +00:00
const unsigned int h =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.h - oty) / ((1 + n - i) / 2);
const int left_gap = (m->nmaster == 0 && n == 1) ? gap_size : top_left_half_gap;
const int top_gap = i == m->nmaster ? gap_size : top_left_half_gap;
const int right_gap = gap_size;
const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + mx + mw + left_gap,
m->window_area_geom.position.y + oty + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_height =
2021-12-04 17:44:06 +00:00
win_geom_total_height(&c->state.geom);
2021-11-20 21:00:39 +00:00
oty += total_height + top_gap + bottom_gap;
}
}
}
}
void floating(void *const arg)
{
Monitor *const m = arg;
const int border_width = settings_get_border_width();
for (Client *c = m->clients; c; c = c->next) {
2021-12-04 17:26:32 +00:00
if (ISVISIBLE(c) && c->state.geom.border_width == 0) {
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
c->state.geom.basic.position.x,
c->state.geom.basic.position.y,
c->state.geom.basic.sizes.w - 2 * border_width,
c->state.geom.basic.sizes.h - 2 * border_width,
2021-11-20 22:49:19 +00:00
border_width
);
2021-11-20 22:49:19 +00:00
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
}
}
}
void horizontile(void *const arg)
2021-11-16 03:08:39 +00:00
{
Monitor *const m = arg;
2021-11-16 03:08:39 +00:00
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
2021-11-20 14:28:50 +00:00
const float master_area_factor = unit_get_master_area_factor(m->unit);
2021-11-20 19:53:53 +00:00
const bool is_fullscreen = m->sel == NULL ? false : m->sel->state.is_fullscreen;
2021-11-16 03:08:39 +00:00
const int gap_size = helpers_gap_size(n, is_fullscreen, is_fullscreen);
const int border_width = helpers_border_width(n, is_fullscreen, is_fullscreen);
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
2021-11-20 19:11:06 +00:00
const unsigned int mh =
n > m->nmaster
?
2021-12-04 17:26:32 +00:00
(m->nmaster ? m->window_area_geom.sizes.h * master_area_factor : 0)
2021-11-20 19:11:06 +00:00
:
2021-12-04 17:26:32 +00:00
m->window_area_geom.sizes.h;
2021-11-16 03:08:39 +00:00
Client *c = nexttiled(m->clients);
for (unsigned int i = 0, mx = 0, tx = 0; c; c = nexttiled(c->next), ++i) {
if (i < m->nmaster) {
2021-11-20 19:11:06 +00:00
const unsigned int w =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.w - mx)
2021-11-20 21:56:08 +00:00
/
(MIN(n, m->nmaster) - i);
2021-11-16 03:08:39 +00:00
const unsigned int left_gap = i == 0 ? gap_size : top_left_half_gap;
const unsigned int top_gap = gap_size;
const unsigned int right_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + mx + left_gap,
m->window_area_geom.position.y + top_gap,
2021-11-16 03:08:39 +00:00
w - 2 * border_width - left_gap - right_gap,
mh - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
2021-11-16 03:08:39 +00:00
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_width =
2021-12-04 17:44:06 +00:00
win_geom_total_width(&c->state.geom);
2021-11-20 21:00:39 +00:00
2021-11-16 03:08:39 +00:00
// FIXME: maybe need + left_gap + right_gap
2021-12-04 17:26:32 +00:00
if (mx + total_width < m->window_area_geom.sizes.w) {
2021-11-20 21:00:39 +00:00
mx += total_width + left_gap + right_gap;
2021-11-16 03:08:39 +00:00
}
} else {
2021-12-04 17:26:32 +00:00
const unsigned int w = (m->window_area_geom.sizes.w - tx) / (n - i);
2021-11-16 03:08:39 +00:00
const unsigned int left_gap = i == m->nmaster ? gap_size : top_left_half_gap;
const unsigned int top_gap = m->nmaster == 0 ? gap_size : top_left_half_gap;
const unsigned int right_gap = (i == n - 1) ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = gap_size;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + tx + left_gap,
m->window_area_geom.position.y + mh + top_gap,
2021-11-16 03:08:39 +00:00
w - 2 * border_width - left_gap - right_gap,
2021-12-04 17:26:32 +00:00
m->window_area_geom.sizes.h - mh - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
2021-11-16 03:08:39 +00:00
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_width =
2021-12-04 17:44:06 +00:00
win_geom_total_width(&c->state.geom);
2021-11-20 21:00:39 +00:00
2021-11-16 03:08:39 +00:00
// FIXME: maybe need + left_gap + right_gap
2021-12-04 17:26:32 +00:00
if (tx + total_width < m->window_area_geom.sizes.w) {
2021-11-20 21:00:39 +00:00
tx += total_width + left_gap + right_gap;
2021-11-16 03:08:39 +00:00
}
}
}
}
void monocle(void *const arg)
{
Monitor *const m = arg;
bool any_is_fullscreen = false;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
2021-11-20 19:53:53 +00:00
any_is_fullscreen = any_is_fullscreen || c->state.is_fullscreen;
}
2021-11-20 19:53:53 +00:00
const bool is_fullscreen = m->sel == NULL ? false : m->sel->state.is_fullscreen;
const int gap_size = helpers_gap_size(1, is_fullscreen, any_is_fullscreen);
const int border_width = helpers_border_width(1, is_fullscreen, any_is_fullscreen);
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + gap_size,
m->window_area_geom.position.y + gap_size,
m->window_area_geom.sizes.w - 2 * border_width - 2 * gap_size,
m->window_area_geom.sizes.h - 2 * border_width - 2 * gap_size,
2021-11-20 22:49:19 +00:00
border_width
);
2021-11-20 22:49:19 +00:00
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
}
}
void tile(void *const arg)
{
Monitor *const m = arg;
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
2021-11-20 14:28:50 +00:00
const float master_area_factor = unit_get_master_area_factor(m->unit);
2021-11-20 19:53:53 +00:00
const bool is_fullscreen = m->sel == NULL ? false : m->sel->state.is_fullscreen;
const int gap_size = helpers_gap_size(n, is_fullscreen, is_fullscreen);
const int border_width = helpers_border_width(n, is_fullscreen, is_fullscreen);
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
2021-11-20 19:11:06 +00:00
const unsigned int mw =
n > m->nmaster
?
2021-12-04 17:26:32 +00:00
(m->nmaster ? m->window_area_geom.sizes.w * master_area_factor : 0)
2021-11-20 19:11:06 +00:00
:
2021-12-04 17:26:32 +00:00
m->window_area_geom.sizes.w;
Client *c = nexttiled(m->clients);
for (unsigned int i = 0, my = 0, ty = 0; c; c = nexttiled(c->next), ++i) {
if (i < m->nmaster) {
2021-11-20 19:11:06 +00:00
const unsigned int h =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.h - my) / (MIN(n, m->nmaster) - i);
const unsigned int left_gap = gap_size;
const unsigned int top_gap = i == 0 ? gap_size : top_left_half_gap;
const unsigned int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + left_gap,
m->window_area_geom.position.y + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_height =
2021-12-04 17:44:06 +00:00
win_geom_total_height(&c->state.geom);
2021-11-20 21:00:39 +00:00
2021-11-16 03:08:39 +00:00
// FIXME: maybe need + top_gap + bottom_gap
2021-12-04 17:26:32 +00:00
if (my + total_height < m->window_area_geom.sizes.h) {
2021-11-20 21:00:39 +00:00
my += total_height + top_gap + bottom_gap;
}
} else {
2021-11-20 21:56:08 +00:00
const unsigned int h =
2021-12-04 17:26:32 +00:00
(m->window_area_geom.sizes.h - ty) / (n - i);
const unsigned int left_gap = m->nmaster == 0 ? gap_size : top_left_half_gap;
const unsigned int top_gap = i == m->nmaster ? gap_size : top_left_half_gap;
const unsigned int right_gap = gap_size;
const unsigned int bottom_gap = (i == n - 1) ? gap_size : bottom_right_half_gap;
2021-12-04 17:44:06 +00:00
struct WinGeom win_geom;
win_geom_init_from_args(
&win_geom,
2021-12-04 17:26:32 +00:00
m->window_area_geom.position.x + mw + left_gap,
m->window_area_geom.position.y + ty + top_gap,
m->window_area_geom.sizes.w - mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
2021-11-20 22:49:19 +00:00
border_width
);
2021-12-04 17:44:06 +00:00
resize(c, win_geom, 0);
2021-11-20 22:49:19 +00:00
2021-11-20 21:00:39 +00:00
const int total_height =
2021-12-04 17:44:06 +00:00
win_geom_total_height(&c->state.geom);
2021-11-20 21:00:39 +00:00
2021-11-16 03:08:39 +00:00
// FIXME: maybe need + top_gap + bottom_gap
2021-12-04 17:26:32 +00:00
if (ty + total_height < m->window_area_geom.sizes.h) {
2021-11-20 21:00:39 +00:00
ty += total_height + top_gap + bottom_gap;
}
}
}
}
2021-11-16 15:03:26 +00:00
#endif // _DWM_LAYOUTS_C