sites

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

dwm-awesomebar-6.2.diff (8274B)


      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..be9582d 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 +			do {
     90 +				if (!ISVISIBLE(c))
     91 +					continue;
     92 +				else
     93 +					x += (1.0 / (double)m->bt) * m->btw;
     94 +			} while (ev->x > x && (c = c->next));
     95 +
     96 +			if (c) {
     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,28 @@ 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 +			for (c = m->clients; c; c = c->next) {
    142 +				if (!ISVISIBLE(c))
    143 +					continue;
    144 +				if (m->sel == c)
    145 +					scm = SchemeSel;
    146 +				else if (HIDDEN(c))
    147 +					scm = SchemeHid;
    148 +				else
    149 +					scm = SchemeNorm;
    150 +				drw_setscheme(drw, scheme[scm]);
    151 +				drw_text(drw, x, 0, (1.0 / (double)n) * w, bh, lrpad / 2, c->name, 0);
    152 +				x += (1.0 / (double)n) * w;
    153 +			}
    154  		} else {
    155  			drw_setscheme(drw, scheme[SchemeNorm]);
    156  			drw_rect(drw, x, 0, w, bh, 1, 1);
    157  		}
    158  	}
    159 +
    160 +	m->bt = n;
    161 +	m->btw = w;
    162  	drw_map(drw, m->barwin, 0, 0, m->ww, bh);
    163  }
    164  
    165 @@ -783,8 +818,8 @@ expose(XEvent *e)
    166  void
    167  focus(Client *c)
    168  {
    169 -	if (!c || !ISVISIBLE(c))
    170 -		for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
    171 +	if (!c || !ISVISIBLE(c) || HIDDEN(c))
    172 +		for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext);
    173  	if (selmon->sel && selmon->sel != c)
    174  		unfocus(selmon->sel, 0);
    175  	if (c) {
    176 @@ -963,6 +998,31 @@ grabkeys(void)
    177  	}
    178  }
    179  
    180 +void
    181 +hide(Client *c) {
    182 +	if (!c || HIDDEN(c))
    183 +		return;
    184 +
    185 +	Window w = c->win;
    186 +	static XWindowAttributes ra, ca;
    187 +
    188 +	// more or less taken directly from blackbox's hide() function
    189 +	XGrabServer(dpy);
    190 +	XGetWindowAttributes(dpy, root, &ra);
    191 +	XGetWindowAttributes(dpy, w, &ca);
    192 +	// prevent UnmapNotify events
    193 +	XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
    194 +	XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
    195 +	XUnmapWindow(dpy, w);
    196 +	setclientstate(c, IconicState);
    197 +	XSelectInput(dpy, root, ra.your_event_mask);
    198 +	XSelectInput(dpy, w, ca.your_event_mask);
    199 +	XUngrabServer(dpy);
    200 +
    201 +	focus(c->snext);
    202 +	arrange(c->mon);
    203 +}
    204 +
    205  void
    206  incnmaster(const Arg *arg)
    207  {
    208 @@ -1067,12 +1127,14 @@ manage(Window w, XWindowAttributes *wa)
    209  	XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
    210  		(unsigned char *) &(c->win), 1);
    211  	XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
    212 -	setclientstate(c, NormalState);
    213 +  if (!HIDDEN(c))
    214 +    setclientstate(c, NormalState);
    215  	if (c->mon == selmon)
    216  		unfocus(selmon->sel, 0);
    217  	c->mon->sel = c;
    218  	arrange(c->mon);
    219 -	XMapWindow(dpy, c->win);
    220 +  if (!HIDDEN(c))
    221 +    XMapWindow(dpy, c->win);
    222  	focus(NULL);
    223  }
    224  
    225 @@ -1195,7 +1257,7 @@ movemouse(const Arg *arg)
    226  Client *
    227  nexttiled(Client *c)
    228  {
    229 -	for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
    230 +	for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next);
    231  	return c;
    232  }
    233  
    234 @@ -1610,6 +1672,17 @@ seturgent(Client *c, int urg)
    235  	XFree(wmh);
    236  }
    237  
    238 +void
    239 +show(Client *c)
    240 +{
    241 +	if (!c || !HIDDEN(c))
    242 +		return;
    243 +
    244 +	XMapWindow(dpy, c->win);
    245 +	setclientstate(c, NormalState);
    246 +	arrange(c->mon);
    247 +}
    248 +
    249  void
    250  showhide(Client *c)
    251  {
    252 @@ -1746,6 +1819,20 @@ toggleview(const Arg *arg)
    253  	}
    254  }
    255  
    256 +void
    257 +togglewin(const Arg *arg)
    258 +{
    259 +	Client *c = (Client*)arg->v;
    260 +	if (c == selmon->sel)
    261 +		hide(c);
    262 +	else {
    263 +		if (HIDDEN(c))
    264 +			show(c);
    265 +		focus(c);
    266 +		restack(selmon);
    267 +	}
    268 +}
    269 +
    270  void
    271  unfocus(Client *c, int setfocus)
    272  {