sites

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

dwm-alternativetags-6.2.diff (4052B)


      1 From b55c4bc2efa0331a6fb521d41169e8ddf8bc9b13 Mon Sep 17 00:00:00 2001
      2 From: Jack Bird <jack.bird@durham.ac.uk>
      3 Date: Sun, 29 Aug 2021 17:30:40 +0100
      4 Subject: [PATCH] Added momentary config option
      5 
      6 ---
      7  config.def.h |  3 +++
      8  dwm.c        | 35 +++++++++++++++++++++++++++++++++--
      9  2 files changed, 36 insertions(+), 2 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 1c0b587..4cfcef1 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -20,6 +20,8 @@ static const char *colors[][3]      = {
     16  
     17  /* tagging */
     18  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     19 +static const char *tagsalt[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     20 +static const int momentaryalttags = 0; /* 1 means alttags will show only when key is held down*/
     21  
     22  static const Rule rules[] = {
     23  	/* xprop(1):
     24 @@ -84,6 +86,7 @@ static Key keys[] = {
     25  	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
     26  	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
     27  	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
     28 +	{ MODKEY,                       XK_n,      togglealttag,   {0} },
     29  	TAGKEYS(                        XK_1,                      0)
     30  	TAGKEYS(                        XK_2,                      1)
     31  	TAGKEYS(                        XK_3,                      2)
     32 diff --git a/dwm.c b/dwm.c
     33 index 4465af1..1e6e6f3 100644
     34 --- a/dwm.c
     35 +++ b/dwm.c
     36 @@ -130,6 +130,7 @@ struct Monitor {
     37  	Monitor *next;
     38  	Window barwin;
     39  	const Layout *lt[2];
     40 +	unsigned int alttag;
     41  };
     42  
     43  typedef struct {
     44 @@ -176,6 +177,7 @@ static void grabbuttons(Client *c, int focused);
     45  static void grabkeys(void);
     46  static void incnmaster(const Arg *arg);
     47  static void keypress(XEvent *e);
     48 +static void keyrelease(XEvent *e);
     49  static void killclient(const Arg *arg);
     50  static void manage(Window w, XWindowAttributes *wa);
     51  static void mappingnotify(XEvent *e);
     52 @@ -209,6 +211,7 @@ static void spawn(const Arg *arg);
     53  static void tag(const Arg *arg);
     54  static void tagmon(const Arg *arg);
     55  static void tile(Monitor *);
     56 +static void togglealttag();
     57  static void togglebar(const Arg *arg);
     58  static void togglefloating(const Arg *arg);
     59  static void toggletag(const Arg *arg);
     60 @@ -253,6 +256,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
     61  	[Expose] = expose,
     62  	[FocusIn] = focusin,
     63  	[KeyPress] = keypress,
     64 +    [KeyRelease] = keyrelease,
     65  	[MappingNotify] = mappingnotify,
     66  	[MapRequest] = maprequest,
     67  	[MotionNotify] = motionnotify,
     68 @@ -695,7 +699,7 @@ dirtomon(int dir)
     69  void
     70  drawbar(Monitor *m)
     71  {
     72 -	int x, w, sw = 0;
     73 +	int x, w, wdelta, sw = 0;
     74  	int boxs = drw->fonts->h / 9;
     75  	int boxw = drw->fonts->h / 6 + 2;
     76  	unsigned int i, occ = 0, urg = 0;
     77 @@ -716,8 +720,9 @@ drawbar(Monitor *m)
     78  	x = 0;
     79  	for (i = 0; i < LENGTH(tags); i++) {
     80  		w = TEXTW(tags[i]);
     81 +		wdelta = selmon->alttag ? abs(TEXTW(tags[i]) - TEXTW(tagsalt[i])) / 2 : 0;
     82  		drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
     83 -		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
     84 +		drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), urg & 1 << i);
     85  		if (occ & 1 << i)
     86  			drw_rect(drw, x + boxs, boxs, boxw, boxw,
     87  				m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
     88 @@ -998,6 +1003,25 @@ keypress(XEvent *e)
     89  			keys[i].func(&(keys[i].arg));
     90  }
     91  
     92 +void
     93 +keyrelease(XEvent *e)
     94 +{
     95 +	unsigned int i;
     96 +	KeySym keysym;
     97 +	XKeyEvent *ev;
     98 +
     99 +	ev = &e->xkey;
    100 +	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    101 +
    102 +    for (i = 0; i < LENGTH(keys); i++)
    103 +        if (momentaryalttags
    104 +        && keys[i].func && keys[i].func == togglealttag
    105 +        && selmon->alttag
    106 +        && (keysym == keys[i].keysym
    107 +        || CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)))
    108 +            keys[i].func(&(keys[i].arg));
    109 +}
    110 +
    111  void
    112  killclient(const Arg *arg)
    113  {
    114 @@ -1696,6 +1720,13 @@ tile(Monitor *m)
    115  		}
    116  }
    117  
    118 +void
    119 +togglealttag()
    120 +{
    121 +	selmon->alttag = !selmon->alttag;
    122 +	drawbar(selmon);
    123 +}
    124 +
    125  void
    126  togglebar(const Arg *arg)
    127  {
    128 -- 
    129 2.33.0
    130