sites

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

dwm-awesomebar-20200829-6.2.diff (8731B)


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