Move layout arrange functions to "dwm/layouts.c"

This commit is contained in:
Alex Kotov 2021-11-16 02:56:57 +05:00
parent 116568141e
commit c530a57c6c
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 189 additions and 186 deletions

190
dwm.c
View File

@ -319,7 +319,11 @@ struct Pertag {
int showbars[TAGS_COUNT + 1]; /* display bar for the current tag */
};
/* function implementations */
#include "dwm/layouts.c"
void
applyrules(Client *c)
{
@ -560,105 +564,6 @@ void configgap(const Arg *const arg)
arrange(selmon);
}
void
centeredmaster(Monitor *m)
{
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
unsigned int mx = 0;
unsigned int mw = m->ww;
unsigned int tw = mw;
if (n > m->nmaster) {
/* go mfact box in the center if more than nmaster clients */
mw = m->nmaster ? m->ww * m->mfact : 0;
tw = m->ww - mw;
if (n - m->nmaster > 1) {
/* only one client */
mx = (m->ww - mw) / 2;
tw = (m->ww - mw) / 2;
}
}
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = (n > 1 || enable_gap_for_single_window) ? settings_get_gap_size() : 0;
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = (n > 1 || enable_border_for_single_window) ? settings_get_border_width() : 0;
unsigned int oty = 0, ety = 0, my = 0;
Client *c = nexttiled(m->clients);
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
const unsigned int h = (m->wh - my) / (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;
resize(
c,
m->wx + mx + left_gap,
m->wy + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
my += HEIGHT(c) + top_gap + bottom_gap;
} else {
// stack clients are stacked vertically
if ((i - m->nmaster) % 2) {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + left_gap,
m->wy + ety + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
ety += HEIGHT(c) + top_gap + bottom_gap;
} else {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + mx + mw + left_gap,
m->wy + oty + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
oty += HEIGHT(c) + top_gap + bottom_gap;
}
}
}
}
void
checkotherwm(void)
{
@ -1469,28 +1374,6 @@ maprequest(XEvent *e)
manage(ev->window, &wa);
}
void
monocle(Monitor *m)
{
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = enable_gap_for_single_window ? settings_get_gap_size() : 0;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = enable_border_for_single_window ? settings_get_border_width() : 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
resize(
c,
m->wx + gap_size,
m->wy + gap_size,
m->ww - 2 * border_width - 2 * gap_size,
m->wh - 2 * border_width - 2 * gap_size,
border_width,
0
);
}
}
void
movemouse(const Arg *arg)
{
@ -2248,71 +2131,6 @@ tagmon(const Arg *arg)
sendmon(selmon->sel, dirtomon(arg->i));
}
void
tile(Monitor *m)
{
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = (n > 1 || enable_gap_for_single_window) ? settings_get_gap_size() : 0;
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = (n > 1 || enable_border_for_single_window) ? settings_get_border_width() : 0;
const unsigned int mw = n > m->nmaster ? (m->nmaster ? m->ww * m->mfact : 0) : m->ww;
Client *c = nexttiled(m->clients);
for (unsigned int i = 0, my = 0, ty = 0; c; c = nexttiled(c->next), ++i) {
if (i < m->nmaster) {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + left_gap,
m->wy + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
if (my + HEIGHT(c) < m->wh) {
my += HEIGHT(c) + top_gap + bottom_gap;
}
} else {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + mw + left_gap,
m->wy + ty + top_gap,
m->ww - mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
if (ty + HEIGHT(c) < m->wh) {
ty += HEIGHT(c) + top_gap + bottom_gap;
}
}
}
}
void
togglebar(const Arg *arg)
{

185
dwm/layouts.c Normal file
View File

@ -0,0 +1,185 @@
void
centeredmaster(Monitor *m)
{
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
unsigned int mx = 0;
unsigned int mw = m->ww;
unsigned int tw = mw;
if (n > m->nmaster) {
/* go mfact box in the center if more than nmaster clients */
mw = m->nmaster ? m->ww * m->mfact : 0;
tw = m->ww - mw;
if (n - m->nmaster > 1) {
/* only one client */
mx = (m->ww - mw) / 2;
tw = (m->ww - mw) / 2;
}
}
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = (n > 1 || enable_gap_for_single_window) ? settings_get_gap_size() : 0;
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = (n > 1 || enable_border_for_single_window) ? settings_get_border_width() : 0;
unsigned int oty = 0, ety = 0, my = 0;
Client *c = nexttiled(m->clients);
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
const unsigned int h = (m->wh - my) / (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;
resize(
c,
m->wx + mx + left_gap,
m->wy + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
my += HEIGHT(c) + top_gap + bottom_gap;
} else {
// stack clients are stacked vertically
if ((i - m->nmaster) % 2) {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + left_gap,
m->wy + ety + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
ety += HEIGHT(c) + top_gap + bottom_gap;
} else {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + mx + mw + left_gap,
m->wy + oty + top_gap,
tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
oty += HEIGHT(c) + top_gap + bottom_gap;
}
}
}
}
void
monocle(Monitor *m)
{
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = enable_gap_for_single_window ? settings_get_gap_size() : 0;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = enable_border_for_single_window ? settings_get_border_width() : 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
resize(
c,
m->wx + gap_size,
m->wy + gap_size,
m->ww - 2 * border_width - 2 * gap_size,
m->wh - 2 * border_width - 2 * gap_size,
border_width,
0
);
}
}
void
tile(Monitor *m)
{
unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return;
const bool enable_gap_for_single_window = settings_get_enable_gap_for_single_window();
const int gap_size = (n > 1 || enable_gap_for_single_window) ? settings_get_gap_size() : 0;
const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap;
const bool enable_border_for_single_window = settings_get_enable_border_for_single_window();
const int border_width = (n > 1 || enable_border_for_single_window) ? settings_get_border_width() : 0;
const unsigned int mw = n > m->nmaster ? (m->nmaster ? m->ww * m->mfact : 0) : m->ww;
Client *c = nexttiled(m->clients);
for (unsigned int i = 0, my = 0, ty = 0; c; c = nexttiled(c->next), ++i) {
if (i < m->nmaster) {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + left_gap,
m->wy + my + top_gap,
mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
if (my + HEIGHT(c) < m->wh) {
my += HEIGHT(c) + top_gap + bottom_gap;
}
} else {
const unsigned int h = (m->wh - 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;
resize(
c,
m->wx + mw + left_gap,
m->wy + ty + top_gap,
m->ww - mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap,
border_width,
0
);
if (ty + HEIGHT(c) < m->wh) {
ty += HEIGHT(c) + top_gap + bottom_gap;
}
}
}
}