sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-layoutmonitorrules-pertag-20211216-a786211d6cb7.diff (2923B)


      1 diff --git config.def.h config.def.h
      2 index a2ac963..9af5393 100644
      3 --- config.def.h
      4 +++ config.def.h
      5 @@ -37,6 +37,11 @@ static const int nmaster     = 1;    /* number of clients in master area */
      6  static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
      7  static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
      8  
      9 +static const LayoutMonitorRule lm_rules[] = {
     10 +	/* >=w, >=h, req'd layout, new nmaster, new mfact */
     11 +	{ 3000, 0,   0,            2,           0.66 },
     12 +};
     13 +
     14  static const Layout layouts[] = {
     15  	/* symbol     arrange function */
     16  	{ "[]=",      tile },    /* first entry is default */
     17 diff --git dwm.c dwm.c
     18 index 5eeb496..f83a555 100644
     19 --- dwm.c
     20 +++ dwm.c
     21 @@ -111,6 +111,13 @@ typedef struct {
     22  	void (*arrange)(Monitor *);
     23  } Layout;
     24  
     25 +typedef struct {
     26 +	int mw, mh;    /* >= matching */
     27 +	int layout;    /* only apply if this is the current layout, <0 for no matching */
     28 +	int nmaster;   /* the new nmaster to apply */
     29 +	float mfact;   /* the new mfact to apply */
     30 +} LayoutMonitorRule;
     31 +
     32  typedef struct Pertag Pertag;
     33  struct Monitor {
     34  	char ltsymbol[16];
     35 @@ -144,6 +151,7 @@ typedef struct {
     36  } Rule;
     37  
     38  /* function declarations */
     39 +static void applylmrules(void);
     40  static void applyrules(Client *c);
     41  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
     42  static void arrange(Monitor *m);
     43 @@ -287,6 +295,39 @@ struct Pertag {
     44  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     45  
     46  /* function implementations */
     47 +void
     48 +applylmrules(void)
     49 +{
     50 +	size_t t;
     51 +
     52 +	for (t = 0; t <= LENGTH(tags); t++) {
     53 +		float new_mfact = mfact;
     54 +		int new_nmaster = nmaster;
     55 +		size_t i;
     56 +
     57 +		for (i = 0; i < LENGTH(lm_rules); i++) {
     58 +			const LayoutMonitorRule *lmr = &lm_rules[i];
     59 +
     60 +			if (selmon->mw >= lmr->mw &&
     61 +			    selmon->mh >= lmr->mh &&
     62 +			    selmon->pertag->sellts[t] == lmr->layout)
     63 +			{
     64 +				new_mfact = lmr->mfact;
     65 +				new_nmaster = lmr->nmaster;
     66 +				break;
     67 +			}
     68 +		}
     69 +
     70 +		selmon->pertag->mfacts[t] = new_mfact;
     71 +		selmon->pertag->nmasters[t] = new_nmaster;
     72 +
     73 +	}
     74 +
     75 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
     76 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
     77 +	arrange(selmon);
     78 +}
     79 +
     80  void
     81  applyrules(Client *c)
     82  {
     83 @@ -583,6 +624,7 @@ configurenotify(XEvent *e)
     84  			}
     85  			focus(NULL);
     86  			arrange(NULL);
     87 +			applylmrules();
     88  		}
     89  	}
     90  }
     91 @@ -1532,9 +1574,8 @@ setlayout(const Arg *arg)
     92  	if (arg && arg->v)
     93  		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
     94  	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
     95 -	if (selmon->sel)
     96 -		arrange(selmon);
     97 -	else
     98 +	applylmrules();
     99 +	if (!selmon->sel)
    100  		drawbar(selmon);
    101  }
    102  
    103 @@ -1621,6 +1662,7 @@ setup(void)
    104  	XSelectInput(dpy, root, wa.event_mask);
    105  	grabkeys();
    106  	focus(NULL);
    107 +	applylmrules();
    108  }
    109  
    110