[hackers] [dwm] apply nmaster patch || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Tue, 25 Oct 2011 21:41:21 +0200 (CEST)

changeset: 1578:dba91d42c851
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Tue Oct 25 20:40:46 2011 +0100
files: config.def.h dwm.c
description:
apply nmaster patch


diff -r 9330efd4971d -r dba91d42c851 config.def.h
--- a/config.def.h Tue Oct 25 20:08:08 2011 +0100
+++ b/config.def.h Tue Oct 25 20:40:46 2011 +0100
_AT_@ -24,6 +24,7 @@
 
 /* layout(s) */
 static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static const int nmaster = 1; /* number of clients in master area */
 static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
 
 static const Layout layouts[] = {
_AT_@ -55,6 +56,8 @@
         { MODKEY, XK_b, togglebar, {0} },
         { MODKEY, XK_j, focusstack, {.i = +1 } },
         { MODKEY, XK_k, focusstack, {.i = -1 } },
+ { MODKEY, XK_i, incnmaster, {.i = +1 } },
+ { MODKEY, XK_d, incnmaster, {.i = -1 } },
         { MODKEY, XK_h, setmfact, {.f = -0.05} },
         { MODKEY, XK_l, setmfact, {.f = +0.05} },
         { MODKEY, XK_Return, zoom, {0} },
diff -r 9330efd4971d -r dba91d42c851 dwm.c
--- a/dwm.c Tue Oct 25 20:08:08 2011 +0100
+++ b/dwm.c Tue Oct 25 20:40:46 2011 +0100
_AT_@ -125,6 +125,7 @@
 struct Monitor {
         char ltsymbol[16];
         float mfact;
+ int nmaster;
         int num;
         int by; /* bar geometry */
         int mx, my, mw, mh; /* screen size */
_AT_@ -189,6 +190,7 @@
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void grabbuttons(Client *c, Bool focused);
 static void grabkeys(void);
+static void incnmaster(const Arg *arg);
 static void initfont(const char *fontstr);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
_AT_@ -664,6 +666,7 @@
                 die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
         m->tagset[0] = m->tagset[1] = 1;
         m->mfact = mfact;
+ m->nmaster = nmaster;
         m->showbar = showbar;
         m->topbar = topbar;
         m->lt[0] = &layouts[0];
_AT_@ -1024,6 +1027,12 @@
 }
 
 void
+incnmaster(const Arg *arg) {
+ selmon->nmaster = MAX(selmon->nmaster + arg->i, 1);
+ arrange(selmon);
+}
+
+void
 initfont(const char *fontstr) {
         char *def, **missing;
         int n;
_AT_@ -1650,32 +1659,23 @@
 
 void
 tile(Monitor *m) {
- int x, y, h, w, mw;
- unsigned int i, n;
+ unsigned int i, n, mw, mh, tw, th;
         Client *c;
 
         for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
         if(n == 0)
                 return;
- /* master */
- c = nexttiled(m->clients);
- mw = m->mfact * m->ww;
- resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False);
- if(--n == 0)
- return;
- /* tile stack */
- x = (m->wx > c->x) ? c->x + mw + 2 * c->bw : m->wx + mw;
- y = m->wy;
- w = (m->wx > c->x) ? m->wx + m->ww - x : m->ww - mw;
- h = m->wh / n;
- if(h < bh)
- h = m->wh;
- for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
- resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
- ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False);
- if(h != m->wh)
- y = c->y + HEIGHT(c);
- }
+
+ mh = (n > m->nmaster) ? m->wh / m->nmaster : m->wh / n;
+ mw = (n > m->nmaster) ? m->ww * m->mfact : m->ww;
+ th = (n > m->nmaster) ? m->wh / (n - m->nmaster) : 0;
+ tw = m->ww - mw;
+
+ for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ if(i < m->nmaster)
+ resize(c, m->wx, m->wy + (i*mh), mw - (2*c->bw), mh - (2*c->bw), False);
+ else
+ resize(c, m->wx + mw, m->wy + ((i - m->nmaster)*th), tw - (2*c->bw), th - (2*c->bw), False);
 }
 
 void
Received on Tue Oct 25 2011 - 21:41:21 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 25 2011 - 21:48:06 CEST