Implement layout symbol functions
This commit is contained in:
parent
70f16b9b05
commit
e93ff551de
6
Makefile
6
Makefile
|
@ -3,7 +3,7 @@
|
|||
|
||||
include config.mk
|
||||
|
||||
SRC = atoms.c drw.c dwm.c settings.c spawn.c tags.c util.c
|
||||
SRC = atoms.c drw.c dwm.c layouts.c settings.c spawn.c tags.c util.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: options polytreewm
|
||||
|
@ -17,7 +17,7 @@ options:
|
|||
%.o: %.c
|
||||
${CC} -c $< -o $@ ${CFLAGS}
|
||||
|
||||
${OBJ}: atoms.h drw.h config.def.h config.mk settings.h spawn.h tags.h util.h
|
||||
${OBJ}: atoms.h drw.h config.def.h config.mk layouts.h settings.h spawn.h tags.h util.h
|
||||
|
||||
polytreewm: ${OBJ}
|
||||
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
|
@ -58,4 +58,4 @@ uninstall:
|
|||
${DESTDIR}${ICONSPREFIX}/polytreewm.png \
|
||||
${DESTDIR}${XSESSIONSPREFIX}/polytreewm.desktop
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
.PHONY: all options clean dist install uninstall xinstall
|
||||
|
|
10
config.def.h
10
config.def.h
|
@ -36,11 +36,11 @@ static const Rule rules[] = {
|
|||
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[M]", monocle }, /* first entry is default */
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ "[]=", tile },
|
||||
{ "=[]=", centeredmaster },
|
||||
/* symbol function, arrange function */
|
||||
{ layouts_symbol_monocle, monocle }, /* first entry is default */
|
||||
{ layouts_symbol_floating, NULL }, /* no layout function means floating behavior */
|
||||
{ layouts_symbol_tile, tile },
|
||||
{ layouts_symbol_centeredmaster, centeredmaster },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
|
|
57
dwm.c
57
dwm.c
|
@ -42,6 +42,7 @@
|
|||
|
||||
#include "atoms.h"
|
||||
#include "drw.h"
|
||||
#include "layouts.h"
|
||||
#include "settings.h"
|
||||
#include "spawn.h"
|
||||
#include "tags.h"
|
||||
|
@ -121,7 +122,7 @@ typedef struct {
|
|||
} Key;
|
||||
|
||||
typedef struct {
|
||||
const char *symbol;
|
||||
LayoutsSymbolFunc symbol_func;
|
||||
void (*arrange)(Monitor *);
|
||||
} Layout;
|
||||
|
||||
|
@ -444,14 +445,28 @@ arrange(Monitor *m)
|
|||
void
|
||||
arrangemon(Monitor *m)
|
||||
{
|
||||
Client *c;
|
||||
unsigned int visible_clients = 0;
|
||||
for (const Client *client = m->clients; client; client = client->next) {
|
||||
if (ISVISIBLE(client)) ++visible_clients;
|
||||
}
|
||||
|
||||
const LayoutsSymbolFunc symbol_func =
|
||||
m->lt[m->sellt]->symbol_func == NULL
|
||||
? layouts_symbol_unknown
|
||||
: m->lt[m->sellt]->symbol_func;
|
||||
|
||||
symbol_func(
|
||||
m->ltsymbol,
|
||||
sizeof(m->ltsymbol),
|
||||
m->nmaster,
|
||||
visible_clients
|
||||
);
|
||||
|
||||
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
|
||||
if (m->lt[m->sellt]->arrange)
|
||||
m->lt[m->sellt]->arrange(m);
|
||||
else
|
||||
/* <>< case; rather than providing an arrange function and upsetting other logic that tests for its presence, simply add borders here */
|
||||
for (c = selmon->clients; c; c = c->next)
|
||||
for (Client *c = selmon->clients; c; c = c->next)
|
||||
if (ISVISIBLE(c) && c->bw == 0)
|
||||
resize(c, c->x, c->y, c->w - 2*borderpx, c->h - 2*borderpx, borderpx, 0);
|
||||
}
|
||||
|
@ -580,7 +595,7 @@ void
|
|||
cleanup(void)
|
||||
{
|
||||
Arg a = {.ui = ~0};
|
||||
Layout foo = { "", NULL };
|
||||
Layout foo = { NULL, NULL };
|
||||
Monitor *m;
|
||||
size_t i;
|
||||
|
||||
|
@ -813,7 +828,14 @@ createmon(void)
|
|||
m->topbar = topbar;
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
|
||||
const LayoutsSymbolFunc symbol_func =
|
||||
layouts[0].symbol_func == NULL
|
||||
? layouts_symbol_unknown
|
||||
: layouts[0].symbol_func;
|
||||
|
||||
symbol_func(m->ltsymbol, sizeof(m->ltsymbol), 0, 0);
|
||||
|
||||
m->pertag = ecalloc(1, sizeof(Pertag));
|
||||
m->pertag->curtag = m->pertag->prevtag = 1;
|
||||
|
||||
|
@ -1370,14 +1392,8 @@ maprequest(XEvent *e)
|
|||
void
|
||||
monocle(Monitor *m)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
Client *c;
|
||||
|
||||
for (c = m->clients; c; c = c->next)
|
||||
if (ISVISIBLE(c))
|
||||
n++;
|
||||
if (n > 0) /* override layout symbol */
|
||||
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
|
||||
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||||
resize(c, m->wx, m->wy, m->ww, m->wh, 0, 0);
|
||||
}
|
||||
|
@ -1935,10 +1951,21 @@ setlayout(const Arg *arg)
|
|||
selmon->lt[selmon->sellt] = new_layout;
|
||||
}
|
||||
|
||||
strncpy(
|
||||
unsigned int visible_clients = 0;
|
||||
for (const Client *client = selmon->clients; client; client = client->next) {
|
||||
if (ISVISIBLE(client)) ++visible_clients;
|
||||
}
|
||||
|
||||
const LayoutsSymbolFunc symbol_func =
|
||||
selmon->lt[selmon->sellt]->symbol_func == NULL
|
||||
? layouts_symbol_unknown
|
||||
: selmon->lt[selmon->sellt]->symbol_func;
|
||||
|
||||
symbol_func(
|
||||
selmon->ltsymbol,
|
||||
selmon->lt[selmon->sellt]->symbol,
|
||||
sizeof(selmon->ltsymbol)
|
||||
sizeof(selmon->ltsymbol),
|
||||
selmon->nmaster,
|
||||
visible_clients
|
||||
);
|
||||
|
||||
if (selmon->sel) {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#include "layouts.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TMP_BUFFER_SIZE 128
|
||||
|
||||
void layouts_symbol_unknown(
|
||||
char *const buffer,
|
||||
const size_t buffer_size,
|
||||
const unsigned int clients_in_master,
|
||||
const unsigned int visible_clients
|
||||
) {
|
||||
// TODO: maybe we should assert
|
||||
if (buffer == NULL) return;
|
||||
|
||||
char tmp[TMP_BUFFER_SIZE];
|
||||
sprintf(tmp, "?%u/%u?", clients_in_master, visible_clients);
|
||||
tmp[(buffer_size > TMP_BUFFER_SIZE ? TMP_BUFFER_SIZE : buffer_size) - 1] = '\0';
|
||||
strncpy(buffer, tmp, buffer_size);
|
||||
}
|
||||
|
||||
void layouts_symbol_monocle(
|
||||
char *const buffer,
|
||||
const size_t buffer_size,
|
||||
const unsigned int clients_in_master,
|
||||
const unsigned int visible_clients
|
||||
) {
|
||||
// TODO: maybe we should assert
|
||||
if (buffer == NULL) return;
|
||||
|
||||
char tmp[TMP_BUFFER_SIZE];
|
||||
sprintf(tmp, "[%u]", visible_clients);
|
||||
tmp[(buffer_size > TMP_BUFFER_SIZE ? TMP_BUFFER_SIZE : buffer_size) - 1] = '\0';
|
||||
strncpy(buffer, tmp, buffer_size);
|
||||
}
|
||||
|
||||
void layouts_symbol_floating(
|
||||
char *const buffer,
|
||||
const size_t buffer_size,
|
||||
const unsigned int clients_in_master,
|
||||
const unsigned int visible_clients
|
||||
) {
|
||||
// TODO: maybe we should assert
|
||||
if (buffer == NULL) return;
|
||||
|
||||
char tmp[TMP_BUFFER_SIZE];
|
||||
strcpy(tmp, "><>");
|
||||
tmp[(buffer_size > TMP_BUFFER_SIZE ? TMP_BUFFER_SIZE : buffer_size) - 1] = '\0';
|
||||
strncpy(buffer, tmp, buffer_size);
|
||||
}
|
||||
|
||||
void layouts_symbol_tile(
|
||||
char *const buffer,
|
||||
const size_t buffer_size,
|
||||
const unsigned int clients_in_master,
|
||||
const unsigned int visible_clients
|
||||
) {
|
||||
// TODO: maybe we should assert
|
||||
if (buffer == NULL) return;
|
||||
|
||||
char tmp[TMP_BUFFER_SIZE];
|
||||
sprintf(tmp, "[%u]=", clients_in_master);
|
||||
tmp[(buffer_size > TMP_BUFFER_SIZE ? TMP_BUFFER_SIZE : buffer_size) - 1] = '\0';
|
||||
strncpy(buffer, tmp, buffer_size);
|
||||
}
|
||||
|
||||
void layouts_symbol_centeredmaster(
|
||||
char *const buffer,
|
||||
const size_t buffer_size,
|
||||
const unsigned int clients_in_master,
|
||||
const unsigned int visible_clients
|
||||
) {
|
||||
// TODO: maybe we should assert
|
||||
if (buffer == NULL) return;
|
||||
|
||||
char tmp[TMP_BUFFER_SIZE];
|
||||
sprintf(tmp, "=[%u]=", clients_in_master);
|
||||
tmp[(buffer_size > TMP_BUFFER_SIZE ? TMP_BUFFER_SIZE : buffer_size) - 1] = '\0';
|
||||
strncpy(buffer, tmp, buffer_size);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef _LAYOUTS_H
|
||||
#define _LAYOUTS_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef void (*LayoutsSymbolFunc)(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
void layouts_symbol_unknown(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
void layouts_symbol_monocle(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
void layouts_symbol_floating(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
void layouts_symbol_tile(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
void layouts_symbol_centeredmaster(
|
||||
char *buffer,
|
||||
size_t buffer_size,
|
||||
unsigned int clients_in_master,
|
||||
unsigned int visible_clients
|
||||
);
|
||||
|
||||
#endif // _LAYOUTS_H
|
Loading…
Reference in New Issue