2023-05-14 00:21:16 +02:00
|
|
|
|
/* See LICENSE file for copyright and license details. */
|
2023-05-10 08:16:22 +02:00
|
|
|
|
void drawhighlights(struct item *item, int x, int y, int w, int p, const char *ittext) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
int i, indent;
|
|
|
|
|
char *highlight;
|
|
|
|
|
char c;
|
2023-03-08 19:20:18 +01:00
|
|
|
|
|
2023-03-29 21:07:23 +02:00
|
|
|
|
// limitation in order to prevent highlighting from drawing when the text isn't visible
|
2023-03-24 03:14:24 +01:00
|
|
|
|
if (columns > 5 && lines > 1) return;
|
2023-03-21 22:24:50 +01:00
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
char *itemtext = strdup(ittext);
|
2023-03-08 19:20:18 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (!(strlen(itemtext) && strlen(text))) return;
|
2023-03-16 11:58:38 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
for (i = 0, highlight = itemtext; *highlight && text[i];) {
|
2023-03-16 17:22:14 +01:00
|
|
|
|
if (((fuzzy && !fstrncmp(&(*highlight), &text[i], 1)) || (!fuzzy && *highlight == text[i]))) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
c = *highlight;
|
|
|
|
|
*highlight = '\0';
|
|
|
|
|
indent = TEXTW(itemtext) - lrpad;
|
|
|
|
|
*highlight = c;
|
|
|
|
|
|
|
|
|
|
// highlight character
|
|
|
|
|
c = highlight[1];
|
|
|
|
|
highlight[1] = '\0';
|
|
|
|
|
drw_text(
|
|
|
|
|
drw,
|
|
|
|
|
x + indent + (p),
|
|
|
|
|
y,
|
|
|
|
|
MIN(w - indent - lrpad, TEXTW(highlight) - lrpad),
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bh, 0, highlight, 0, pango_highlight ? True : False,
|
|
|
|
|
item == sel ? col_hlselfg : col_hlnormfg,
|
|
|
|
|
item == sel ? col_hlselbg : col_hlnormbg,
|
|
|
|
|
item == sel ? alpha_hlselfg : alpha_hlnormfg,
|
|
|
|
|
item == sel ? alpha_hlselbg : alpha_hlnormbg);
|
2023-05-08 23:00:45 +02:00
|
|
|
|
highlight[1] = c;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
highlight++;
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawitemtext(struct item *item, int x, int y, int w) {
|
2023-03-29 21:07:23 +02:00
|
|
|
|
char buffer[MAXITEMLENGTH]; // buffer containing item text
|
|
|
|
|
int leftpadding = lrpad / 2; // padding
|
|
|
|
|
int wr, rd; // character
|
2023-05-08 23:00:45 +02:00
|
|
|
|
int fg = 7; // foreground
|
|
|
|
|
int bg = 0; // background
|
2023-03-29 21:07:23 +02:00
|
|
|
|
int bgfg = 0; // both
|
|
|
|
|
int ignore = 0; // ignore colors
|
2023-04-30 23:45:58 +02:00
|
|
|
|
int selitem = 0;
|
|
|
|
|
int priitem = 0;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
char *bgcol;
|
|
|
|
|
char *fgcol;
|
|
|
|
|
int bga;
|
|
|
|
|
int fga;
|
2023-03-29 21:07:23 +02:00
|
|
|
|
|
|
|
|
|
// memcpy the correct scheme
|
2023-03-02 11:40:52 +01:00
|
|
|
|
if (item == sel) {
|
2023-04-30 23:45:58 +02:00
|
|
|
|
selitem = 1;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemselbg;
|
|
|
|
|
fgcol = col_itemselfg;
|
|
|
|
|
bga = alpha_itemselbg;
|
|
|
|
|
fga = alpha_itemselfg;
|
2023-03-09 10:10:29 +01:00
|
|
|
|
|
2023-04-30 23:45:58 +02:00
|
|
|
|
if (item->hp) {
|
|
|
|
|
priitem = 1;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemselpribg;
|
|
|
|
|
fgcol = col_itemselprifg;
|
|
|
|
|
|
|
|
|
|
fga = alpha_itemselprifg;
|
|
|
|
|
bga = alpha_itemselpribg;
|
2023-04-30 23:45:58 +02:00
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
} else {
|
2023-05-13 16:07:29 +02:00
|
|
|
|
if (itemn) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemnormbg2;
|
|
|
|
|
fgcol = col_itemnormfg2;
|
|
|
|
|
fga = alpha_itemnormfg2;
|
|
|
|
|
bga = alpha_itemnormbg2;
|
2023-05-13 16:07:29 +02:00
|
|
|
|
} else {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemnormbg;
|
|
|
|
|
fgcol = col_itemnormfg;
|
|
|
|
|
fga = alpha_itemnormfg;
|
|
|
|
|
bga = alpha_itemnormbg;
|
2023-05-13 16:07:29 +02:00
|
|
|
|
}
|
2023-03-09 10:10:29 +01:00
|
|
|
|
|
2023-04-30 23:45:58 +02:00
|
|
|
|
if (item->hp) {
|
|
|
|
|
priitem = 1;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemnormpribg;
|
|
|
|
|
fgcol = col_itemnormprifg;
|
|
|
|
|
fga = alpha_itemnormprifg;
|
|
|
|
|
bga = alpha_itemnormpribg;
|
2023-04-30 23:45:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 18:54:26 +02:00
|
|
|
|
if (is_selected(item->index)) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemmarkedbg;
|
|
|
|
|
fgcol = col_itemmarkedfg;
|
|
|
|
|
fga = alpha_itemmarkedfg;
|
|
|
|
|
bga = alpha_itemmarkedbg;
|
2023-05-16 18:54:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 23:45:58 +02:00
|
|
|
|
// apply extra padding
|
|
|
|
|
if ((selitem && !priitem) && lines) {
|
|
|
|
|
leftpadding += selitempadding;
|
|
|
|
|
} else if (priitem && lines) {
|
|
|
|
|
leftpadding += priitempadding;
|
|
|
|
|
} else if (lines) {
|
|
|
|
|
leftpadding += normitempadding;
|
2023-03-02 11:40:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 15:10:57 +02:00
|
|
|
|
// don't color
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (!coloritems) {
|
|
|
|
|
bgcol = itemn ? col_itemnormbg2 : col_itemnormbg;
|
|
|
|
|
fgcol = itemn ? col_itemnormfg2 : col_itemnormfg;
|
|
|
|
|
bga = itemn ? alpha_itemnormbg2 : alpha_itemnormbg;
|
|
|
|
|
fga = itemn ? alpha_itemnormfg2 : alpha_itemnormfg;
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-16 16:54:36 +01:00
|
|
|
|
// parse item text
|
2023-05-08 23:00:45 +02:00
|
|
|
|
for (wr = 0, rd = 0; item->text[rd]; rd++) {
|
|
|
|
|
if (item->text[rd] == '' && item->text[rd + 1] == '[') {
|
|
|
|
|
size_t alen = strspn(item->text + rd + 2, "0123456789;");
|
|
|
|
|
if (item->text[rd + alen + 2] == 'm' && sgr) { // last character in sequence is always 'm'
|
|
|
|
|
buffer[wr] = '\0';
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-04-07 03:35:36 +02:00
|
|
|
|
if (!lines) {
|
|
|
|
|
w -= item->text[rd + alen];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 19:59:36 +01:00
|
|
|
|
apply_fribidi(buffer);
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, MIN(w, TEXTW(buffer) - lrpad) + leftpadding, bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga);
|
2023-05-10 08:16:22 +02:00
|
|
|
|
drawhighlights(item, x, y, MIN(w, TEXTW(buffer) - lrpad) + leftpadding, leftpadding, isrtl ? fribidi_text : buffer);
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-29 21:07:23 +02:00
|
|
|
|
// position and width
|
2023-05-08 23:00:45 +02:00
|
|
|
|
x += MIN(w, TEXTW(buffer) - lrpad) + leftpadding;
|
2023-03-29 21:07:23 +02:00
|
|
|
|
w -= MIN(w, TEXTW(buffer) - lrpad) + leftpadding;
|
2023-03-29 20:23:49 +02:00
|
|
|
|
|
2023-03-29 21:07:23 +02:00
|
|
|
|
// no highlighting if colored text
|
|
|
|
|
leftpadding = 0;
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
char *character = item->text + rd + 1; // current character
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
// parse hex colors, m is always the last character
|
2023-05-08 23:00:45 +02:00
|
|
|
|
while (*character != 'm') {
|
|
|
|
|
unsigned nextchar = strtoul(character + 1, &character, 10);
|
2023-03-04 02:07:06 +01:00
|
|
|
|
if (ignore)
|
2023-05-08 23:00:45 +02:00
|
|
|
|
continue;
|
|
|
|
|
if (bgfg) {
|
|
|
|
|
if (bgfg < 4 && nextchar == 5) {
|
|
|
|
|
bgfg <<= 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (bgfg == 4) {
|
|
|
|
|
fgcol = txtcols[fg = nextchar];
|
|
|
|
|
} else if (bgfg == 6) {
|
|
|
|
|
bgcol = txtcols[bg = nextchar];
|
|
|
|
|
}
|
2023-05-08 23:00:45 +02:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
ignore = 1;
|
2023-05-08 23:00:45 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nextchar == 1) {
|
|
|
|
|
fg |= 8;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
fgcol = txtcols[fg];
|
2023-05-08 23:00:45 +02:00
|
|
|
|
} else if (nextchar == 22) {
|
|
|
|
|
fg &= ~8;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
fgcol = txtcols[fg];
|
2023-04-29 22:53:00 +02:00
|
|
|
|
} else if (nextchar == 38) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
bgfg = 2;
|
|
|
|
|
} else if (nextchar >= 30 && nextchar <= 37) {
|
|
|
|
|
fg = nextchar % 10 | (fg & 8);
|
2023-06-02 18:37:51 +02:00
|
|
|
|
fgcol = txtcols[fg];
|
2023-05-08 23:00:45 +02:00
|
|
|
|
} else if (nextchar >= 40 && nextchar <= 47) {
|
|
|
|
|
bg = nextchar % 10;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = txtcols[bg];
|
2023-05-08 23:00:45 +02:00
|
|
|
|
} else if (nextchar == 48) {
|
2023-03-02 11:40:52 +01:00
|
|
|
|
bgfg = 3;
|
2023-04-02 17:45:56 +02:00
|
|
|
|
} else if (nextchar == 0) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
// memcpy the correct scheme
|
2023-04-02 17:45:56 +02:00
|
|
|
|
if (item == sel) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
selitem = 1;
|
|
|
|
|
bgcol = col_itemselbg;
|
|
|
|
|
fgcol = col_itemselfg;
|
|
|
|
|
bga = alpha_itemselbg;
|
|
|
|
|
fga = alpha_itemselfg;
|
|
|
|
|
|
|
|
|
|
if (item->hp) {
|
|
|
|
|
priitem = 1;
|
|
|
|
|
bgcol = col_itemselpribg;
|
|
|
|
|
fgcol = col_itemselprifg;
|
|
|
|
|
|
|
|
|
|
fga = alpha_itemselprifg;
|
|
|
|
|
bga = alpha_itemselpribg;
|
|
|
|
|
}
|
2023-04-02 17:45:56 +02:00
|
|
|
|
} else {
|
2023-05-13 16:07:29 +02:00
|
|
|
|
if (itemn) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemnormbg2;
|
|
|
|
|
fgcol = col_itemnormfg2;
|
|
|
|
|
fga = alpha_itemnormfg2;
|
|
|
|
|
bga = alpha_itemnormbg2;
|
2023-05-13 16:07:29 +02:00
|
|
|
|
} else {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemnormbg;
|
|
|
|
|
fgcol = col_itemnormfg;
|
|
|
|
|
fga = alpha_itemnormfg;
|
|
|
|
|
bga = alpha_itemnormbg;
|
2023-05-13 16:07:29 +02:00
|
|
|
|
}
|
2023-04-02 17:45:56 +02:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (item->hp) {
|
|
|
|
|
priitem = 1;
|
|
|
|
|
bgcol = col_itemnormpribg;
|
|
|
|
|
fgcol = col_itemnormprifg;
|
|
|
|
|
fga = alpha_itemnormprifg;
|
|
|
|
|
bga = alpha_itemnormpribg;
|
|
|
|
|
}
|
2023-04-02 17:45:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 20:03:52 +02:00
|
|
|
|
if (is_selected(item->index)) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
bgcol = col_itemmarkedbg;
|
|
|
|
|
fgcol = col_itemmarkedfg;
|
|
|
|
|
fga = alpha_itemmarkedfg;
|
|
|
|
|
bga = alpha_itemmarkedbg;
|
2023-05-16 20:03:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-02 17:45:56 +02:00
|
|
|
|
// don't color
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (!coloritems) {
|
|
|
|
|
bgcol = itemn ? col_itemnormbg2 : col_itemnormbg;
|
|
|
|
|
fgcol = itemn ? col_itemnormfg2 : col_itemnormfg;
|
|
|
|
|
bga = itemn ? alpha_itemnormbg2 : alpha_itemnormbg;
|
|
|
|
|
fga = itemn ? alpha_itemnormfg2 : alpha_itemnormfg;
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
}
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
rd += alen + 2;
|
|
|
|
|
wr = 0;
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
buffer[wr++] = item->text[rd];
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
buffer[wr] = '\0';
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-16 10:09:51 +01:00
|
|
|
|
// now draw any non-colored text
|
2023-03-02 11:40:52 +01:00
|
|
|
|
apply_fribidi(buffer);
|
2023-06-02 18:37:51 +02:00
|
|
|
|
int r = drw_text(drw, x, y, w, bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga);
|
2023-05-10 08:16:22 +02:00
|
|
|
|
if (!hidehighlight) drawhighlights(item, x, y, w, leftpadding, buffer);
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-29 21:07:23 +02:00
|
|
|
|
// copy current buffer to item->clntext instead of item->text, this way SGR sequences aren't drawn
|
2023-03-24 03:48:56 +01:00
|
|
|
|
item->clntext = malloc(sizeof(buffer));
|
|
|
|
|
memcpy(item->clntext, buffer, sizeof(buffer));
|
|
|
|
|
|
2023-03-02 11:40:52 +01:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawitem(int x, int y, int w) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
struct item *item;
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-02 17:51:25 +01:00
|
|
|
|
int numberWidth = 0;
|
|
|
|
|
int modeWidth = 0;
|
2023-03-29 22:01:45 +02:00
|
|
|
|
int larrowWidth = 0;
|
2023-03-02 17:51:25 +01:00
|
|
|
|
int rarrowWidth = 0;
|
2023-04-20 21:22:45 +02:00
|
|
|
|
int capsWidth = 0;
|
2023-03-02 17:51:25 +01:00
|
|
|
|
|
2023-03-21 16:30:30 +01:00
|
|
|
|
// add width
|
2023-03-29 22:01:45 +02:00
|
|
|
|
if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow);
|
|
|
|
|
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
|
2023-03-02 18:25:28 +01:00
|
|
|
|
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
|
|
|
|
|
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
|
2023-04-20 21:22:45 +02:00
|
|
|
|
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
|
2023-03-12 21:03:35 +01:00
|
|
|
|
|
2023-04-21 09:49:38 +02:00
|
|
|
|
if (!strcmp(capstext, ""))
|
|
|
|
|
capsWidth = 0;
|
2023-03-12 21:03:35 +01:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#if USEIMAGE
|
2023-03-26 16:42:11 +02:00
|
|
|
|
int ox = 0; // original x position
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#endif
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-11 13:24:20 +01:00
|
|
|
|
// draw items and image
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (lines > 0) {
|
|
|
|
|
int i = 0;
|
2023-03-24 04:04:37 +01:00
|
|
|
|
int rx = 0;
|
2023-03-02 18:10:37 +01:00
|
|
|
|
|
2023-03-11 13:24:20 +01:00
|
|
|
|
// draw image first
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#if USEIMAGE
|
2023-06-08 19:40:30 +02:00
|
|
|
|
if (!hideimage && longestedge != 0) {
|
2023-03-24 04:04:37 +01:00
|
|
|
|
rx = ox;
|
2023-05-01 04:30:38 +02:00
|
|
|
|
rx += MAX((imagegaps * 2) + imagewidth + menumarginh, indentitems ? x : 0);
|
2023-03-24 04:04:37 +01:00
|
|
|
|
} else
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#endif
|
2023-03-24 04:04:37 +01:00
|
|
|
|
if (!indentitems) {
|
|
|
|
|
rx = 0;
|
|
|
|
|
} else {
|
|
|
|
|
rx = x;
|
|
|
|
|
}
|
2023-03-02 18:10:37 +01:00
|
|
|
|
|
2023-05-07 15:33:09 +02:00
|
|
|
|
int itemoverride = 1;
|
2023-05-13 16:19:03 +02:00
|
|
|
|
itemn = 0;
|
2023-05-07 15:33:09 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
for (item = curr; item != next; item = item->right, i++) {
|
|
|
|
|
x = drawitemtext(
|
|
|
|
|
item,
|
|
|
|
|
rx + ((i / lines) * ((mw - rx) / columns)),
|
|
|
|
|
y + (((i % lines) + 1) * bh),
|
|
|
|
|
(mw - rx) / columns
|
|
|
|
|
);
|
2023-05-07 15:33:09 +02:00
|
|
|
|
|
|
|
|
|
if (item == sel && itemoverride) {
|
|
|
|
|
itemnumber = i;
|
|
|
|
|
itemoverride = 0;
|
|
|
|
|
}
|
2023-05-13 16:07:29 +02:00
|
|
|
|
|
|
|
|
|
itemn = !itemn;
|
2023-03-13 22:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
// horizontal list
|
|
|
|
|
} else if (matches) {
|
|
|
|
|
x += inputw;
|
2023-03-02 18:10:37 +01:00
|
|
|
|
|
2023-04-05 19:07:29 +02:00
|
|
|
|
w = larrowWidth;
|
2023-04-05 20:54:37 +02:00
|
|
|
|
x = drawlarrow(x, y, w);
|
2023-03-02 18:10:37 +01:00
|
|
|
|
|
2023-05-07 15:33:09 +02:00
|
|
|
|
itemnumber = 0;
|
|
|
|
|
int itemoverride = 1;
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
for (item = curr; item != next; item = item->right) { // draw items
|
2023-04-21 09:49:38 +02:00
|
|
|
|
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text),
|
|
|
|
|
mw - x -
|
|
|
|
|
rarrowWidth -
|
|
|
|
|
numberWidth -
|
|
|
|
|
modeWidth -
|
|
|
|
|
capsWidth -
|
|
|
|
|
menumarginh -
|
|
|
|
|
2 * sp -
|
|
|
|
|
2 * borderwidth
|
2023-05-08 23:00:45 +02:00
|
|
|
|
));
|
2023-04-21 09:49:38 +02:00
|
|
|
|
|
2023-05-07 15:33:09 +02:00
|
|
|
|
if (itemoverride) {
|
|
|
|
|
itemnumber++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item == sel) {
|
|
|
|
|
itemoverride = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w = rarrowWidth + numberWidth + modeWidth + capsWidth + menumarginh + 2 * sp + 2 * borderwidth;
|
|
|
|
|
x = drawrarrow(mw - w, y, w);
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-26 16:42:11 +02:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawprompt(int x, int y, int w) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (prompt && *prompt && !hideprompt) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
x = drw_text(drw, x, y, w, bh, lrpad / 2, prompt, 0, pango_prompt ? True : False, col_promptfg, col_promptbg, alpha_promptfg, alpha_promptbg);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-04-07 21:20:43 +02:00
|
|
|
|
if (!hidepowerline && powerlineprompt) {
|
2023-06-07 21:31:10 +02:00
|
|
|
|
if (promptpwlstyle == 2) {
|
|
|
|
|
drw_circle(drw, x, y, plw, bh, 1, col_menu, col_promptbg, alpha_menu, alpha_promptbg);
|
|
|
|
|
} else {
|
|
|
|
|
drw_arrow(drw, x, y, plw, bh, 1, promptpwlstyle, col_menu, col_promptbg, alpha_menu, alpha_promptbg);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 16:42:11 +02:00
|
|
|
|
x += plw;
|
|
|
|
|
}
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawinput(int x, int y, int w) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
char *censort; // censor text (password)
|
|
|
|
|
unsigned int curpos = 0;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
int fh = drw->font->h;
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (passwd) {
|
|
|
|
|
censort = ecalloc(1, sizeof(text));
|
2023-04-04 21:39:38 +02:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < strlen(text); i++)
|
|
|
|
|
memcpy(&censort[i], password, strlen(text));
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
apply_fribidi(censort);
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2, isrtl ? fribidi_text : censort, 0, pango_password ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
curpos = TEXTW(censort) - TEXTW(&text[cursor]);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
free(censort);
|
2023-05-08 23:00:45 +02:00
|
|
|
|
} else if (!passwd) {
|
2023-03-26 16:42:11 +02:00
|
|
|
|
apply_fribidi(text);
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2, isrtl ? fribidi_text : text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
curpos = TEXTW(text) - TEXTW(&text[cursor]);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if ((curpos += lrpad / 2 - 1) < w && !hidecaret && cursorstate) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg);
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawlarrow(int x, int y, int w) {
|
2023-03-29 22:01:45 +02:00
|
|
|
|
if (hidelarrow) return x;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (curr->left) { // draw left arrow
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2, leftarrow, 0, pango_leftarrow ? True : False, col_larrowfg, col_larrowbg, alpha_larrowfg, alpha_larrowbg);
|
2023-05-08 23:00:45 +02:00
|
|
|
|
x += w;
|
|
|
|
|
}
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawrarrow(int x, int y, int w) {
|
2023-03-29 22:01:45 +02:00
|
|
|
|
if (hiderarrow) return x;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
if (next) { // draw right arrow
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, mw - w, y, w, bh, lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False, col_rarrowfg, col_rarrowbg, alpha_rarrowfg, alpha_rarrowbg);
|
2023-03-29 22:01:45 +02:00
|
|
|
|
x += w;
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
|
2023-03-26 16:42:11 +02:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawnumber(int x, int y, int w) {
|
2023-04-05 19:07:29 +02:00
|
|
|
|
if (hidematchcount) return x;
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
2023-04-07 21:20:43 +02:00
|
|
|
|
int powerlinewidth = 0;
|
|
|
|
|
|
|
|
|
|
if (!hidepowerline && powerlinecount) {
|
|
|
|
|
powerlinewidth = plw / 2;
|
|
|
|
|
}
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2 + powerlinewidth, numbers, 0, pango_numbers ? True : False, col_numfg, col_numbg, alpha_numfg, alpha_numbg);
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
2023-04-05 19:07:29 +02:00
|
|
|
|
// draw powerline for match count
|
2023-04-07 21:20:43 +02:00
|
|
|
|
if (!hidepowerline && powerlinecount) {
|
2023-06-07 21:31:10 +02:00
|
|
|
|
if (matchcountpwlstyle == 2) {
|
|
|
|
|
drw_circle(drw, x, y, plw, bh, 0, col_menu, col_numbg, alpha_menu, alpha_numbg);
|
|
|
|
|
} else {
|
|
|
|
|
drw_arrow(drw, x, y, plw, bh, 0, matchcountpwlstyle, col_menu, col_numbg, alpha_menu, alpha_numbg);
|
|
|
|
|
}
|
2023-04-05 19:07:29 +02:00
|
|
|
|
|
|
|
|
|
x += plw;
|
2023-03-02 11:40:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 16:42:11 +02:00
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawmode(int x, int y, int w) {
|
2023-03-16 10:09:51 +01:00
|
|
|
|
if (!hidemode) { // draw mode indicator
|
2023-04-07 21:20:43 +02:00
|
|
|
|
int powerlinewidth = 0;
|
|
|
|
|
|
|
|
|
|
if (!hidepowerline && powerlinemode) {
|
|
|
|
|
powerlinewidth = plw / 2;
|
|
|
|
|
}
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2 + powerlinewidth, modetext, 0, pango_mode ? True : False, col_modefg, col_modebg, alpha_modefg, alpha_modebg);
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
|
|
|
|
// draw powerline for match count
|
2023-04-07 21:20:43 +02:00
|
|
|
|
if (!hidepowerline && powerlinemode) {
|
2023-06-07 21:31:10 +02:00
|
|
|
|
if (modepwlstyle == 2) {
|
|
|
|
|
drw_circle(drw, x, y, plw, bh, 0,
|
|
|
|
|
hidematchcount ? col_menu : col_numbg, col_modebg,
|
|
|
|
|
hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg);
|
|
|
|
|
} else {
|
|
|
|
|
drw_arrow(drw, x, y, plw, bh, 0, modepwlstyle,
|
|
|
|
|
hidematchcount ? col_menu : col_numbg, col_modebg,
|
|
|
|
|
hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg);
|
|
|
|
|
}
|
2023-03-21 16:40:11 +01:00
|
|
|
|
|
|
|
|
|
x += plw;
|
|
|
|
|
}
|
2023-03-02 11:40:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
return x;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
int drawcaps(int x, int y, int w) {
|
2023-04-20 21:22:45 +02:00
|
|
|
|
if (!w) return x; // not caps lock
|
|
|
|
|
|
|
|
|
|
if (!hidecaps) { // draw caps lock indicator
|
|
|
|
|
int powerlinewidth = 0;
|
|
|
|
|
|
|
|
|
|
if (!hidepowerline && powerlinecaps) {
|
|
|
|
|
powerlinewidth = plw / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_text(drw, x, y, w, bh, lrpad / 2 + powerlinewidth, capstext, 0, pango_caps ? True : False, col_capsfg, col_capsbg, alpha_capsfg, alpha_capsbg);
|
2023-04-20 21:22:45 +02:00
|
|
|
|
|
|
|
|
|
// draw powerline for caps lock indicator
|
|
|
|
|
if (!hidepowerline && powerlinecaps) {
|
2023-06-07 21:31:10 +02:00
|
|
|
|
if (capspwlstyle == 2) {
|
|
|
|
|
drw_circle(drw, x, y, plw, bh, 0,
|
|
|
|
|
hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg,
|
|
|
|
|
hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg);
|
|
|
|
|
} else {
|
|
|
|
|
drw_arrow(drw, x, y, plw, bh, 0, capspwlstyle,
|
|
|
|
|
hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg,
|
|
|
|
|
hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg);
|
|
|
|
|
}
|
2023-04-20 21:22:45 +02:00
|
|
|
|
|
|
|
|
|
x += plw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
return x;
|
2023-04-20 21:22:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 08:16:22 +02:00
|
|
|
|
void drawmenu(void) {
|
2023-06-02 18:37:51 +02:00
|
|
|
|
#if USEWAYLAND
|
|
|
|
|
if (protocol) {
|
|
|
|
|
readfile();
|
|
|
|
|
drawmenu_layer();
|
|
|
|
|
|
|
|
|
|
wl_surface_set_buffer_scale(state.surface, 1);
|
|
|
|
|
wl_surface_attach(state.surface, state.buffer, 0, 0);
|
|
|
|
|
wl_surface_damage(state.surface, 0, 0, state.width, state.height);
|
|
|
|
|
wl_surface_commit(state.surface);
|
2023-06-08 19:40:30 +02:00
|
|
|
|
|
|
|
|
|
drawimage();
|
2023-06-02 18:37:51 +02:00
|
|
|
|
} else {
|
|
|
|
|
drawmenu_layer();
|
|
|
|
|
}
|
2023-06-08 19:40:30 +02:00
|
|
|
|
#elif USEX
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drawmenu_layer();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawmenu_layer(void) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
int x = 0, y = 0, w = 0;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
plw = hidepowerline ? 0 : drw->font->h / 2 + 1; // powerline size
|
|
|
|
|
|
|
|
|
|
// draw menu first using menu scheme
|
2023-06-02 18:37:51 +02:00
|
|
|
|
drw_rect(drw, 0, 0, mw, mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
int numberWidth = 0;
|
|
|
|
|
int modeWidth = 0;
|
2023-04-20 21:22:45 +02:00
|
|
|
|
int capsWidth = 0;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
// add width
|
|
|
|
|
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
|
2023-04-20 21:22:45 +02:00
|
|
|
|
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
|
|
|
|
|
|
|
|
|
|
if (!strcmp(capstext, ""))
|
|
|
|
|
capsWidth = 0;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
|
|
|
|
// calculate match count
|
|
|
|
|
if (!hidematchcount) {
|
|
|
|
|
recalculatenumbers();
|
|
|
|
|
numberWidth = TEXTW(numbers);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-16 23:57:02 +02:00
|
|
|
|
x += menumarginh;
|
|
|
|
|
y += menumarginv;
|
|
|
|
|
|
2023-04-21 09:49:38 +02:00
|
|
|
|
calcoffsets();
|
|
|
|
|
|
2023-03-28 17:37:06 +02:00
|
|
|
|
// why have an empty line?
|
2023-04-21 17:59:10 +02:00
|
|
|
|
if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#if USEIMAGE
|
2023-04-01 15:03:42 +02:00
|
|
|
|
) && (!image || hideimage)) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#else
|
2023-04-01 13:59:31 +02:00
|
|
|
|
)) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
#endif
|
|
|
|
|
y -= bh;
|
|
|
|
|
mh = (lines + 1) * bh - bh + 2 * menumarginv;
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (!protocol) {
|
2023-06-05 17:16:26 +02:00
|
|
|
|
#if USEX
|
2023-06-02 18:37:51 +02:00
|
|
|
|
if (!win) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-28 17:37:06 +02:00
|
|
|
|
|
2023-06-02 18:37:51 +02:00
|
|
|
|
XResizeWindow(dpy, win, mw - 2 * sp - 2 * borderwidth, mh);
|
|
|
|
|
drw_resize(drw, mw - 2 * sp - 2 * borderwidth, mh);
|
2023-06-05 17:16:26 +02:00
|
|
|
|
#endif
|
2023-06-02 18:37:51 +02:00
|
|
|
|
} else {
|
|
|
|
|
resizeclient();
|
|
|
|
|
}
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
|
|
|
|
#if USEIMAGE
|
2023-05-16 22:06:24 +02:00
|
|
|
|
else if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
y -= bh;
|
2023-05-16 22:06:24 +02:00
|
|
|
|
mh = (lines + 1) * bh - bh + 2 * menumarginv;
|
2023-06-02 18:37:51 +02:00
|
|
|
|
|
|
|
|
|
#if USEWAYLAND
|
|
|
|
|
if (protocol) {
|
|
|
|
|
state.width = mw;
|
|
|
|
|
state.height = mh;
|
|
|
|
|
|
|
|
|
|
set_layer_size(&state, state.width, state.height);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2023-03-28 17:37:06 +02:00
|
|
|
|
|
2023-05-14 00:10:24 +02:00
|
|
|
|
if (!hideprompt && !fullscreen) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
w = promptw;
|
|
|
|
|
x = drawprompt(x, y, w);
|
|
|
|
|
}
|
2023-05-14 00:10:24 +02:00
|
|
|
|
|
|
|
|
|
if (!hideinput && !fullscreen) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
w = (lines > 0 || !matches) ? mw - x : inputw;
|
|
|
|
|
x = drawinput(x, y, w);
|
|
|
|
|
}
|
2023-04-05 18:58:48 +02:00
|
|
|
|
|
2023-05-14 00:10:24 +02:00
|
|
|
|
if (!hidemode && !fullscreen) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-05-08 23:00:45 +02:00
|
|
|
|
// draw the items, this function also calls drawrarrow() and drawlarrow()
|
|
|
|
|
if (!hideitem) drawitem(x, y, w);
|
2023-03-28 17:37:06 +02:00
|
|
|
|
|
2023-05-14 00:10:24 +02:00
|
|
|
|
if (!hidematchcount && !fullscreen) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
w = numberWidth;
|
|
|
|
|
drawnumber(mw - numberWidth - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
|
|
|
|
|
}
|
2023-04-05 19:07:29 +02:00
|
|
|
|
|
2023-05-14 00:10:24 +02:00
|
|
|
|
if (!hidemode && !fullscreen) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
w = modeWidth;
|
|
|
|
|
drawmode(mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
|
|
|
|
|
}
|
2023-04-20 21:22:45 +02:00
|
|
|
|
|
2023-05-14 00:10:24 +02:00
|
|
|
|
if (!hidecaps && !fullscreen) {
|
2023-05-08 23:00:45 +02:00
|
|
|
|
w = capsWidth;
|
|
|
|
|
drawcaps(mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
|
|
|
|
|
}
|
2023-03-26 16:42:11 +02:00
|
|
|
|
|
2023-06-05 17:16:26 +02:00
|
|
|
|
#if USEX
|
2023-06-08 19:40:30 +02:00
|
|
|
|
drawimage();
|
2023-05-08 23:00:45 +02:00
|
|
|
|
drw_map(drw, win, 0, 0, mw, mh);
|
2023-06-05 17:16:26 +02:00
|
|
|
|
#endif
|
2023-05-08 23:00:45 +02:00
|
|
|
|
}
|