dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

bar_taggrid.c (3451B)


      1 int
      2 width_taggrid(Bar *bar, BarArg *a)
      3 {
      4 	return (a->h / 2) * (NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0)) + lrpad;
      5 }
      6 
      7 int
      8 draw_taggrid(Bar *bar, BarArg *a)
      9 {
     10 	unsigned int x, y, h, max_x = 0, columns, occ = 0;
     11 	int invert, i,j, k;
     12 	Client *c;
     13 
     14 	for (c = bar->mon->clients; c; c = c->next)
     15 		occ |= c->tags;
     16 
     17 	max_x = x = a->x + lrpad / 2;
     18 	h = a->h / tagrows - 1;
     19 	y = a->y;
     20 	columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
     21 
     22 	/* Firstly we will fill the borders of squares */
     23 	XSetForeground(drw->dpy, drw->gc, scheme[SchemeTagsNorm][ColBg].pixel);
     24 	XFillRectangle(dpy, drw->drawable, drw->gc, x, y, h*columns + 1, a->h);
     25 
     26 	/* We will draw NUMTAGS squares in tagraws raws. */
     27 	for (j = 0, i = 0; j < tagrows; j++) {
     28 		x = a->x + lrpad / 2;
     29 		for (k = 0; k < columns; k++, i++) {
     30 			if (i < NUMTAGS) {
     31 				invert = bar->mon->tagset[bar->mon->seltags] & 1 << i ? 0 : 1;
     32 
     33 				/* Select active color for current square */
     34 				XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeTagsSel][ColBg].pixel :
     35 									scheme[SchemeTagsNorm][ColFg].pixel);
     36 				XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h-1);
     37 
     38 				/* Mark square if tag has client */
     39 				if (occ & 1 << i) {
     40 					XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeTagsSel][ColFg].pixel :
     41 									scheme[SchemeTagsNorm][ColBg].pixel);
     42 					XFillRectangle(dpy, drw->drawable, drw->gc, x + 1, y + 1,
     43 								   h / 2, h / 2);
     44 				}
     45 			} else {
     46 				XSetForeground(drw->dpy, drw->gc, scheme[SchemeTagsNorm][ColBg].pixel);
     47 				XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h);
     48 			}
     49 			x += h;
     50 			if (x > max_x) {
     51 				max_x = x;
     52 			}
     53 		}
     54 		y += h;
     55 	}
     56 	return 1;
     57 }
     58 
     59 int
     60 click_taggrid(Bar *bar, Arg *arg, BarArg *a)
     61 {
     62 	unsigned int i, h, columns;
     63 
     64 	h = a->h / tagrows - 1;
     65 	columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
     66 	i = (a->x - lrpad / 2) / h + columns * (a->y / h);
     67 	if (i >= NUMTAGS) {
     68 		i = NUMTAGS - 1;
     69 	}
     70 	arg->ui = 1 << i;
     71 	return ClkTagBar;
     72 }
     73 
     74 void
     75 switchtag(const Arg *arg)
     76 {
     77 	unsigned int columns;
     78 	unsigned int new_tagset = 0;
     79 	unsigned int pos, i;
     80 	int col, row;
     81 	Arg new_arg;
     82 
     83 	columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
     84 
     85 	for (i = 0; i < NUMTAGS; ++i) {
     86 		if (!(selmon->tagset[selmon->seltags] & 1 << i)) {
     87 			continue;
     88 		}
     89 		pos = i;
     90 		row = pos / columns;
     91 		col = pos % columns;
     92 		if (arg->ui & SWITCHTAG_UP) {     /* UP */
     93 			row --;
     94 			if (row < 0) {
     95 				row = tagrows - 1;
     96 			}
     97 			do {
     98 				pos = row * columns + col;
     99 				row --;
    100 			} while (pos >= NUMTAGS);
    101 		}
    102 		if (arg->ui & SWITCHTAG_DOWN) {     /* DOWN */
    103 			row ++;
    104 			if (row >= tagrows) {
    105 				row = 0;
    106 			}
    107 			pos = row * columns + col;
    108 			if (pos >= NUMTAGS) {
    109 				row = 0;
    110 			}
    111 			pos = row * columns + col;
    112 		}
    113 		if (arg->ui & SWITCHTAG_LEFT) {     /* LEFT */
    114 			col --;
    115 			if (col < 0) {
    116 				col = columns - 1;
    117 			}
    118 			do {
    119 				pos = row * columns + col;
    120 				col --;
    121 			} while (pos >= NUMTAGS);
    122 		}
    123 		if (arg->ui & SWITCHTAG_RIGHT) {     /* RIGHT */
    124 			col ++;
    125 			if (col >= columns) {
    126 				col = 0;
    127 			}
    128 			pos = row * columns + col;
    129 			if (pos >= NUMTAGS) {
    130 				col = 0;
    131 				pos = row * columns + col;
    132 			}
    133 		}
    134 		new_tagset |= 1 << pos;
    135 	}
    136 	new_arg.ui = new_tagset;
    137 	if (arg->ui & SWITCHTAG_TOGGLETAG) {
    138 		toggletag(&new_arg);
    139 	}
    140 	if (arg->ui & SWITCHTAG_TAG) {
    141 		tag(&new_arg);
    142 	}
    143 	if (arg->ui & SWITCHTAG_VIEW) {
    144 		view (&new_arg);
    145 	}
    146 	if (arg->ui & SWITCHTAG_TOGGLEVIEW) {
    147 		toggleview (&new_arg);
    148 	}
    149 }
    150