separate schemes for each part

This commit is contained in:
speedie 2023-01-23 12:05:20 +01:00
parent b2dea6d4de
commit f7c4c75d8a
2 changed files with 95 additions and 52 deletions

View file

@ -3,8 +3,11 @@
/* Alpha */ /* Alpha */
static const unsigned int alphas[][3] = { static const unsigned int alphas[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = { fgalpha, bgalpha, borderalpha }, [SchemeLArrow] = { fgalpha, bgalpha, borderalpha },
[SchemeSel] = { fgalpha, bgalpha, borderalpha }, [SchemeRArrow] = { fgalpha, bgalpha, borderalpha },
[SchemeItemNorm] = { fgalpha, bgalpha, borderalpha },
[SchemeItemSel] = { fgalpha, bgalpha, borderalpha },
[SchemeMenu] = { fgalpha, bgalpha, borderalpha },
[SchemePrompt] = { fgalpha, bgalpha, borderalpha }, [SchemePrompt] = { fgalpha, bgalpha, borderalpha },
[SchemeNormHighlight] = { fgalpha, bgalpha, borderalpha }, [SchemeNormHighlight] = { fgalpha, bgalpha, borderalpha },
[SchemeSelHighlight] = { fgalpha, bgalpha, borderalpha }, [SchemeSelHighlight] = { fgalpha, bgalpha, borderalpha },
@ -16,14 +19,17 @@ static const unsigned int alphas[][3] = {
/* Colors */ /* Colors */
static const char *colors[SchemeLast][2] = { static const char *colors[SchemeLast][2] = {
/* fg bg */ /* fg bg */
[SchemeNorm] = { col_normfgcolor, col_normbgcolor }, [SchemeLArrow] = { col_normfgcolor, col_normbgcolor },
[SchemeSel] = { col_selfgcolor, col_selbgcolor }, [SchemeRArrow] = { col_normfgcolor, col_normbgcolor },
[SchemeBorder] = { NULL, col_bordercolor }, [SchemeItemNorm] = { col_normfgcolor, col_normbgcolor },
[SchemeItemSel] = { col_selfgcolor, col_selbgcolor },
[SchemeMenu] = { NULL, col_normbgcolor },
[SchemePrompt] = { col_selfgcolor, col_selbgcolor }, [SchemePrompt] = { col_selfgcolor, col_selbgcolor },
[SchemeNormHighlight] = { col_normhlfgcolor, col_normhlbgcolor }, [SchemeNormHighlight] = { col_normhlfgcolor, col_normhlbgcolor },
[SchemeSelHighlight] = { col_selhlfgcolor, col_selhlbgcolor }, [SchemeSelHighlight] = { col_selhlfgcolor, col_selhlbgcolor },
[SchemeCaret] = { col_caretfgcolor, NULL }, [SchemeCaret] = { col_caretfgcolor, NULL },
[SchemeNumber] = { col_numfgcolor, col_numbgcolor }, [SchemeNumber] = { col_numfgcolor, col_numbgcolor },
[SchemeBorder] = { NULL, col_bordercolor },
}; };
/* sgr colors */ /* sgr colors */

129
spmenu.c
View file

@ -58,21 +58,22 @@ static char fribidi_text[BUFSIZ] = "";
#define opaque 0xffU #define opaque 0xffU
/* enums */ /* enums */
enum { SchemeNorm, enum { SchemeLArrow,
SchemeSel, SchemeRArrow,
SchemeItemNorm,
SchemeItemSel,
SchemeMenu,
SchemePrompt, SchemePrompt,
SchemeCaret,
SchemeOut,
SchemeNumber,
SchemeNormHighlight, SchemeNormHighlight,
SchemeSelHighlight, SchemeSelHighlight,
SchemeCaret,
SchemeNumber,
SchemeBorder, SchemeBorder,
SchemeLast }; /* color schemes */ SchemeLast }; /* color schemes */
struct item { struct item {
char *text; char *text;
struct item *left, *right; struct item *left, *right;
int out;
double distance; double distance;
}; };
@ -305,11 +306,9 @@ int
drawitem(struct item *item, int x, int y, int w) drawitem(struct item *item, int x, int y, int w)
{ {
if (item == sel) if (item == sel)
drw_setscheme(drw, scheme[SchemeSel]); drw_setscheme(drw, scheme[SchemeItemSel]);
else if (item->out)
drw_setscheme(drw, scheme[SchemeOut]);
else else
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeItemNorm]);
char buffer[sizeof(item->text) + lrpad / 2]; char buffer[sizeof(item->text) + lrpad / 2];
Clr scm[3]; Clr scm[3];
@ -321,11 +320,9 @@ drawitem(struct item *item, int x, int y, int w)
int bgfg = 0; int bgfg = 0;
if (item == sel) if (item == sel)
memcpy(scm, scheme[SchemeSel], sizeof(scm)); memcpy(scm, scheme[SchemeItemSel], sizeof(scm));
else if (item->out)
memcpy(scm, scheme[SchemeOut], sizeof(scm));
else else
memcpy(scm, scheme[SchemeNorm], sizeof(scm)); memcpy(scm, scheme[SchemeItemNorm], sizeof(scm));
drw_setscheme(drw, scm); /* set scheme to what we copied */ drw_setscheme(drw, scm); /* set scheme to what we copied */
@ -434,7 +431,7 @@ drawmenu(void)
int x = 0, y = 0, fh = drw->font->h, w; int x = 0, y = 0, fh = drw->font->h, w;
char *censort; char *censort;
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeMenu]);
drw_rect(drw, 0, 0, mw, mh, 1, 1); drw_rect(drw, 0, 0, mw, mh, 1, 1);
if (prompt && *prompt) { if (prompt && *prompt) {
@ -446,7 +443,7 @@ drawmenu(void)
} }
/* draw input field */ /* draw input field */
w = (lines > 0 || !matches) ? mw - x : inputw; w = (lines > 0 || !matches) ? mw - x : inputw;
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeMenu]);
if (passwd) { if (passwd) {
censort = ecalloc(1, sizeof(text)); censort = ecalloc(1, sizeof(text));
memset(censort, '.', strlen(text)); memset(censort, '.', strlen(text));
@ -490,7 +487,7 @@ drawmenu(void)
x += inputw; x += inputw;
w = TEXTW(leftarrow); w = TEXTW(leftarrow);
if (curr->left) { if (curr->left) {
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeLArrow]);
drw_text(drw, x, 0, w, bh, lrpad / 2, leftarrow, 0, True); drw_text(drw, x, 0, w, bh, lrpad / 2, leftarrow, 0, True);
} }
x += w; x += w;
@ -502,7 +499,7 @@ drawmenu(void)
} }
if (next) { if (next) {
w = TEXTW(rightarrow); w = TEXTW(rightarrow);
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeRArrow]);
if (hidematchcount) { if (hidematchcount) {
drw_text(drw, mw - w, 0, w, bh, lrpad / 2, rightarrow, 0, True); drw_text(drw, mw - w, 0, w, bh, lrpad / 2, rightarrow, 0, True);
@ -1258,7 +1255,6 @@ buttonpress(XEvent *e)
exit(0); exit(0);
sel = item; sel = item;
if (sel) { if (sel) {
sel->out = 1;
drawmenu(); drawmenu();
} }
return; return;
@ -1286,7 +1282,6 @@ buttonpress(XEvent *e)
exit(0); exit(0);
sel = item; sel = item;
if (sel) { if (sel) {
sel->out = 1;
drawmenu(); drawmenu();
} }
return; return;
@ -1404,7 +1399,6 @@ readstdin(void)
*p = '\0'; *p = '\0';
if (!(items[i].text = strdup(buf))) if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1); die("cannot strdup %u bytes:", strlen(buf) + 1);
items[i].out = 0;
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True); drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
if (tmpmax > inputw) { if (tmpmax > inputw) {
inputw = tmpmax; inputw = tmpmax;
@ -1756,14 +1750,15 @@ usage(void)
"spmenu -wm Spawn spmenu as a window manager controlled client/window. Useful for testing\n" "spmenu -wm Spawn spmenu as a window manager controlled client/window. Useful for testing\n"
"spmenu -v Print spmenu version to stdout\n" "spmenu -v Print spmenu version to stdout\n"
"\n" "\n"
"- Color arguments -\n" "- Appearance arguments -\n"
"spmenu -fn <font> Set the spmenu font to <font>\n" "spmenu -fn <font> Set the spmenu font to <font>\n"
"spmenu -nb <color> Set the normal background color\n" "spmenu -nif <color> Set the normal item foreground color\n"
"spmenu -nf <color> Set the normal foreground color\n" "spmenu -nib <color> Set the normal item background color\n"
"spmenu -sb <color> Set the selected background color\n" "spmenu -sif <color> Set the selected item foreground color\n"
"spmenu -sf <color> Set the selected foreground color\n" "spmenu -sib <color> Set the selected item background color\n"
"spmenu -cc <color> Set the caret color\n" "spmenu -pfg <color> Set the prompt foreground color\n"
"spmenu -bcb <color> Set the border color\n" "spmenu -pbg <color> Set the prompt background color\n"
"spmenu -mbg <color> Set the menu background color\n"
"spmenu -nhf <color> Set the normal highlight foreground color\n" "spmenu -nhf <color> Set the normal highlight foreground color\n"
"spmenu -nhb <color> Set the normal highlight background color\n" "spmenu -nhb <color> Set the normal highlight background color\n"
"spmenu -shf <color> Set the selected highlight foreground color\n" "spmenu -shf <color> Set the selected highlight foreground color\n"
@ -1771,6 +1766,10 @@ usage(void)
"spmenu -shb <color> Set the selected highlight background color\n" "spmenu -shb <color> Set the selected highlight background color\n"
"spmenu -nfg <color> Set the foreground color for the match count\n" "spmenu -nfg <color> Set the foreground color for the match count\n"
"spmenu -nbg <color> Set the background color for the match count\n" "spmenu -nbg <color> Set the background color for the match count\n"
"spmenu -laf <color> Set the left arrow color\n"
"spmenu -raf <color> Set the left arrow color\n"
"spmenu -cc <color> Set the caret color\n"
"spmenu -bcb <color> Set the border color\n"
"spmenu -sgr0 Set the SGR 0 color\n" "spmenu -sgr0 Set the SGR 0 color\n"
"spmenu -sgr1 Set the SGR 1 color\n" "spmenu -sgr1 Set the SGR 1 color\n"
"spmenu -sgr2 Set the SGR 2 color\n" "spmenu -sgr2 Set the SGR 2 color\n"
@ -1788,6 +1787,12 @@ usage(void)
"spmenu -sgr14 Set the SGR 14 color\n" "spmenu -sgr14 Set the SGR 14 color\n"
"spmenu -sgr15 Set the SGR 15 color\n" "spmenu -sgr15 Set the SGR 15 color\n"
"\n" "\n"
"- dmenu compatibility -\n"
"spmenu -nb <color> Set the normal background color\n"
"spmenu -nf <color> Set the normal foreground color\n"
"spmenu -sb <color> Set the selected background color\n"
"spmenu -sf <color> Set the selected foreground color\n"
"\n"
"- Example usage -\n" "- Example usage -\n"
"`echo 'Hello\\nWorld' | spmenu -l 2` will allow you to pick either 'Hello' or 'World'. The selected then gets printed to stdout. This means you can pipe it into `sed` or `grep`.\n" "`echo 'Hello\\nWorld' | spmenu -l 2` will allow you to pick either 'Hello' or 'World'. The selected then gets printed to stdout. This means you can pipe it into `sed` or `grep`.\n"
, stdout); , stdout);
@ -1907,30 +1912,62 @@ main(int argc, char *argv[])
dmw = atoi(argv[++i]); dmw = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i]; prompt = argv[++i];
else if (!strcmp(argv[i], "-fn")) /* font or font set */ else if (!strcmp(argv[i], "-fn")) { /* font or font set */
strcpy(font, argv[++i]); /* font[0] = argv[++i]; */ strcpy(font, argv[++i]); /* font[0] = argv[++i]; */
else if (!strcmp(argv[i], "-nb")) /* normal background color */
colors[SchemeNorm][ColBg] = argv[++i]; /* dmenu compatibility options */
else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ } else if (!strcmp(argv[i], "-nb")) { /* normal background color */
colors[SchemeNorm][ColFg] = argv[++i]; colors[SchemeItemNorm][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-sb")) /* selected background color */ colors[SchemeMenu][ColBg] = argv[++i];
colors[SchemeSel][ColBg] = argv[++i]; colors[SchemePrompt][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ } else if (!strcmp(argv[i], "-nf")) { /* normal foreground color */
colors[SchemeSel][ColFg] = argv[++i]; colors[SchemeItemNorm][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-shf")) /* selected highlight foreground color */ colors[SchemeMenu][ColFg] = argv[++i];
colors[SchemePrompt][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-sb")) { /* selected background color */
colors[SchemeItemSel][ColBg] = argv[++i];
colors[SchemeMenu][ColBg] = argv[++i];
colors[SchemePrompt][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-sf")) { /* selected foreground color */
colors[SchemeItemSel][ColFg] = argv[++i];
colors[SchemeMenu][ColFg] = argv[++i];
colors[SchemePrompt][ColFg] = argv[++i];
/* spmenu colors */
} else if (!strcmp(argv[i], "-nif")) { /* normal item foreground color */
colors[SchemeItemNorm][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-nib")) { /* normal item background color */
colors[SchemeItemNorm][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-sif")) { /* selected item foreground color */
colors[SchemeItemSel][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-sib")) { /* selected item background color */
colors[SchemeItemSel][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-mbg")) { /* menu color */
colors[SchemeMenu][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-pfg")) { /* prompt fg color */
colors[SchemePrompt][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-pbg")) { /* prompt bg color */
colors[SchemePrompt][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-shf")) { /* selected highlight foreground color */
colors[SchemeSelHighlight][ColBg] = argv[++i]; colors[SchemeSelHighlight][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-nhf")) /* normal highlight foreground color */ } else if (!strcmp(argv[i], "-shf")) { /* selected highlight foreground color */
colors[SchemeNormHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-shb")) /* selected highlight foreground color */
colors[SchemeSelHighlight][ColBg] = argv[++i]; colors[SchemeSelHighlight][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-nhb")) /* normal highlight foreground color */ } else if (!strcmp(argv[i], "-nhf")) { /* normal highlight foreground color */
colors[SchemeNormHighlight][ColFg] = argv[++i]; colors[SchemeNormHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-nbg")) /* numbgcolor */ } else if (!strcmp(argv[i], "-shb")) { /* selected highlight foreground color */
colors[SchemeSelHighlight][ColBg] = argv[++i];
} else if (!strcmp(argv[i], "-nhb")) { /* normal highlight foreground color */
colors[SchemeNormHighlight][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-nbg")) { /* numbgcolor */
colors[SchemeNumber][ColBg] = argv[++i]; colors[SchemeNumber][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-nfg")) /* numfgcolor */ } else if (!strcmp(argv[i], "-laf")) { /* left arrow fg */
colors[SchemeNumber][ColFg] = argv[++i]; colors[SchemeLArrow][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-bcb")) /* border */ } else if (!strcmp(argv[i], "-raf")) { /* right arrow fg */
colors[SchemeRArrow][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-bcb")) { /* border */
colors[SchemeBorder][ColBg] = argv[++i]; colors[SchemeBorder][ColBg] = argv[++i];
}
/* sgr colors */ /* sgr colors */
else if (!strcmp(argv[i], "-sgr0")) textcolors[0] = argv[++i]; /* sgr color 0 */ else if (!strcmp(argv[i], "-sgr0")) textcolors[0] = argv[++i]; /* sgr color 0 */
else if (!strcmp(argv[i], "-sgr1")) textcolors[1] = argv[++i]; /* sgr color 1 */ else if (!strcmp(argv[i], "-sgr1")) textcolors[1] = argv[++i]; /* sgr color 1 */