sites

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

dwm-awesomebar-20191003-80e2a76.diff (8759B)


      1 From 80e2a7685d9ce745a0c6d8845f967484b8e3ed42 Mon Sep 17 00:00:00 2001
      2 From: Yegor Bayev <kodxpub@gmail.com>
      3 Date: Thu, 3 Oct 2019 00:10:28 +0300
      4 Subject: [PATCH] add awesomebar with fix
      5 
      6 ---
      7  config.def.h |   2 +
      8  dwm.c        | 128 ++++++++++++++++++++++++++++++++++++++++++++-------
      9  2 files changed, 114 insertions(+), 16 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 1c0b587..1e62218 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -16,6 +16,7 @@ static const char *colors[][3]      = {
     16  	/*               fg         bg         border   */
     17  	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
     18  	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
     19 +	[SchemeHid]  = { col_cyan,  col_gray1, col_cyan  },
     20  };
     21  
     22  /* tagging */
     23 @@ -102,6 +103,7 @@ static Button buttons[] = {
     24  	/* click                event mask      button          function        argument */
     25  	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     26  	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
     27 +	{ ClkWinTitle,          0,              Button1,        togglewin,      {0} },
     28  	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
     29  	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
     30  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     31 diff --git a/dwm.c b/dwm.c
     32 index 4465af1..151d50e 100644
     33 --- a/dwm.c
     34 +++ b/dwm.c
     35 @@ -50,6 +50,7 @@
     36  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
     37                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
     38  #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
     39 +#define HIDDEN(C)               ((getstate(C->win) == IconicState))
     40  #define LENGTH(X)               (sizeof X / sizeof X[0])
     41  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
     42  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
     43 @@ -59,7 +60,7 @@
     44  
     45  /* enums */
     46  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     47 -enum { SchemeNorm, SchemeSel }; /* color schemes */
     48 +enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */
     49  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     50         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     51         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     52 @@ -117,6 +118,8 @@ struct Monitor {
     53  	int nmaster;
     54  	int num;
     55  	int by;               /* bar geometry */
     56 +	int btw;              /* width of tasks portion of bar */
     57 +	int bt;               /* number of tasks */
     58  	int mx, my, mw, mh;   /* screen size */
     59  	int wx, wy, ww, wh;   /* window area  */
     60  	unsigned int seltags;
     61 @@ -174,6 +177,7 @@ static long getstate(Window w);
     62  static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
     63  static void grabbuttons(Client *c, int focused);
     64  static void grabkeys(void);
     65 +static void hide(Client *c);
     66  static void incnmaster(const Arg *arg);
     67  static void keypress(XEvent *e);
     68  static void killclient(const Arg *arg);
     69 @@ -203,6 +207,7 @@ static void setlayout(const Arg *arg);
     70  static void setmfact(const Arg *arg);
     71  static void setup(void);
     72  static void seturgent(Client *c, int urg);
     73 +static void show(Client *c);
     74  static void showhide(Client *c);
     75  static void sigchld(int unused);
     76  static void spawn(const Arg *arg);
     77 @@ -213,6 +218,7 @@ static void togglebar(const Arg *arg);
     78  static void togglefloating(const Arg *arg);
     79  static void toggletag(const Arg *arg);
     80  static void toggleview(const Arg *arg);
     81 +static void togglewin(const Arg *arg);
     82  static void unfocus(Client *c, int setfocus);
     83  static void unmanage(Client *c, int destroyed);
     84  static void unmapnotify(XEvent *e);
     85 @@ -439,10 +445,25 @@ buttonpress(XEvent *e)
     86  			arg.ui = 1 << i;
     87  		} else if (ev->x < x + blw)
     88  			click = ClkLtSymbol;
     89 -		else if (ev->x > selmon->ww - TEXTW(stext))
     90 +		/* 2px right padding */
     91 +		else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
     92  			click = ClkStatusText;
     93 -		else
     94 -			click = ClkWinTitle;
     95 +		else {
     96 +			x += blw;
     97 +			c = m->clients;
     98 +
     99 +			do {
    100 +				if (!ISVISIBLE(c))
    101 +					continue;
    102 +				else
    103 +					x += (1.0 / (double)m->bt) * m->btw;
    104 +			} while (ev->x > x && (c = c->next));
    105 +
    106 +			if (c) {
    107 +				click = ClkWinTitle;
    108 +				arg.v = c;
    109 +			}
    110 +		}
    111  	} else if ((c = wintoclient(ev->window))) {
    112  		focus(c);
    113  		restack(selmon);
    114 @@ -452,7 +473,7 @@ buttonpress(XEvent *e)
    115  	for (i = 0; i < LENGTH(buttons); i++)
    116  		if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
    117  		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
    118 -			buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
    119 +			buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
    120  }
    121  
    122  void
    123 @@ -695,7 +716,7 @@ dirtomon(int dir)
    124  void
    125  drawbar(Monitor *m)
    126  {
    127 -	int x, w, sw = 0;
    128 +	int x, w, sw = 0, n = 0, scm;
    129  	int boxs = drw->fonts->h / 9;
    130  	int boxw = drw->fonts->h / 6 + 2;
    131  	unsigned int i, occ = 0, urg = 0;
    132 @@ -709,6 +730,8 @@ drawbar(Monitor *m)
    133  	}
    134  
    135  	for (c = m->clients; c; c = c->next) {
    136 +		if (ISVISIBLE(c))
    137 +			n++;
    138  		occ |= c->tags;
    139  		if (c->isurgent)
    140  			urg |= c->tags;
    141 @@ -729,16 +752,37 @@ drawbar(Monitor *m)
    142  	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
    143  
    144  	if ((w = m->ww - sw - x) > bh) {
    145 -		if (m->sel) {
    146 -			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
    147 -			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
    148 -			if (m->sel->isfloating)
    149 -				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
    150 +		if (n > 0) {
    151 +			int remainder = w % n;
    152 +			int tabw = (1.0 / (double)n) * w + 1;
    153 +			for (c = m->clients; c; c = c->next) {
    154 +				if (!ISVISIBLE(c))
    155 +					continue;
    156 +				if (m->sel == c)
    157 +					scm = SchemeSel;
    158 +				else if (HIDDEN(c))
    159 +					scm = SchemeHid;
    160 +				else
    161 +					scm = SchemeNorm;
    162 +				drw_setscheme(drw, scheme[scm]);
    163 +
    164 +				if (remainder >= 0) {
    165 +					if (remainder == 0) {
    166 +						tabw--;
    167 +					}
    168 +					remainder--;
    169 +				}
    170 +				drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0);
    171 +				x += tabw;
    172 +			}
    173  		} else {
    174  			drw_setscheme(drw, scheme[SchemeNorm]);
    175  			drw_rect(drw, x, 0, w, bh, 1, 1);
    176  		}
    177  	}
    178 +
    179 +	m->bt = n;
    180 +	m->btw = w;
    181  	drw_map(drw, m->barwin, 0, 0, m->ww, bh);
    182  }
    183  
    184 @@ -783,8 +827,8 @@ expose(XEvent *e)
    185  void
    186  focus(Client *c)
    187  {
    188 -	if (!c || !ISVISIBLE(c))
    189 -		for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
    190 +	if (!c || !ISVISIBLE(c) || HIDDEN(c))
    191 +		for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
    192  	if (selmon->sel && selmon->sel != c)
    193  		unfocus(selmon->sel, 0);
    194  	if (c) {
    195 @@ -963,6 +1007,31 @@ grabkeys(void)
    196  	}
    197  }
    198  
    199 +void
    200 +hide(Client *c) {
    201 +	if (!c || HIDDEN(c))
    202 +		return;
    203 +
    204 +	Window w = c->win;
    205 +	static XWindowAttributes ra, ca;
    206 +
    207 +	// more or less taken directly from blackbox's hide() function
    208 +	XGrabServer(dpy);
    209 +	XGetWindowAttributes(dpy, root, &ra);
    210 +	XGetWindowAttributes(dpy, w, &ca);
    211 +	// prevent UnmapNotify events
    212 +	XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
    213 +	XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
    214 +	XUnmapWindow(dpy, w);
    215 +	setclientstate(c, IconicState);
    216 +	XSelectInput(dpy, root, ra.your_event_mask);
    217 +	XSelectInput(dpy, w, ca.your_event_mask);
    218 +	XUngrabServer(dpy);
    219 +
    220 +	focus(c->snext);
    221 +	arrange(c->mon);
    222 +}
    223 +
    224  void
    225  incnmaster(const Arg *arg)
    226  {
    227 @@ -1067,12 +1136,14 @@ manage(Window w, XWindowAttributes *wa)
    228  	XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
    229  		(unsigned char *) &(c->win), 1);
    230  	XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
    231 -	setclientstate(c, NormalState);
    232 +	if (!HIDDEN(c))
    233 +		setclientstate(c, NormalState);
    234  	if (c->mon == selmon)
    235  		unfocus(selmon->sel, 0);
    236  	c->mon->sel = c;
    237  	arrange(c->mon);
    238 -	XMapWindow(dpy, c->win);
    239 +	if (!HIDDEN(c))
    240 +		XMapWindow(dpy, c->win);
    241  	focus(NULL);
    242  }
    243  
    244 @@ -1195,7 +1266,7 @@ movemouse(const Arg *arg)
    245  Client *
    246  nexttiled(Client *c)
    247  {
    248 -	for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
    249 +	for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
    250  	return c;
    251  }
    252  
    253 @@ -1610,6 +1681,17 @@ seturgent(Client *c, int urg)
    254  	XFree(wmh);
    255  }
    256  
    257 +void
    258 +show(Client *c)
    259 +{
    260 +	if (!c || !HIDDEN(c))
    261 +		return;
    262 +
    263 +	XMapWindow(dpy, c->win);
    264 +	setclientstate(c, NormalState);
    265 +	arrange(c->mon);
    266 +}
    267 +
    268  void
    269  showhide(Client *c)
    270  {
    271 @@ -1746,6 +1828,20 @@ toggleview(const Arg *arg)
    272  	}
    273  }
    274  
    275 +void
    276 +togglewin(const Arg *arg)
    277 +{
    278 +	Client *c = (Client*)arg->v;
    279 +	if (c == selmon->sel)
    280 +		hide(c);
    281 +	else {
    282 +		if (HIDDEN(c))
    283 +			show(c);
    284 +		focus(c);
    285 +		restack(selmon);
    286 +	}
    287 +}
    288 +
    289  void
    290  unfocus(Client *c, int setfocus)
    291  {
    292 -- 
    293 2.20.1
    294