all repos — dwm @ c0705eeb65733e8c5091e47d5bdc701a0779a949

fork of suckless dynamic window manager

screen.c (view raw)

  1/*
  2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3 * See LICENSE file for license details.
  4 */
  5
  6#include "dwm.h"
  7
  8void (*arrange)(Arg *) = tiling;
  9
 10void
 11view(Arg *arg)
 12{
 13	Client *c;
 14
 15	tsel = arg->i;
 16	arrange(NULL);
 17
 18	for(c = clients; c; c = getnext(c->next))
 19		drawtitle(c);
 20	drawstatus();
 21}
 22
 23void
 24floating(Arg *arg)
 25{
 26	Client *c;
 27
 28	arrange = floating;
 29	for(c = clients; c; c = c->next) {
 30		if(c->tags[tsel])
 31			resize(c, True);
 32		else
 33			ban(c);
 34	}
 35	if(sel && !sel->tags[tsel]) {
 36		if((sel = getnext(clients))) {
 37			higher(sel);
 38			focus(sel);
 39		}
 40	}
 41	drawstatus();
 42}
 43
 44void
 45tiling(Arg *arg)
 46{
 47	Client *c;
 48	int n, i, w, h;
 49
 50	w = sw - mw;
 51	arrange = tiling;
 52	for(n = 0, c = clients; c; c = c->next)
 53		if(c->tags[tsel] && !c->floating)
 54			n++;
 55
 56	if(n > 1)
 57		h = (sh - bh) / (n - 1);
 58	else
 59		h = sh - bh;
 60
 61	for(i = 0, c = clients; c; c = c->next) {
 62		if(c->tags[tsel]) {
 63			if(c->floating) {
 64				higher(c);
 65				resize(c, True);
 66				continue;
 67			}
 68			if(n == 1) {
 69				c->x = sx;
 70				c->y = sy + bh;
 71				c->w = sw - 2 * c->border;
 72				c->h = sh - 2 * c->border - bh;
 73			}
 74			else if(i == 0) {
 75				c->x = sx;
 76				c->y = sy + bh;
 77				c->w = mw - 2 * c->border;
 78				c->h = sh - 2 * c->border - bh;
 79			}
 80			else {
 81				c->x = sx + mw;
 82				c->y = sy + (i - 1) * h + bh;
 83				c->w = w - 2 * c->border;
 84				c->h = h - 2 * c->border;
 85			}
 86			resize(c, False);
 87			i++;
 88		}
 89		else
 90			ban(c);
 91	}
 92	if(!sel || (sel && !sel->tags[tsel])) {
 93		if((sel = getnext(clients))) {
 94			higher(sel);
 95			focus(sel);
 96		}
 97	}
 98	drawstatus();
 99}
100