Clean up code for the buttonpress function

This commit is contained in:
speediegq 2022-08-27 19:50:19 +02:00
parent 4d68e538dc
commit 44360a9cf7

View file

@ -931,81 +931,18 @@ buttonpress(XEvent *e)
selmon = m; selmon = m;
focus(NULL); focus(NULL);
} }
/* For !leftlayout */
if (!leftlayout) {
if (ev->window == selmon->barwin) {
i = x = occ = 0;
/* Bitmask of occupied tags */
unsigned int occ = 0;
for (c = m->clients; c; c = c->next)
occ |= c->tags;
do {
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue;
x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
} while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
selmon->mouseactivated = 1;
click = ClkTagBar;
arg.ui = 1 << i;
} else if (ev->x < x + blw)
click = ClkLtSymbol;
else if (ev->x > (selmon->ww - TEXTW(stext) + lrpad) - 2) {
x = selmon->ww - TEXTW(stext) + lrpad - 2;
click = ClkStatusText;
char *text = rawstext;
int i = -1;
char ch;
statuscmdn = 0;
while (text[++i]) {
if ((unsigned char)text[i] < ' ') {
ch = text[i];
text[i] = '\0';
x += TEXTW(text) - lrpad;
text[i] = ch;
text += i+1;
i = -1;
if (x >= ev->x) break;
statuscmdn = ch;
}
}
} else {
x += blw;
c = m->clients;
if (c) {
do {
if (!ISVISIBLE(c))
continue;
else
x += (1.0 / (double)m->bt) * m->btw;
} while (ev->x > x && (c = c->next));
click = ClkWinTitle;
arg.v = c;
}
}
} else if ((c = wintoclient(ev->window))) {
focus(c);
restack(selmon);
XAllowEvents(dpy, ReplayPointer, CurrentTime);
click = ClkClientWin;
}
} else {
if (ev->window == selmon->barwin) { if (ev->window == selmon->barwin) {
i = x = occ = 0; i = x = occ = 0;
/* Bitmask of occupied tags */ /* Bitmask of occupied tags */
for (c = m->clients; c; c = c->next) for (c = m->clients; c; c = c->next)
occ |= c->tags; occ |= c->tags;
x += blw;
if (ev->x < x) { if (leftlayout)
click = ClkLtSymbol; x += blw;
if (ev->x < x && leftlayout) {
click = ClkLtSymbol; // left layout
} else { } else {
do { do {
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue; continue;
x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]); x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
@ -1014,7 +951,9 @@ if (!leftlayout) {
selmon->mouseactivated = 1; selmon->mouseactivated = 1;
click = ClkTagBar; click = ClkTagBar;
arg.ui = 1 << i; arg.ui = 1 << i;
} else if (ev->x > selmon->ww - statusw + lrpad - 2) { } else if (ev->x < x + blw && !leftlayout) // right layout
click = ClkLtSymbol; // right layout
else if (ev->x > selmon->ww - statusw + lrpad - 2) {
x = selmon->ww - TEXTW(stext) + lrpad - 2; x = selmon->ww - TEXTW(stext) + lrpad - 2;
click = ClkStatusText; click = ClkStatusText;
char *text = rawstext; char *text = rawstext;
@ -1034,7 +973,9 @@ if (!leftlayout) {
} }
} }
} else { } else {
//x += blw; if (!leftlayout)
x += blw; // Left layout does not need this
c = m->clients; c = m->clients;
if (c) { if (c) {
@ -1042,7 +983,7 @@ if (!leftlayout) {
if (!ISVISIBLE(c)) if (!ISVISIBLE(c))
continue; continue;
else else
x += (1.0 / (double)m->bt) * m->btw - 2 * sp; x += (1.0 / (double)m->bt) * m->btw;
} while (ev->x > x && (c = c->next)); } while (ev->x > x && (c = c->next));
click = ClkWinTitle; click = ClkWinTitle;
@ -1050,13 +991,13 @@ if (!leftlayout) {
} }
} }
} }
} else if ((c = wintoclient(ev->window))) { } else if ((c = wintoclient(ev->window))) {
focus(c); focus(c);
restack(selmon); restack(selmon);
XAllowEvents(dpy, ReplayPointer, CurrentTime); XAllowEvents(dpy, ReplayPointer, CurrentTime);
click = ClkClientWin; click = ClkClientWin;
} }
}
for (i = 0; i < LENGTH(buttons); i++) for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button