sites

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

dwm-rmaster-6.2.diff (3963B)


      1 From de2bfe560a8085630ffe976fd5972ee1e8d03916 Mon Sep 17 00:00:00 2001
      2 From: pskry <peter@skrypalle.dk>
      3 Date: Mon, 16 Nov 2020 17:47:05 +0100
      4 Subject: [PATCH] Enable swapping master- and stack-area
      5 
      6 Enables swapping the master- and stack area such that the master-client
      7 appears on the right and the stack-clients appear on the left.
      8 
      9 A variable and a toggle-function are introduced to achieve this
     10 behaviour which are set in the config.h:
     11 
     12 * The rmaster-variable can be set to 1 to make the right area the
     13 default master-area
     14 * The togglemaster-function can be used to swap the master- and
     15 stack-areas dynamically.
     16 ---
     17  config.def.h |  2 ++
     18  dwm.c        | 23 ++++++++++++++++++++---
     19  2 files changed, 22 insertions(+), 3 deletions(-)
     20 
     21 diff --git a/config.def.h b/config.def.h
     22 index 1c0b587..1d00282 100644
     23 --- a/config.def.h
     24 +++ b/config.def.h
     25 @@ -3,6 +3,7 @@
     26  /* appearance */
     27  static const unsigned int borderpx  = 1;        /* border pixel of windows */
     28  static const unsigned int snap      = 32;       /* snap pixel */
     29 +static const int rmaster            = 1;        /* 1 means master-area is initially on the right */
     30  static const int showbar            = 1;        /* 0 means no bar */
     31  static const int topbar             = 1;        /* 0 means bottom bar */
     32  static const char *fonts[]          = { "monospace:size=10" };
     33 @@ -78,6 +79,7 @@ static Key keys[] = {
     34  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     35  	{ MODKEY,                       XK_space,  setlayout,      {0} },
     36  	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
     37 +	{ MODKEY,                       XK_r,      togglermaster,  {0} },
     38  	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     39  	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     40  	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
     41 diff --git a/dwm.c b/dwm.c
     42 index 664c527..cc9a7f6 100644
     43 --- a/dwm.c
     44 +++ b/dwm.c
     45 @@ -122,6 +122,7 @@ struct Monitor {
     46  	unsigned int seltags;
     47  	unsigned int sellt;
     48  	unsigned int tagset[2];
     49 +	int rmaster;
     50  	int showbar;
     51  	int topbar;
     52  	Client *clients;
     53 @@ -212,6 +213,7 @@ static void tagmon(const Arg *arg);
     54  static void tile(Monitor *);
     55  static void togglebar(const Arg *arg);
     56  static void togglefloating(const Arg *arg);
     57 +static void togglermaster(const Arg *arg);
     58  static void toggletag(const Arg *arg);
     59  static void toggleview(const Arg *arg);
     60  static void unfocus(Client *c, int setfocus);
     61 @@ -637,6 +639,7 @@ createmon(void)
     62  	m->tagset[0] = m->tagset[1] = 1;
     63  	m->mfact = mfact;
     64  	m->nmaster = nmaster;
     65 +	m->rmaster = rmaster;
     66  	m->showbar = showbar;
     67  	m->topbar = topbar;
     68  	m->lt[0] = &layouts[0];
     69 @@ -1682,18 +1685,22 @@ tile(Monitor *m)
     70  		return;
     71  
     72  	if (n > m->nmaster)
     73 -		mw = m->nmaster ? m->ww * m->mfact : 0;
     74 +		mw = m->nmaster
     75 +			? m->ww * (m->rmaster ? 1.0 - m->mfact : m->mfact)
     76 +			: 0;
     77  	else
     78  		mw = m->ww;
     79  	for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
     80  		if (i < m->nmaster) {
     81  			h = (m->wh - my) / (MIN(n, m->nmaster) - i);
     82 -			resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
     83 +			resize(c, m->rmaster ? m->wx + m->ww - mw : m->wx,
     84 +			       m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
     85  			if (my + HEIGHT(c) < m->wh)
     86  				my += HEIGHT(c);
     87  		} else {
     88  			h = (m->wh - ty) / (n - i);
     89 -			resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
     90 +			resize(c, m->rmaster ? m->wx : m->wx + mw, m->wy + ty,
     91 +			       m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
     92  			if (ty + HEIGHT(c) < m->wh)
     93  				ty += HEIGHT(c);
     94  		}
     95 @@ -1722,6 +1729,16 @@ togglefloating(const Arg *arg)
     96  	arrange(selmon);
     97  }
     98  
     99 +void
    100 +togglermaster(const Arg *arg)
    101 +{
    102 +	selmon->rmaster = !selmon->rmaster;
    103 +	/* now mfact represents the left factor */
    104 +	selmon->mfact = 1.0 - selmon->mfact;
    105 +	if (selmon->lt[selmon->sellt]->arrange)
    106 +		arrange(selmon);
    107 +}
    108 +
    109  void
    110  toggletag(const Arg *arg)
    111  {
    112 -- 
    113 2.29.2
    114