Improve layout symbol functions

This commit is contained in:
Alex Kotov 2021-11-15 04:26:13 +05:00
parent ee0c5ec71e
commit 61542641d9
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 38 additions and 18 deletions

29
dwm.c
View file

@ -450,12 +450,8 @@ arrangemon(Monitor *m)
if (ISVISIBLE(client)) ++visible_clients; if (ISVISIBLE(client)) ++visible_clients;
} }
const LayoutsSymbolFunc symbol_func = layouts_symbol_func(
m->lt[m->sellt]->symbol_func == NULL m->lt[m->sellt]->symbol_func,
? layouts_symbol_unknown
: m->lt[m->sellt]->symbol_func;
symbol_func(
m->ltsymbol, m->ltsymbol,
sizeof(m->ltsymbol), sizeof(m->ltsymbol),
m->nmaster, m->nmaster,
@ -829,12 +825,13 @@ createmon(void)
m->lt[0] = &layouts[0]; m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)]; m->lt[1] = &layouts[1 % LENGTH(layouts)];
const LayoutsSymbolFunc symbol_func = layouts_symbol_func(
layouts[0].symbol_func == NULL layouts[0].symbol_func,
? layouts_symbol_unknown m->ltsymbol,
: layouts[0].symbol_func; sizeof(m->ltsymbol),
0,
symbol_func(m->ltsymbol, sizeof(m->ltsymbol), 0, 0); 0
);
m->pertag = ecalloc(1, sizeof(Pertag)); m->pertag = ecalloc(1, sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1; m->pertag->curtag = m->pertag->prevtag = 1;
@ -1956,12 +1953,8 @@ setlayout(const Arg *arg)
if (ISVISIBLE(client)) ++visible_clients; if (ISVISIBLE(client)) ++visible_clients;
} }
const LayoutsSymbolFunc symbol_func = layouts_symbol_func(
selmon->lt[selmon->sellt]->symbol_func == NULL selmon->lt[selmon->sellt]->symbol_func,
? layouts_symbol_unknown
: selmon->lt[selmon->sellt]->symbol_func;
symbol_func(
selmon->ltsymbol, selmon->ltsymbol,
sizeof(selmon->ltsymbol), sizeof(selmon->ltsymbol),
selmon->nmaster, selmon->nmaster,

View file

@ -5,6 +5,25 @@
#define TMP_BUFFER_SIZE 128 #define TMP_BUFFER_SIZE 128
void layouts_symbol_func(
LayoutsSymbolFunc func,
char *const buffer,
const size_t buffer_size,
const unsigned int clients_in_master,
const unsigned int visible_clients
) {
if (func == NULL) {
func = layouts_symbol_unknown;
}
func(
buffer,
buffer_size,
clients_in_master,
visible_clients
);
}
void layouts_symbol_unknown( void layouts_symbol_unknown(
char *const buffer, char *const buffer,
const size_t buffer_size, const size_t buffer_size,

View file

@ -10,6 +10,14 @@ typedef void (*LayoutsSymbolFunc)(
unsigned int visible_clients unsigned int visible_clients
); );
void layouts_symbol_func(
LayoutsSymbolFunc func,
char *buffer,
size_t buffer_size,
unsigned int clients_in_master,
unsigned int visible_clients
);
void layouts_symbol_unknown( void layouts_symbol_unknown(
char *buffer, char *buffer,
size_t buffer_size, size_t buffer_size,