dwm

personal fork of dwm (rnpnr branch)
git clone anongit@rnpnr.xyz:dwm.git
Log | Files | Refs | Feed | README | LICENSE

gaps.c (2679B)


      1 /* Key binding functions */
      2 static void defaultgaps(const Arg *arg);
      3 static void incrgaps(const Arg *arg);
      4 static void incrigaps(const Arg *arg);
      5 static void incrogaps(const Arg *arg);
      6 static void togglegaps(const Arg *arg);
      7 /* Internals */
      8 static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
      9 static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
     10 static void setgaps(int oh, int ov, int ih, int iv);
     11 
     12 /* Settings */
     13 static int enablegaps = 1;
     14 
     15 void
     16 setgaps(int oh, int ov, int ih, int iv)
     17 {
     18 	if (oh < 0) oh = 0;
     19 	if (ov < 0) ov = 0;
     20 	if (ih < 0) ih = 0;
     21 	if (iv < 0) iv = 0;
     22 
     23 	selmon->gappoh = oh;
     24 	selmon->gappov = ov;
     25 	selmon->gappih = ih;
     26 	selmon->gappiv = iv;
     27 	arrange(selmon);
     28 }
     29 
     30 void
     31 togglegaps(const Arg *arg)
     32 {
     33 	enablegaps = !enablegaps;
     34 	arrange(NULL);
     35 }
     36 
     37 void
     38 defaultgaps(const Arg *arg)
     39 {
     40 	setgaps(gappoh, gappov, gappih, gappiv);
     41 }
     42 
     43 void
     44 incrgaps(const Arg *arg)
     45 {
     46 	setgaps(selmon->gappoh + arg->i,
     47 	        selmon->gappov + arg->i,
     48 	        selmon->gappih + arg->i,
     49 	        selmon->gappiv + arg->i);
     50 }
     51 
     52 void
     53 incrigaps(const Arg *arg)
     54 {
     55 	setgaps(selmon->gappoh,
     56 	        selmon->gappov,
     57 	        selmon->gappih + arg->i,
     58 	        selmon->gappiv + arg->i);
     59 }
     60 
     61 void
     62 incrogaps(const Arg *arg)
     63 {
     64 	setgaps(selmon->gappoh + arg->i,
     65 	        selmon->gappov + arg->i,
     66 	        selmon->gappih,
     67 	        selmon->gappiv);
     68 }
     69 
     70 void
     71 getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
     72 {
     73 	unsigned int n, oe, ie;
     74 	oe = ie = enablegaps;
     75 	Client *c;
     76 
     77 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     78 
     79 	if (smartgaps && n == 1) {
     80 		oe = 0; /* outer gaps disabled when only one client */
     81 	}
     82 
     83 	*oh = m->gappoh*oe; /* outer horizontal gap */
     84 	*ov = m->gappov*oe; /* outer vertical gap */
     85 	*ih = m->gappih*ie; /* inner horizontal gap */
     86 	*iv = m->gappiv*ie; /* inner vertical gap */
     87 	*nc = n;            /* number of clients */
     88 }
     89 
     90 void
     91 getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr)
     92 {
     93 	unsigned int n;
     94 	float mfacts, sfacts;
     95 	int mtotal = 0, stotal = 0;
     96 	Client *c;
     97 
     98 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     99 	mfacts = MIN(n, m->nmaster);
    100 	sfacts = n - m->nmaster;
    101 
    102 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
    103 		if (n < m->nmaster)
    104 			mtotal += msize / mfacts;
    105 		else
    106 			stotal += ssize / sfacts;
    107 
    108 	*mf = mfacts; /* total factor of master area */
    109 	*sf = sfacts; /* total factor of stack area */
    110 	*mr = msize - mtotal; /* the remainder (rest) of pixels after an even master split */
    111 	*sr = ssize - stotal; /* the remainder (rest) of pixels after an even stack split */
    112 }