all repos — dwm @ 2feb3afe784cbd9d900bd70aad91431a4b25f2ab

fork of suckless dynamic window manager

layout.c (view raw)

  1/* See LICENSE file for copyright and license details. */
  2#include "dwm.h"
  3#include <stdlib.h>
  4
  5unsigned int blw = 0;
  6Layout *lt = NULL;
  7
  8/* static */
  9
 10static unsigned int nlayouts = 0;
 11
 12LAYOUTS
 13
 14/* extern */
 15
 16void
 17floating(void) {
 18	Client *c;
 19
 20	if(lt->arrange != floating)
 21		return;
 22
 23	for(c = clients; c; c = c->next)
 24		if(isvisible(c)) {
 25			unban(c);
 26			resize(c, c->x, c->y, c->w, c->h, True);
 27		}
 28		else
 29			ban(c);
 30	focus(NULL);
 31	restack();
 32}
 33
 34void
 35focusclient(const char *arg) {
 36	Client *c;
 37   
 38	if(!sel || !arg)
 39		return;
 40	if(atoi(arg) < 0) {
 41		for(c = sel->prev; c && !isvisible(c); c = c->prev);
 42		if(!c) {
 43			for(c = clients; c && c->next; c = c->next);
 44			for(; c && !isvisible(c); c = c->prev);
 45		}
 46	}
 47	else {
 48		for(c = sel->next; c && !isvisible(c); c = c->next);
 49		if(!c)
 50			for(c = clients; c && !isvisible(c); c = c->next);
 51	}
 52	if(c) {
 53		focus(c);
 54		restack();
 55	}
 56}
 57
 58void
 59initlayouts(void) {
 60	unsigned int i, w;
 61
 62	lt = &layout[0];
 63	nlayouts = sizeof layout / sizeof layout[0];
 64	for(blw = i = 0; i < nlayouts; i++) {
 65		w = textw(layout[i].symbol);
 66		if(w > blw)
 67			blw = w;
 68	}
 69}
 70
 71Client *
 72nexttiled(Client *c) {
 73	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
 74	return c;
 75}
 76
 77void
 78restack(void) {
 79	Client *c;
 80	XEvent ev;
 81	XWindowChanges wc;
 82
 83	drawstatus();
 84	if(!sel)
 85		return;
 86	if(sel->isfloating || lt->arrange == floating)
 87		XRaiseWindow(dpy, sel->win);
 88	if(lt->arrange != floating) {
 89		wc.stack_mode = Below;
 90		wc.sibling = barwin;
 91		if(!sel->isfloating) {
 92			XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
 93			wc.sibling = sel->win;
 94		}
 95		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
 96			if(c == sel)
 97				continue;
 98			XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
 99			wc.sibling = c->win;
100		}
101	}
102	XSync(dpy, False);
103	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
104}
105
106void
107setlayout(const char *arg) {
108	int i;
109
110	if(!arg) {
111		lt++;
112		if(lt == layout + nlayouts)
113			lt = layout;
114	}
115	else {
116		i = atoi(arg);
117		if(i < 0 || i >= nlayouts)
118			return;
119		lt = &layout[i];
120	}
121	if(sel)
122		lt->arrange();
123	else
124		drawstatus();
125}
126
127void
128togglebar(const char *arg) {
129	if(bpos == BarOff)
130		bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
131	else
132		bpos = BarOff;
133	updatebarpos();
134	lt->arrange();
135}
136
137void
138togglemax(const char *arg) {
139	XEvent ev;
140
141	if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
142		return;
143	if((sel->ismax = !sel->ismax)) {
144		sel->rx = sel->x;
145		sel->ry = sel->y;
146		sel->rw = sel->w;
147		sel->rh = sel->h;
148		resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
149	}
150	else
151		resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
152	drawstatus();
153	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
154}