Improve code of funcs "arrange" and "arrangemon"

This commit is contained in:
Alex Kotov 2021-11-20 20:25:45 +05:00
parent 1d95ddcfdc
commit fbe103ade6
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 43 additions and 30 deletions

View file

@ -407,42 +407,39 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int bw, int interact)
void void
arrange(Monitor *m) arrange(Monitor *m)
{ {
if (m) if (m) {
showhide(m->stack); showhide(m->stack);
else for (m = mons; m; m = m->next) } else {
for (m = mons; m; m = m->next) {
showhide(m->stack); showhide(m->stack);
}
}
if (m) { if (m) {
arrangemon(m); arrangemon(m);
restack(m); restack(m);
} else for (m = mons; m; m = m->next) } else {
for (m = mons; m; m = m->next) {
arrangemon(m); arrangemon(m);
} }
}
}
void void
arrangemon(Monitor *m) arrangemon(Monitor *m)
{ {
unsigned int visible_clients = 0; unsigned int visible_clients = 0;
for (const Client *client = m->clients; client; client = client->next) { for (const Client *client = m->clients; client; client = client->next) {
if (ISVISIBLE(client)) ++visible_clients; if (ISVISIBLE(client)) {
++visible_clients;
}
} }
if (m->lt[m->sellt]->arrange) if (m->lt[m->sellt]->arrange) {
m->lt[m->sellt]->arrange(m); m->lt[m->sellt]->arrange(m);
else { } else {
const int border_width = settings_get_border_width(); floating(selmon);
/* <>< case; rather than providing an arrange function and upsetting other logic that tests for its presence, simply add borders here */
for (Client *c = selmon->clients; c; c = c->next)
if (ISVISIBLE(c) && c->bw == 0)
resize(
c,
c->x,
c->y,
c->w - 2 * border_width,
c->h - 2 * border_width,
border_width,
0
);
} }
} }

View file

@ -1,8 +1,7 @@
#ifndef _DWM_LAYOUTS_C #ifndef _DWM_LAYOUTS_C
#define _DWM_LAYOUTS_C #define _DWM_LAYOUTS_C
void void centeredmaster(Monitor *m)
centeredmaster(Monitor *m)
{ {
unsigned int n = 0; unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n); for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
@ -103,8 +102,26 @@ centeredmaster(Monitor *m)
} }
} }
void void floating(Monitor *m)
horizontile(Monitor *m) {
const int border_width = settings_get_border_width();
for (Client *c = m->clients; c; c = c->next) {
if (ISVISIBLE(c) && c->bw == 0) {
resize(
c,
c->x,
c->y,
c->w - 2 * border_width,
c->h - 2 * border_width,
border_width,
0
);
}
}
}
void horizontile(Monitor *m)
{ {
unsigned int n = 0; unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n); for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
@ -173,8 +190,7 @@ horizontile(Monitor *m)
} }
} }
void void monocle(Monitor *m)
monocle(Monitor *m)
{ {
bool any_is_fullscreen = false; bool any_is_fullscreen = false;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) { for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
@ -199,8 +215,7 @@ monocle(Monitor *m)
} }
} }
void void tile(Monitor *m)
tile(Monitor *m)
{ {
unsigned int n = 0; unsigned int n = 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n); for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);

View file

@ -2,6 +2,7 @@
#define _DWM_LAYOUTS_H #define _DWM_LAYOUTS_H
static void centeredmaster(Monitor *m); static void centeredmaster(Monitor *m);
static void floating(Monitor *m);
static void horizontile(Monitor *); static void horizontile(Monitor *);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void tile(Monitor *); static void tile(Monitor *);