2020-07-15 06:57:30 +00:00
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
width_taggrid(Bar *bar, BarArg *a)
|
2020-07-15 06:57:30 +00:00
|
|
|
{
|
2020-09-09 15:24:02 +00:00
|
|
|
return (a->h / 2) * (NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0)) + lrpad;
|
2020-07-15 06:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
draw_taggrid(Bar *bar, BarArg *a)
|
2020-07-15 06:57:30 +00:00
|
|
|
{
|
2020-07-18 11:03:30 +00:00
|
|
|
unsigned int x, y, h, max_x = 0, columns, occ = 0;
|
2020-07-15 15:14:14 +00:00
|
|
|
int invert, i,j, k;
|
|
|
|
Client *c;
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
for (c = bar->mon->clients; c; c = c->next)
|
2020-07-15 06:57:30 +00:00
|
|
|
occ |= c->tags;
|
|
|
|
|
2020-07-18 11:03:30 +00:00
|
|
|
max_x = x = a->x + lrpad / 2;
|
2020-09-09 15:24:02 +00:00
|
|
|
h = a->h / tagrows - 1;
|
|
|
|
y = a->y;
|
2020-08-25 14:27:14 +00:00
|
|
|
columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-07-15 15:14:14 +00:00
|
|
|
/* Firstly we will fill the borders of squares */
|
2020-07-18 11:03:30 +00:00
|
|
|
XSetForeground(drw->dpy, drw->gc, scheme[SchemeTagsNorm][ColBg].pixel);
|
2020-09-09 15:24:02 +00:00
|
|
|
XFillRectangle(dpy, drw->drawable, drw->gc, x, y, h*columns + 1, a->h);
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-08-25 14:27:14 +00:00
|
|
|
/* We will draw NUMTAGS squares in tagraws raws. */
|
2020-07-15 15:14:14 +00:00
|
|
|
for (j = 0, i = 0; j < tagrows; j++) {
|
2020-07-18 11:03:30 +00:00
|
|
|
x = a->x + lrpad / 2;
|
2020-07-15 15:14:14 +00:00
|
|
|
for (k = 0; k < columns; k++, i++) {
|
2020-08-25 14:27:14 +00:00
|
|
|
if (i < NUMTAGS) {
|
2020-07-18 11:03:30 +00:00
|
|
|
invert = bar->mon->tagset[bar->mon->seltags] & 1 << i ? 0 : 1;
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-07-15 15:14:14 +00:00
|
|
|
/* Select active color for current square */
|
2020-07-18 11:03:30 +00:00
|
|
|
XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeTagsSel][ColBg].pixel :
|
|
|
|
scheme[SchemeTagsNorm][ColFg].pixel);
|
2020-07-15 15:14:14 +00:00
|
|
|
XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h-1);
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-07-15 15:14:14 +00:00
|
|
|
/* Mark square if tag has client */
|
|
|
|
if (occ & 1 << i) {
|
2020-07-18 11:03:30 +00:00
|
|
|
XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeTagsSel][ColFg].pixel :
|
|
|
|
scheme[SchemeTagsNorm][ColBg].pixel);
|
2020-07-15 15:14:14 +00:00
|
|
|
XFillRectangle(dpy, drw->drawable, drw->gc, x + 1, y + 1,
|
|
|
|
h / 2, h / 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XSetForeground(drw->dpy, drw->gc, scheme[SchemeTagsNorm][ColBg].pixel);
|
|
|
|
XFillRectangle(dpy, drw->drawable, drw->gc, x+1, y+1, h-1, h);
|
|
|
|
}
|
|
|
|
x += h;
|
|
|
|
if (x > max_x) {
|
|
|
|
max_x = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
y += h;
|
2020-07-15 06:57:30 +00:00
|
|
|
}
|
2020-08-22 06:43:07 +00:00
|
|
|
return 1;
|
2020-07-15 06:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-09-09 15:24:02 +00:00
|
|
|
click_taggrid(Bar *bar, Arg *arg, BarArg *a)
|
2020-07-15 06:57:30 +00:00
|
|
|
{
|
2020-09-09 15:24:02 +00:00
|
|
|
unsigned int i, h, columns;
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-09-09 15:24:02 +00:00
|
|
|
h = a->h / tagrows - 1;
|
2020-08-25 14:27:14 +00:00
|
|
|
columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
|
2020-09-09 15:24:02 +00:00
|
|
|
i = (a->x - lrpad / 2) / h + columns * (a->y / h);
|
2020-08-25 14:27:14 +00:00
|
|
|
if (i >= NUMTAGS) {
|
|
|
|
i = NUMTAGS - 1;
|
2020-07-15 06:57:30 +00:00
|
|
|
}
|
|
|
|
arg->ui = 1 << i;
|
|
|
|
return ClkTagBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
switchtag(const Arg *arg)
|
|
|
|
{
|
2020-07-15 15:14:14 +00:00
|
|
|
unsigned int columns;
|
|
|
|
unsigned int new_tagset = 0;
|
|
|
|
unsigned int pos, i;
|
|
|
|
int col, row;
|
|
|
|
Arg new_arg;
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-08-25 14:27:14 +00:00
|
|
|
columns = NUMTAGS / tagrows + ((NUMTAGS % tagrows > 0) ? 1 : 0);
|
2020-07-15 06:57:30 +00:00
|
|
|
|
2020-08-25 14:27:14 +00:00
|
|
|
for (i = 0; i < NUMTAGS; ++i) {
|
2020-07-15 15:14:14 +00:00
|
|
|
if (!(selmon->tagset[selmon->seltags] & 1 << i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pos = i;
|
|
|
|
row = pos / columns;
|
|
|
|
col = pos % columns;
|
|
|
|
if (arg->ui & SWITCHTAG_UP) { /* UP */
|
|
|
|
row --;
|
|
|
|
if (row < 0) {
|
|
|
|
row = tagrows - 1;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
pos = row * columns + col;
|
|
|
|
row --;
|
2020-08-25 14:27:14 +00:00
|
|
|
} while (pos >= NUMTAGS);
|
2020-07-15 15:14:14 +00:00
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_DOWN) { /* DOWN */
|
|
|
|
row ++;
|
|
|
|
if (row >= tagrows) {
|
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
pos = row * columns + col;
|
2020-08-25 14:27:14 +00:00
|
|
|
if (pos >= NUMTAGS) {
|
2020-07-15 15:14:14 +00:00
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
pos = row * columns + col;
|
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_LEFT) { /* LEFT */
|
|
|
|
col --;
|
|
|
|
if (col < 0) {
|
|
|
|
col = columns - 1;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
pos = row * columns + col;
|
|
|
|
col --;
|
2020-08-25 14:27:14 +00:00
|
|
|
} while (pos >= NUMTAGS);
|
2020-07-15 15:14:14 +00:00
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_RIGHT) { /* RIGHT */
|
|
|
|
col ++;
|
|
|
|
if (col >= columns) {
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
pos = row * columns + col;
|
2020-08-25 14:27:14 +00:00
|
|
|
if (pos >= NUMTAGS) {
|
2020-07-15 15:14:14 +00:00
|
|
|
col = 0;
|
|
|
|
pos = row * columns + col;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_tagset |= 1 << pos;
|
|
|
|
}
|
|
|
|
new_arg.ui = new_tagset;
|
|
|
|
if (arg->ui & SWITCHTAG_TOGGLETAG) {
|
|
|
|
toggletag(&new_arg);
|
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_TAG) {
|
|
|
|
tag(&new_arg);
|
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_VIEW) {
|
|
|
|
view (&new_arg);
|
|
|
|
}
|
|
|
|
if (arg->ui & SWITCHTAG_TOGGLEVIEW) {
|
|
|
|
toggleview (&new_arg);
|
|
|
|
}
|
2020-07-15 06:57:30 +00:00
|
|
|
}
|