2023-05-14 00:21:16 +02:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
void buttonpress_x11(XEvent *e) {
|
2023-05-08 23:00:45 +02:00
|
|
|
struct item *item;
|
|
|
|
XButtonPressedEvent *ev = &e->xbutton;
|
2023-06-23 03:38:21 +02:00
|
|
|
int x = 0, y = 0, h = sp.bh, w, item_num = 0;
|
2023-04-02 16:10:13 +02:00
|
|
|
unsigned int i, click;
|
2023-06-19 23:16:03 +02:00
|
|
|
int yp = 0;
|
2023-03-08 17:20:32 +01:00
|
|
|
|
2023-04-21 09:49:38 +02:00
|
|
|
// margin
|
2023-04-16 23:57:02 +02:00
|
|
|
x += menumarginh;
|
|
|
|
|
2023-06-23 17:27:57 +02:00
|
|
|
int larroww = 0;
|
|
|
|
int rarroww = 0;
|
|
|
|
int numberw = 0;
|
|
|
|
int modew = 0;
|
|
|
|
int capsw = 0;
|
|
|
|
|
|
|
|
if (!hidelarrow) larroww = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow);
|
|
|
|
if (!hiderarrow) rarroww = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
|
|
|
|
if (!hidematchcount) numberw = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers);
|
|
|
|
if (!hidemode) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext);
|
|
|
|
if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext);
|
2023-04-20 21:22:45 +02:00
|
|
|
|
2023-06-23 03:38:21 +02:00
|
|
|
if (!strcmp(tx.capstext, ""))
|
2023-06-23 17:27:57 +02:00
|
|
|
capsw = 0;
|
2023-06-11 19:32:02 +02:00
|
|
|
|
2023-06-19 23:16:03 +02:00
|
|
|
if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) {
|
|
|
|
yp = 1;
|
|
|
|
} else if (lines && ev->y < h + menumarginv && ev->y > menumarginv) {
|
|
|
|
yp = 1;
|
2023-06-19 23:26:23 +02:00
|
|
|
} else if (!lines) {
|
|
|
|
yp = 1;
|
2023-06-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
if (ev->window != win) return; // if incorrect or wrong window, return
|
2023-03-08 17:20:32 +01:00
|
|
|
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-04-21 17:59:10 +02:00
|
|
|
// check click position and override the value of click
|
2023-06-23 03:38:21 +02:00
|
|
|
if (yp && ev->x < x + sp.promptw + powerlineprompt ? sp.plw : 0) { // prompt
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickPrompt;
|
2023-06-23 17:27:57 +02:00
|
|
|
} else if (yp && (ev->x > sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsw) { // caps lock indicator
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickCaps;
|
2023-06-23 17:27:57 +02:00
|
|
|
} else if (yp && ev->x > sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickMode;
|
2023-06-23 17:27:57 +02:00
|
|
|
} else if (yp && ev->x > sp.mw - modew - numberw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickNumber;
|
2023-06-19 23:16:03 +02:00
|
|
|
} else if (yp && !hideinput) { // input
|
2023-06-23 03:38:21 +02:00
|
|
|
w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw;
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-06-23 03:38:21 +02:00
|
|
|
if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + sp.promptw +
|
2023-07-16 03:16:45 +02:00
|
|
|
((!previousitem || !currentitem->left) ? larroww : 0)) ||
|
2023-05-08 23:00:45 +02:00
|
|
|
(lines > 0 && ev->y >= y && ev->y <= y + h)) {
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickInput;
|
2023-04-02 16:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 17:20:32 +01:00
|
|
|
|
2023-06-19 23:16:03 +02:00
|
|
|
#if USEIMAGE
|
2023-07-03 18:48:38 +02:00
|
|
|
if (!hideimage && img.longestedge != 0 && imagetype) {
|
2023-06-24 04:20:51 +02:00
|
|
|
x += MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0);
|
2023-06-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-02 16:10:13 +02:00
|
|
|
// item click
|
2023-05-08 23:00:45 +02:00
|
|
|
if (lines > 0) {
|
2023-06-23 03:38:21 +02:00
|
|
|
w = sp.mw - x;
|
2023-06-19 23:16:03 +02:00
|
|
|
|
|
|
|
ev->y -= menumarginv;
|
|
|
|
|
2023-06-20 01:27:46 +02:00
|
|
|
if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) {
|
|
|
|
ev->y += h;
|
|
|
|
}
|
|
|
|
|
2023-07-19 17:50:50 +02:00
|
|
|
i = 0;
|
|
|
|
|
2023-07-16 03:16:45 +02:00
|
|
|
for (item = currentitem; item != nextitem; item = item->right) {
|
2023-05-08 23:00:45 +02:00
|
|
|
if (item_num++ == lines) {
|
|
|
|
item_num = 1;
|
|
|
|
x += w / columns;
|
|
|
|
y = 0;
|
|
|
|
}
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
y += h;
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-05-06 14:13:56 +02:00
|
|
|
// ClickSelItem, called function doesn't matter
|
2023-06-23 03:38:21 +02:00
|
|
|
if (ev->y >= y && ev->y <= (y + h) && ev->x >= x + (powerlineitems ? sp.plw : 0) && ev->x <= (x + w / columns) + (powerlineitems ? sp.plw : 0)) {
|
2023-07-19 17:50:50 +02:00
|
|
|
click = ClickItem;
|
|
|
|
sp.clickitemindex = i;
|
2023-07-03 23:06:33 +02:00
|
|
|
#if USEIMAGE
|
|
|
|
} else if (ev->y >= y && ev->y <= (y + h) && ev->x >= x + (powerlineitems ? sp.plw : 0) - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) && ev->x <= (x - MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0) + w / columns) + (powerlineitems ? sp.plw : 0)) {
|
|
|
|
click = ClickImage;
|
|
|
|
#endif
|
2023-05-08 23:00:45 +02:00
|
|
|
}
|
2023-07-19 17:50:50 +02:00
|
|
|
|
|
|
|
i++;
|
2023-05-08 23:00:45 +02:00
|
|
|
}
|
|
|
|
} else if (matches) { // a single line, meaning it could be arrows too, so we check that here
|
2023-06-23 03:38:21 +02:00
|
|
|
x += sp.inputw;
|
2023-06-23 17:27:57 +02:00
|
|
|
w = larroww;
|
2023-06-18 22:55:45 +02:00
|
|
|
|
2023-07-16 03:16:45 +02:00
|
|
|
if (previousitem && currentitem->left) {
|
2023-05-08 23:00:45 +02:00
|
|
|
if (ev->x >= x && ev->x <= x + w) {
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickLArrow;
|
2023-05-08 23:00:45 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-02 16:10:13 +02:00
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
// right arrow
|
2023-06-23 17:27:57 +02:00
|
|
|
w = rarroww;
|
2023-06-23 03:38:21 +02:00
|
|
|
x = sp.mw - w;
|
2023-07-16 03:16:45 +02:00
|
|
|
if (nextitem && ev->x >= x && ev->x <= x + w) {
|
2023-05-06 14:13:56 +02:00
|
|
|
click = ClickRArrow;
|
2023-05-08 23:00:45 +02:00
|
|
|
}
|
2023-04-02 16:10:13 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 17:59:10 +02:00
|
|
|
// go through mouse button array and run function
|
2023-04-25 16:42:15 +02:00
|
|
|
for (i = 0; i < LENGTH(buttons); i++) {
|
2023-06-23 03:38:21 +02:00
|
|
|
if (sp.ignoreglobalmouse) break;
|
2023-07-14 21:31:29 +02:00
|
|
|
if ((click == buttons[i].click || buttons[i].click == ClickNone) && buttons[i].func && buttons[i].button == ev->button)
|
2023-04-02 16:10:13 +02:00
|
|
|
buttons[i].func(&buttons[i].arg);
|
2023-04-25 16:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// go through mouse config array and run function
|
|
|
|
for (i = 0; i < LENGTH(cbuttons); i++) {
|
2023-06-23 03:38:21 +02:00
|
|
|
if (sp.ignoreconfmouse) break;
|
2023-07-14 21:31:29 +02:00
|
|
|
if ((click == cbuttons[i].click || cbuttons[i].click == ClickNone) && cbuttons[i].func && cbuttons[i].button == ev->button)
|
2023-04-25 16:42:15 +02:00
|
|
|
cbuttons[i].func(&cbuttons[i].arg);
|
|
|
|
}
|
2023-03-08 17:20:32 +01:00
|
|
|
}
|