From b79f5c39c153ad960a5b8b66725d8cbba1f62152 Mon Sep 17 00:00:00 2001 From: speedie Date: Thu, 20 Apr 2023 21:22:45 +0200 Subject: [PATCH] add a caps lock indicator, took lots of work --- docs/docs.md | 9 +++++ docs/example.Xresources | 8 ++++ docs/spmenu.conf | 10 +++++ libs/argv.c | 13 +++++- libs/colors.h | 2 + libs/conf/config.c | 44 ++++++++++++++------ libs/draw.c | 45 +++++++++++++++++++-- libs/draw.h | 1 + libs/event.c | 78 +++++++++++++++++++----------------- libs/key.c | 15 ++++++- libs/key.h | 3 ++ libs/mode.c | 2 +- libs/mouse.c | 11 ++++- libs/mouse.h | 1 + libs/schemes.c | 2 + libs/schemes.h | 1 + libs/xresources.h | 12 +++++- mouse.h | 1 + options.h | 12 ++++++ spmenu.1 | 9 +++++ spmenu.c | 1 + themes/dmenu.conf | 1 + themes/legacy/Catppuccin | 2 + themes/legacy/Cyberpunk-Neon | 2 + themes/legacy/Doom-One | 2 + themes/legacy/Dracula | 2 + themes/legacy/Gruvbox-Dark | 2 + themes/legacy/Nord | 56 +++++++++++++------------- themes/legacy/Solarized-Dark | 4 +- themes/legacy/Tokyo-Night | 2 + 30 files changed, 266 insertions(+), 87 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 32f419f..8abef37 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -125,6 +125,12 @@ You may use long, descriptive arguments or the shorter arguments. `-imt, --insert-mode-text text` : Set insert mode text to text +`-clon, --caps-lock-on-text text` +: Set caps lock on text to text + +`-clof, --caps-lock-off-text text` +: Set caps lock off text to text + `-bw, --border-width width` : Set width of the border to width . 0 will disable the border @@ -191,6 +197,9 @@ You may use long, descriptive arguments or the shorter arguments. `-hi, --hide-image` : Hide image +`-hcl, --hide-caps` +: Hide caps lock indicator + `-sm, --show-mode` : Show mode indicator diff --git a/docs/example.Xresources b/docs/example.Xresources index fe5acbd..b70e6ef 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -36,6 +36,8 @@ spmenu.col_caretbg: #222222 spmenu.col_border: #35638A spmenu.col_modefg: #ffffff spmenu.col_modebg: #35638A +spmenu.col_capsfg: #ffffff +spmenu.col_capsbg: #45638A spmenu.col_sgr0: #000000 spmenu.col_sgr1: #7f0000 spmenu.col_sgr2: #007f00 @@ -82,14 +84,18 @@ spmenu.alpha_caretfgfg: 255 spmenu.alpha_caretfgbg: 200 spmenu.alpha_modefg: 255 spmenu.alpha_modebg: 200 +spmenu.alpha_capsfg: 255 +spmenu.alpha_capsbg: 200 !! Powerline spmenu.powerlineprompt: 1 spmenu.powerlinecount: 1 spmenu.powerlinemode: 1 +spmenu.powerlinecaps: 1 spmenu.promptpwlstyle: 0 spmenu.matchcountpwlstyle: 0 spmenu.modepwlstyle: 0 +spmenu.capspwlstyle: 0 !! Misc color spmenu.globalcolors: 1 @@ -156,6 +162,7 @@ spmenu.hideitem: 0 spmenu.hideprompt: 0 spmenu.hideinput: 0 spmenu.hidepowerline: 0 +spmenu.hidecaps: 0 spmenu.hidecaret: 0 spmenu.hidehighlight: 0 spmenu.hideimage: 0 @@ -168,5 +175,6 @@ spmenu.pango_leftarrow: 0 spmenu.pango_rightarrow: 0 spmenu.pango_numbers: 0 spmenu.pango_mode: 0 +spmenu.pango_caps: 0 spmenu.pango_password: 0 spmenu.pango_highlight: 1 diff --git a/docs/spmenu.conf b/docs/spmenu.conf index c3e3421..9ae450c 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -35,6 +35,8 @@ spmenu = password = "*"; prompt = ""; input = ""; + capslockon = "Caps Lock"; + capslockoff = ""; } ); // Color @@ -63,6 +65,8 @@ spmenu = numbg = "#2d3856"; modefg = "#ffffff"; modebg = "#35638A"; + capsfg = "#ffffff"; + capsbg = "#45638A"; border = "#35638A"; caretfg = "#ffffff"; caretbg = "#222222"; @@ -115,15 +119,19 @@ spmenu = caretbg = 200; modefg = 255; modebg = 200; + capsfg = 255; + capsbg = 200; } ); // Powerline options powerline = ( { promptstyle = 0; matchcountstyle = 0; modestyle = 0; + capsstyle = 0; prompt = 1; matchcount = 1; mode = 1; + caps = 1; } ); // Hide options @@ -137,6 +145,7 @@ spmenu = highlight = 0; matchcount = 0; mode = 0; + caps = 0; image = 0; } ); @@ -200,6 +209,7 @@ spmenu = rightarrow = 0; numbers = 0; mode = 0; + caps = 0; password = 0; } ); }; diff --git a/libs/argv.c b/libs/argv.c index 1619d56..506539e 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -250,8 +250,12 @@ readargs(int argc, char *argv[]) fonts[0] = argv[++i]; else if (!strcmp(argv[i], "-nmt") || (!strcmp(argv[i], "--normal-mode-text"))) // normal mode text strcpy(normtext, argv[++i]); - else if (!strcmp(argv[i], "-imt") || (!strcmp(argv[i], "--insert-mode-text"))) { // insert mode text + else if (!strcmp(argv[i], "-imt") || (!strcmp(argv[i], "--insert-mode-text"))) // insert mode text strcpy(instext, argv[++i]); + else if (!strcmp(argv[i], "-clon") || (!strcmp(argv[i], "--caps-lock-on-text"))) // caps lock on text + strcpy(capslockontext, argv[++i]); + else if (!strcmp(argv[i], "-clof") || (!strcmp(argv[i], "--caps-lock-off-text"))) { // caps lock off text + strcpy(capslockofftext, argv[++i]); // dmenu compatibility options } else if (!strcmp(argv[i], "-nb")) { // normal background color @@ -436,12 +440,16 @@ usage(void) "spmenu -na, --no-alpha Disable alpha\n" "spmenu -tp, --allow-typing Allow the user to type\n" "spmenu -nt, --no-allow-typing Don't allow typing, the user must select an option\n" - "spmenu -x, --x-position Offset spmenu x position by \n" + , stdout); + + fputs("spmenu -x, --x-position Offset spmenu x position by \n" "spmenu -y, --y-position Offset spmenu y position by \n" "spmenu -n, --preselect Preselect in the list of items\n" "spmenu -z, --width Width of the spmenu window\n" "spmenu -nmt, --normal-mode-text Set normal mode text to \n" "spmenu -imt, --insert-mode-text Set insert mode text to \n" + "spmenu -clon, --caps-lock-on-text Set caps lock on text to \n" + "spmenu -clof, --caps-lock-off-text Set caps lock off text to \n" "spmenu -bw, --border-width Set width of the border to . 0 will disable the border\n" "spmenu -so, --sort Sort matches\n" "spmenu -nso, --no-sort Don't sort matches\n" @@ -467,6 +475,7 @@ usage(void) "spmenu -hc, --hide-caret, --hide-cursor Hide caret\n" "spmenu -hhl, --hide-highlighting Hide highlight\n" "spmenu -hi, --hide-image Hide image\n" + "spmenu -hcl, --hide-caps Hide caps lock indicator\n" "spmenu -sm, --show-mode Show mode indicator\n" "spmenu -smc, --show-match-count Show match count\n" "spmenu -sla, --show-left-arrow Show left arrow\n" diff --git a/libs/colors.h b/libs/colors.h index 2046142..eb077ad 100644 --- a/libs/colors.h +++ b/libs/colors.h @@ -16,6 +16,7 @@ static unsigned int alphas[][2] = { [SchemeCaret] = { 255, 200 }, [SchemeNumber] = { 255, 200 }, [SchemeBorder] = { 255, 200 }, + [SchemeCaps] = { 255, 200 }, }; // colorscheme array @@ -29,6 +30,7 @@ static char *colors[SchemeLast][2] = { [SchemeItemSelPri] = { col_itemselprifg, col_itemselpribg }, [SchemeInput] = { col_inputfg, col_inputbg, }, [SchemeMenu] = { NULL, col_menu }, + [SchemeCaps] = { col_capsfg, col_capsbg }, [SchemePrompt] = { col_promptfg, col_promptbg }, [SchemeNormHighlight] = { col_hlnormfg, col_hlnormbg }, [SchemeSelHighlight] = { col_hlselfg, col_hlselbg }, diff --git a/libs/conf/config.c b/libs/conf/config.c index e2cd00a..d7fe9c2 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -120,9 +120,11 @@ conf_init(void) config_setting_lookup_int(conf, "promptstyle", &promptpwlstyle); // spmenu.powerline.promptstyle config_setting_lookup_int(conf, "matchcountstyle", &matchcountpwlstyle); // spmenu.powerline.matchcountstyle config_setting_lookup_int(conf, "modestyle", &modepwlstyle); // spmenu.powerline.modestyle + config_setting_lookup_int(conf, "capsstyle", &capspwlstyle); // spmenu.powerline.capsstyle config_setting_lookup_int(conf, "prompt", &powerlineprompt); // spmenu.powerline.prompt config_setting_lookup_int(conf, "matchcount", &powerlinecount); // spmenu.powerline.matchcount config_setting_lookup_int(conf, "mode", &powerlinemode); // spmenu.powerline.mode + config_setting_lookup_int(conf, "caps", &powerlinecaps); // spmenu.powerline.caps } } @@ -152,25 +154,31 @@ conf_init(void) config_setting_t *conf = config_setting_get_elem(setting, i); // look up - config_setting_lookup_string(conf, "font", &dest); // spmenu.text.font - strcpy(font, strdup(dest)); + if (config_setting_lookup_string(conf, "font", &dest)) // spmenu.text.font + strcpy(font, strdup(dest)); config_setting_lookup_int(conf, "padding", &textpadding); // spmenu.text.padding - config_setting_lookup_string(conf, "leftarrow", &dest); // spmenu.text.leftarrow - leftarrow = strdup(dest); + if (config_setting_lookup_string(conf, "leftarrow", &dest)) // spmenu.text.leftarrow + leftarrow = strdup(dest); - config_setting_lookup_string(conf, "rightarrow", &dest); // spmenu.text.rightarrow - rightarrow = strdup(dest); + if (config_setting_lookup_string(conf, "rightarrow", &dest)) // spmenu.text.rightarrow + rightarrow = strdup(dest); - config_setting_lookup_string(conf, "password", &dest); - password = strdup(dest); + if (config_setting_lookup_string(conf, "password", &dest)) + password = strdup(dest); - config_setting_lookup_string(conf, "prompt", &dest); - prompt = strdup(dest); + if (config_setting_lookup_string(conf, "prompt", &dest)) + prompt = strdup(dest); - config_setting_lookup_string(conf, "input", &dest); - input = strdup(dest); + if (config_setting_lookup_string(conf, "capslockon", &dest)) + capslockontext = strdup(dest); + + if (config_setting_lookup_string(conf, "capslockoff", &dest)) + capslockofftext = strdup(dest); + + if (config_setting_lookup_string(conf, "input", &dest)) + input = strdup(dest); } } @@ -223,6 +231,9 @@ conf_init(void) config_setting_lookup_int(conf, "modefg", &alpha_modefg); // spmenu.alpha.modefg config_setting_lookup_int(conf, "modebg", &alpha_modebg); // spmenu.alpha.modebg + + config_setting_lookup_int(conf, "capsfg", &alpha_capsfg); // spmenu.alpha.capsfg + config_setting_lookup_int(conf, "capsbg", &alpha_capsbg); // spmenu.alpha.capsbg } } @@ -320,6 +331,13 @@ conf_init(void) if (config_setting_lookup_string(conf, "modebg", &dest)) strcpy(colors[SchemeMode][ColBg], strdup(dest)); + // caps + if (config_setting_lookup_string(conf, "capsfg", &dest)) + strcpy(colors[SchemeCaps][ColFg], strdup(dest)); + + if (config_setting_lookup_string(conf, "capsbg", &dest)) + strcpy(colors[SchemeCaps][ColBg], strdup(dest)); + // border if (config_setting_lookup_string(conf, "border", &dest)) strcpy(colors[SchemeBorder][ColBg], strdup(dest)); @@ -521,6 +539,7 @@ conf_init(void) config_setting_lookup_int(conf, "highlight", &hidehighlight); // spmenu.hide.highlight config_setting_lookup_int(conf, "matchcount", &hidematchcount); // spmenu.hide.matchcount config_setting_lookup_int(conf, "mode", &hidemode); // spmenu.hide.mode + config_setting_lookup_int(conf, "caps", &hidecaps); // spmenu.hide.caps config_setting_lookup_int(conf, "hideimage", &hideimage); // spmenu.hide.image } } @@ -544,6 +563,7 @@ conf_init(void) config_setting_lookup_int(conf, "rightarrow", &pango_rightarrow); // spmenu.pango.rightarrow config_setting_lookup_int(conf, "numbers", &pango_numbers); // spmenu.pango.numbers config_setting_lookup_int(conf, "mode", &pango_mode); // spmenu.pango.mode + config_setting_lookup_int(conf, "caps", &pango_caps); // spmenu.pango.caps config_setting_lookup_int(conf, "password", &pango_password); // spmenu.pango.mode } } diff --git a/libs/draw.c b/libs/draw.c index 70252ae..f4b0ce3 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -181,6 +181,7 @@ drawitem(int x, int y, int w) int modeWidth = 0; int larrowWidth = 0; int rarrowWidth = 0; + int capsWidth = 0; // add width if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); @@ -188,6 +189,7 @@ drawitem(int x, int y, int w) if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers); + if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); // mode indicator is always going to be at the right if (hidemode) { @@ -235,7 +237,7 @@ drawitem(int x, int y, int w) x = drawlarrow(x, y, w); for (item = curr; item != next; item = item->right) // draw items - x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), mw - x - rarrowWidth - numberWidth - modeWidth - menumarginh)); + x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), mw - x - rarrowWidth - numberWidth - modeWidth - capsWidth - menumarginh)); w = rarrowWidth + numberWidth + modeWidth + menumarginh; x = drawrarrow(mw - w, y, w); @@ -378,6 +380,33 @@ drawmode(int x, int y, int w) return x; } +int +drawcaps(int x, int y, int w) +{ + if (!w) return x; // not caps lock + + if (!hidecaps) { // draw caps lock indicator + int powerlinewidth = 0; + + if (!hidepowerline && powerlinecaps) { + powerlinewidth = plw / 2; + } + + drw_setscheme(drw, scheme[SchemeCaps]); + drw_text(drw, x, y, w, bh, lrpad / 2 + powerlinewidth, capstext, 0, pango_caps ? True : False); + + // draw powerline for caps lock indicator + if (!hidepowerline && powerlinecaps) { + drw_settrans(drw, scheme[SchemeCaps], hidemode ? hidematchcount ? scheme[SchemeMenu] : scheme[SchemeNumber] : scheme[SchemeMode]); + drw_arrow(drw, x, y, plw, bh, 0, capspwlstyle); + + x += plw; + } + } + + return x; +} + void drawmenu(void) { @@ -390,9 +419,14 @@ drawmenu(void) int numberWidth = 0; int modeWidth = 0; + int capsWidth = 0; // add width if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); + if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); + + if (!strcmp(capstext, "")) + capsWidth = 0; // calculate match count if (!hidematchcount) { @@ -441,12 +475,17 @@ drawmenu(void) if (!hidematchcount) { w = numberWidth; - drawnumber(mw - numberWidth - modeWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); + drawnumber(mw - numberWidth - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); } if (!hidemode) { w = modeWidth; - drawmode(mw - modeWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); + drawmode(mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); + } + + if (!hidecaps) { + w = capsWidth; + drawcaps(mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w); } drw_map(drw, win, 0, 0, mw, mh); diff --git a/libs/draw.h b/libs/draw.h index c9a341d..52f1490 100644 --- a/libs/draw.h +++ b/libs/draw.h @@ -4,5 +4,6 @@ static int drawprompt(int x, int y, int w); static int drawinput(int x, int y, int w); static int drawnumber(int x, int y, int w); static int drawmode(int x, int y, int w); +static int drawcaps(int x, int y, int w); static int drawlarrow(int x, int y, int w); static int drawrarrow(int x, int y, int w); diff --git a/libs/event.c b/libs/event.c index e25db31..9bfa063 100644 --- a/libs/event.c +++ b/libs/event.c @@ -10,43 +10,47 @@ eventloop(void) if (XFilterEvent(&ev, None)) continue; switch(ev.type) { - case DestroyNotify: - if (ev.xdestroywindow.window != win) - break; - cleanup(); - exit(1); - case ButtonPress: - buttonpress(&ev); - #if USEIMAGE - noimg = 0; - #endif - break; - case MotionNotify: - motionevent(&ev.xbutton); - #if USEIMAGE - noimg = 0; - #endif - break; - case Expose: - if (ev.xexpose.count == 0) - drw_map(drw, win, 0, 0, mw, mh); - break; - case FocusIn: - // regrab focus from parent window - if (ev.xfocus.window != win) - grabfocus(); - break; - case KeyPress: // read key array and call functions - keypress(&ev); - break; - case SelectionNotify: // paste selection - if (ev.xselection.property == utf8) - pastesel(); - break; - case VisibilityNotify: - if (ev.xvisibility.state != VisibilityUnobscured) - XRaiseWindow(dpy, win); - break; + case DestroyNotify: + if (ev.xdestroywindow.window != win) + break; + cleanup(); + exit(1); + case ButtonPress: + buttonpress(&ev); + #if USEIMAGE + noimg = 0; + #endif + break; + case MotionNotify: + motionevent(&ev.xbutton); + #if USEIMAGE + noimg = 0; + #endif + break; + case Expose: + if (ev.xexpose.count == 0) + drw_map(drw, win, 0, 0, mw, mh); + break; + case FocusIn: + // regrab focus from parent window + if (ev.xfocus.window != win) + grabfocus(); + break; + case KeyPress: // read key array and call functions + keypress(&ev); + break; + case SelectionNotify: // paste selection + if (ev.xselection.property == utf8) + pastesel(); + break; + case VisibilityNotify: + if (ev.xvisibility.state != VisibilityUnobscured) + XRaiseWindow(dpy, win); + break; + case KeyRelease: + getcapsstate(); + drawmenu(); + break; } // redraw image on X11 event diff --git a/libs/key.c b/libs/key.c index eee500c..9c958dd 100644 --- a/libs/key.c +++ b/libs/key.c @@ -69,9 +69,22 @@ grabkeyboard(void) // try to grab keyboard, we may have to wait for another process to ungrab for (i = 0; i < 1000; i++) { if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, - GrabModeAsync, CurrentTime) == GrabSuccess) + GrabModeAsync, CurrentTime) == GrabSuccess) { + getcapsstate(); return; + } nanosleep(&ts, NULL); } die("cannot grab keyboard"); } + +void +getcapsstate(void) +{ + unsigned int cs = 0; + + XkbGetIndicatorState(dpy, XkbUseCoreKbd, &cs); + capslockstate = (cs & 0x01) == 1; + + strncpy(capstext, capslockstate ? capslockontext : capslockofftext, 15); +} diff --git a/libs/key.h b/libs/key.h index 6bcbadf..85d3a43 100644 --- a/libs/key.h +++ b/libs/key.h @@ -9,3 +9,6 @@ typedef struct { static void updatenumlockmask(void); static void keypress(XEvent *e); static void grabkeyboard(void); +static void getcapsstate(void); + +static char capstext[16] = "Caps Lock"; diff --git a/libs/mode.c b/libs/mode.c index bc7a01f..c127b82 100644 --- a/libs/mode.c +++ b/libs/mode.c @@ -4,7 +4,7 @@ switchmode(const Arg *arg) curMode = !curMode; allowkeys = !curMode; - strcpy(modetext, curMode ? instext : normtext); + strncpy(modetext, curMode ? instext : normtext, 15); drawmenu(); } diff --git a/libs/mouse.c b/libs/mouse.c index 3e6a289..4e10cdc 100644 --- a/libs/mouse.c +++ b/libs/mouse.c @@ -72,11 +72,16 @@ buttonpress(XEvent *e) int rarrowWidth = 0; int numberWidth = 0; int modeWidth = 0; + int capsWidth = 0; if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers); if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); + if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); + + if (!strcmp(capstext, "")) + capsWidth = 0; // if incorrect or wrong window, return if (ev->window != win) @@ -88,9 +93,11 @@ buttonpress(XEvent *e) // check if we clicked on the prompt or the input if (ev->x < x + promptw + powerlineprompt ? plw : 0) { click = clickprompt; - } else if (ev->x > mw - modeWidth - 2 * sp - 2 * borderwidth) { + } else if ((ev->x > mw - capsWidth - 2 * sp - 2 * borderwidth) && !hidecaps) { + click = clickcaps; + } else if (ev->x > mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth) { click = clickmode; - } else if (ev->x > mw - modeWidth - numberWidth - 2 * sp - 2 * borderwidth) { + } else if (ev->x > mw - modeWidth - numberWidth - capsWidth - 2 * sp - 2 * borderwidth) { click = clicknumber; } else { // actually we clicked on the input w = (lines > 0 || !matches) ? mw - x : inputw; diff --git a/libs/mouse.h b/libs/mouse.h index 086a48c..a2f811b 100644 --- a/libs/mouse.h +++ b/libs/mouse.h @@ -16,6 +16,7 @@ enum { clickselitem, clickrarrow, clicknumber, + clickcaps, clickmode, }; diff --git a/libs/schemes.c b/libs/schemes.c index 6cf8c50..745041b 100644 --- a/libs/schemes.c +++ b/libs/schemes.c @@ -39,6 +39,8 @@ init_appearance(void) alphas[SchemeNumber][ColBg] = alpha_numbg; alphas[SchemeMode][ColFg] = alpha_modefg; alphas[SchemeMode][ColBg] = alpha_modebg; + alphas[SchemeCaps][ColFg] = alpha_capsfg; + alphas[SchemeCaps][ColBg] = alpha_capsbg; alphas[SchemeBorder][ColBg] = alpha_border; // create color schemes from array diff --git a/libs/schemes.h b/libs/schemes.h index c3625bd..914d50f 100644 --- a/libs/schemes.h +++ b/libs/schemes.h @@ -16,5 +16,6 @@ enum { SchemeLArrow, SchemeNumber, SchemeMode, SchemeBorder, + SchemeCaps, SchemeLast, }; diff --git a/libs/xresources.h b/libs/xresources.h index 913619c..9179eac 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -29,6 +29,8 @@ ResourcePref resources[] = { { "col_border", STRING, &col_border }, { "col_promptfg", STRING, &col_promptfg }, { "col_promptbg", STRING, &col_promptbg }, + { "col_capsfg", STRING, &col_capsfg }, + { "col_capsbg", STRING, &col_capsbg }, // Alpha { "alpha_itemnormfg", INTEGER, &alpha_itemnormfg }, @@ -59,6 +61,8 @@ ResourcePref resources[] = { { "alpha_caretbg", INTEGER, &alpha_caretbg }, { "alpha_modefg", INTEGER, &alpha_modefg }, { "alpha_modebg", INTEGER, &alpha_modebg }, + { "alpha_capsfg", INTEGER, &alpha_capsfg }, + { "alpha_capsbg", INTEGER, &alpha_capsbg }, // SGR sequence colors { "col_sgr0", STRING, &col_sgr0 }, @@ -82,9 +86,11 @@ ResourcePref resources[] = { { "promptpwlstyle", INTEGER, &promptpwlstyle }, { "matchcountpwlstyle", INTEGER, &matchcountpwlstyle }, { "modepwlstyle", INTEGER, &modepwlstyle }, + { "capspwlstyle", INTEGER, &capspwlstyle }, { "powerlineprompt", INTEGER, &powerlineprompt }, { "powerlinecount", INTEGER, &powerlinecount }, { "powerlinemode", INTEGER, &powerlinemode }, + { "powerlinecaps", INTEGER, &powerlinecaps }, { "dockproperty", INTEGER, &dockproperty }, { "globalcolors", INTEGER, &globalcolors }, { "coloritems", INTEGER, &coloritems }, @@ -122,6 +128,7 @@ ResourcePref resources[] = { { "hidepowerline", INTEGER, &hidepowerline }, { "hidecaret", INTEGER, &hidecaret }, { "hidecursor", INTEGER, &hidecaret }, + { "hidecaps", INTEGER, &hidecaps }, { "histdup", INTEGER, &histdup }, { "casesensitive", INTEGER, &casesensitive }, { "imagewidth", INTEGER, &imagewidth }, @@ -143,6 +150,7 @@ ResourcePref resources[] = { { "pango_rightarrow", INTEGER, &pango_rightarrow }, { "pango_numbers", INTEGER, &pango_numbers }, { "pango_mode", INTEGER, &pango_mode }, + { "pango_caps", INTEGER, &pango_caps }, { "pango_password", INTEGER, &pango_password }, { "pango_highlight", INTEGER, &pango_highlight }, }; @@ -165,13 +173,15 @@ ResourcePref cols[] = { { "color0", STRING, &col_inputbg }, { "color12", STRING, &col_promptbg }, { "color0", STRING, &col_promptfg }, + { "color7", STRING, &col_capsbg }, + { "color0", STRING, &col_capsfg }, { "color6", STRING, &col_itemselbg }, { "color6", STRING, &col_itemselpribg }, { "color6", STRING, &col_border }, { "color0", STRING, &col_numfg }, { "color5", STRING, &col_numbg }, { "color0", STRING, &col_modefg }, - { "color7", STRING, &col_modebg }, + { "color11", STRING, &col_modebg }, { "color2", STRING, &col_hlnormbg }, { "color3", STRING, &col_hlselbg }, { "color0", STRING, &col_hlnormfg }, diff --git a/mouse.h b/mouse.h index 9264d8c..d0caeed 100644 --- a/mouse.h +++ b/mouse.h @@ -12,6 +12,7 @@ * clickrarrow: - Right arrow * clicknumber: - Match count * clickmode: - Mode indicator + * clickcaps: - Caps lock indicator * * Button1 - Left click * Button2 - Middle click diff --git a/options.h b/options.h index 61d8ec2..ddb8b72 100644 --- a/options.h +++ b/options.h @@ -29,9 +29,11 @@ static int managed = 0; /* Let your window manager manage sp static int powerlineprompt = 1; /* Enable powerline for the prompt */ static int powerlinecount = 1; /* Enable powerline for the match count */ static int powerlinemode = 1; /* Enable powerline for the mode indicator */ +static int powerlinecaps = 1; /* Enable powerline for the caps lock indicator */ static int promptpwlstyle = 0; /* Prompt powerline style (0: >, 1: \) */ static int matchcountpwlstyle = 0; /* Match count powerline style (0: <, 1: /) */ static int modepwlstyle = 0; /* Mode indicator powerline style (0: <, 1: /) */ +static int capspwlstyle = 0; /* Caps lock indicator powerline style (0: <, 1: /) */ /* Window properties */ static int dockproperty = 1; /* Set _NET_WM_WINDOW_TYPE_DOCK */ @@ -48,6 +50,8 @@ static int maxcache = 512; /* Max image size to cache */ static int mode = 0; /* Mode to start speedwm in (0: Normal mode, 1: Insert mode) */ static char *normtext = "Normal"; /* Text to display for normal mode */ static char *instext = "Insert"; /* Text to display for insert mode */ +static char *capslockontext = "Caps Lock"; /* Text to display for the caps lock indicator when caps lock is on */ +static char *capslockofftext = ""; /* Text to display for the caps lock indicator when caps lock is off */ /* Window border options */ static int borderwidth = 0; /* Width of the border */ @@ -90,6 +94,7 @@ static int hidelarrow = 0; /* Hide left arrow (0/1) */ static int hiderarrow = 0; /* Hide right arrow (0/1) */ static int hideitem = 0; /* Hide item (0/1) */ static int hideprompt = 0; /* Hide prompt (0/1) */ +static int hidecaps = 0; /* Hide caps lock indicator (0/1) */ static int hidepowerline = 0; /* Hide powerline (0/1) */ static int hidecaret = 0; /* Hide caret (0/1) */ static int hidehighlight = 0; /* Hide highlight (0/1) */ @@ -149,6 +154,10 @@ static char col_caretbg[] = "#222222"; /* Background caret color */ static char col_modefg[] = "#ffffff"; /* Mode text color */ static char col_modebg[] = "#35638A"; /* Mode background color */ +/* Caps lock colors */ +static char col_capsfg[] = "#ffffff"; /* Caps lock text color */ +static char col_capsbg[] = "#45638A"; /* Caps lock background color */ + /* SGR colors */ static char col_sgr0[] = "#000000"; /* SGR color #0 */ static char col_sgr1[] = "#7f0000"; /* SGR color #1 */ @@ -196,11 +205,14 @@ static int alpha_caretfg = 255; /* Alpha for the caret foreground static int alpha_caretbg = 200; /* Alpha for the caret background (0-255) */ static int alpha_modefg = 255; /* Alpha for the mode indicator foreground (0-255) */ static int alpha_modebg = 200; /* Alpha for the mode indicator background (0-255) */ +static int alpha_capsfg = 255; /* Alpha for the caps lock indicator foreground (0-255) */ +static int alpha_capsbg = 200; /* Alpha for the caps lock indicator background (0-255) */ /* Pango options */ static int pango_item = 1; /* Enable support for pango markup for the items */ static int pango_highlight = 1; /* Enable support for pango markup for the highlighting */ static int pango_prompt = 1; /* Enable support for pango markup for the prompt */ +static int pango_caps = 1; /* Enable support for pango markup for the caps lock indicator */ static int pango_input = 1; /* Enable support for pango markup for user input */ static int pango_leftarrow = 0; /* Enable support for pango markup for the left arrow */ static int pango_rightarrow = 0; /* Enable support for pango markup for the right arrow */ diff --git a/spmenu.1 b/spmenu.1 index fa4b59c..fd8f316 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -142,6 +142,12 @@ Set normal mode text to text \f[V]-imt, --insert-mode-text text\f[R] Set insert mode text to text .TP +\f[V]-clon, --caps-lock-on-text text\f[R] +Set caps lock on text to text +.TP +\f[V]-clof, --caps-lock-off-text text\f[R] +Set caps lock off text to text +.TP \f[V]-bw, --border-width width\f[R] Set width of the border to width . 0 will disable the border @@ -209,6 +215,9 @@ Hide highlight \f[V]-hi, --hide-image\f[R] Hide image .TP +\f[V]-hcl, --hide-caps\f[R] +Hide caps lock indicator +.TP \f[V]-sm, --show-mode\f[R] Show mode indicator .TP diff --git a/spmenu.c b/spmenu.c index 292ae5f..c6e76e8 100644 --- a/spmenu.c +++ b/spmenu.c @@ -121,6 +121,7 @@ static char *embed; // keybinds static int numlockmask = 0; +static int capslockstate = 0; // height of each item, menu width, menu height static int bh, mw, mh; diff --git a/themes/dmenu.conf b/themes/dmenu.conf index 0c124df..4ee47fa 100644 --- a/themes/dmenu.conf +++ b/themes/dmenu.conf @@ -121,6 +121,7 @@ spmenu = { highlight = 1; matchcount = 1; mode = 1; + caps = 1; image = 1; } ); diff --git a/themes/legacy/Catppuccin b/themes/legacy/Catppuccin index 27fb40f..d1455ec 100644 --- a/themes/legacy/Catppuccin +++ b/themes/legacy/Catppuccin @@ -31,6 +31,8 @@ spmenu.col_caretfg: #cad3f5 spmenu.col_border: #8AADF4 spmenu.col_modefg: #24273a spmenu.col_modebg: #F5BDE6 +spmenu.col_capsfg: #24273a +spmenu.col_capsbg: #8AADF4 spmenu.col_sgr0: #494D64 spmenu.col_sgr1: #ED8796 spmenu.col_sgr2: #A6DA95 diff --git a/themes/legacy/Cyberpunk-Neon b/themes/legacy/Cyberpunk-Neon index 249a350..a314865 100644 --- a/themes/legacy/Cyberpunk-Neon +++ b/themes/legacy/Cyberpunk-Neon @@ -31,6 +31,8 @@ spmenu.col_caretfg: #0abdc6 spmenu.col_border: #711c91 spmenu.col_modefg: #000b1e spmenu.col_modebg: #d300c4 +spmenu.col_capsfg: #000b1e +spmenu.col_capsbg: #1c61c2 spmenu.col_sgr0: #123e7c spmenu.col_sgr1: #ff0000 spmenu.col_sgr2: #d300c4 diff --git a/themes/legacy/Doom-One b/themes/legacy/Doom-One index 0e084ac..19624e6 100644 --- a/themes/legacy/Doom-One +++ b/themes/legacy/Doom-One @@ -31,6 +31,8 @@ spmenu.col_caretfg: #d7d7d7 spmenu.col_border: #ff6c6b spmenu.col_modefg: #282c34 spmenu.col_modebg: #51afef +spmenu.col_capsfg: #282c34 +spmenu.col_capsbg: #da8548 spmenu.col_sgr0: #1c1f24 spmenu.col_sgr1: #ff6c6b spmenu.col_sgr2: #98be65 diff --git a/themes/legacy/Dracula b/themes/legacy/Dracula index 8d6ee20..3703389 100644 --- a/themes/legacy/Dracula +++ b/themes/legacy/Dracula @@ -31,6 +31,8 @@ spmenu.col_caretfg: #f8f8f2 spmenu.col_border: #ff79c6 spmenu.col_modefg: #282a36 spmenu.col_modebg: #ff79c6 +spmenu.col_capsfg: #282a36 +spmenu.col_capsbg: #8b39fd spmenu.col_sgr0: #000000 spmenu.col_sgr1: #ff5555 spmenu.col_sgr2: #50fa7b diff --git a/themes/legacy/Gruvbox-Dark b/themes/legacy/Gruvbox-Dark index f02f929..ccf51e8 100644 --- a/themes/legacy/Gruvbox-Dark +++ b/themes/legacy/Gruvbox-Dark @@ -31,6 +31,8 @@ spmenu.col_caretfg: #fbf1c7 spmenu.col_border: #d79921 spmenu.col_modefg: #3c3836 spmenu.col_modebg: #d65d0e +spmenu.col_capsfg: #3c3836 +spmenu.col_capsbg: #d3869b spmenu.col_sgr0: #282828 spmenu.col_sgr1: #cc241d spmenu.col_sgr2: #98971a diff --git a/themes/legacy/Nord b/themes/legacy/Nord index 6449895..4241820 100644 --- a/themes/legacy/Nord +++ b/themes/legacy/Nord @@ -4,33 +4,35 @@ ! If you want that, then you may set this to 1. spmenu.globalcolors: 0 -spmenu.col_itemnormfg: #ECEFF4 -spmenu.col_itemnormbg: #2E3440 -spmenu.col_itemselfg: #ECEFF4 -spmenu.col_itemselbg: #BF616A -spmenu.col_itemnormprifg: #ECEFF4 -spmenu.col_itemnormpribg: #3B4252 -spmenu.col_itemselprifg: #ECEFF4 -spmenu.col_itemselpribg: #D08770 -spmenu.col_menu: #2E3440 -spmenu.col_promptfg: #2E3440 -spmenu.col_promptbg: #B48EAD -spmenu.col_larrowfg: #8FBCBB -spmenu.col_rarrowfg: #8FBCBB -spmenu.col_larrowbg: #2E3440 -spmenu.col_rarrowbg: #2E3440 -spmenu.col_inputfg: #ECEFF4 -spmenu.col_inputbg: #2E3440 -spmenu.col_numfg: #2E3440 -spmenu.col_numbg: #A3BE8C -spmenu.col_normhlfg: #88C0D0 -spmenu.col_normhlbg: #2E3440 -spmenu.col_selhlfg: #EBCB8B -spmenu.col_selhlbg: #2E3440 -spmenu.col_caretfg: #D8DEE9 -spmenu.col_border: #5E81AC -spmenu.col_modefg: #2E3440 -spmenu.col_modebg: #81A1C1 +spmenu.col_itemnormfg: #eceff4 +spmenu.col_itemnormbg: #2e3440 +spmenu.col_itemselfg: #eceff4 +spmenu.col_itemselbg: #bf616a +spmenu.col_itemnormprifg: #eceff4 +spmenu.col_itemnormpribg: #3b4252 +spmenu.col_itemselprifg: #eceff4 +spmenu.col_itemselpribg: #d08770 +spmenu.col_menu: #2e3440 +spmenu.col_promptfg: #2e3440 +spmenu.col_promptbg: #b48ead +spmenu.col_larrowfg: #8fbcbb +spmenu.col_rarrowfg: #8fbcbb +spmenu.col_larrowbg: #2e3440 +spmenu.col_rarrowbg: #2e3440 +spmenu.col_inputfg: #eceff4 +spmenu.col_inputbg: #2e3440 +spmenu.col_numfg: #2e3440 +spmenu.col_numbg: #a3be8c +spmenu.col_normhlfg: #88c0d0 +spmenu.col_normhlbg: #2e3440 +spmenu.col_selhlfg: #ebcb8b +spmenu.col_selhlbg: #2e3440 +spmenu.col_caretfg: #d8dee9 +spmenu.col_border: #5e81ac +spmenu.col_modefg: #2e3440 +spmenu.col_modebg: #81a1c1 +spmenu.col_capsfg: #d8dee9 +spmenu.col_capsbg: #8fbcbb spmenu.col_sgr0: #3b4252 spmenu.col_sgr1: #bf616a spmenu.col_sgr2: #a3be8c diff --git a/themes/legacy/Solarized-Dark b/themes/legacy/Solarized-Dark index 3d1d61d..8a5607f 100644 --- a/themes/legacy/Solarized-Dark +++ b/themes/legacy/Solarized-Dark @@ -6,7 +6,7 @@ spmenu.globalcolors: 0 spmenu.col_itemnormfg: #eee8d5 spmenu.col_itemnormbg: #002b36 spmenu.col_itemselfg: #eee8d5 -spmenu.col_itemselbg: #073642 +spmenu.col_itemselbg: #dc322f spmenu.col_itemnormprifg: #eee8d5 spmenu.col_itemnormpribg: #002b36 spmenu.col_itemselprifg: #eee8d5 @@ -30,6 +30,8 @@ spmenu.col_caretfg: #eee8d5 spmenu.col_border: #859900 spmenu.col_modefg: #262626 spmenu.col_modebg: #859900 +spmenu.col_capsfg: #262626 +spmenu.col_capsbg: #2aa198 spmenu.col_sgr0: #073642 spmenu.col_sgr1: #dc322f spmenu.col_sgr2: #859900 diff --git a/themes/legacy/Tokyo-Night b/themes/legacy/Tokyo-Night index 95abd59..a28e6b3 100644 --- a/themes/legacy/Tokyo-Night +++ b/themes/legacy/Tokyo-Night @@ -31,6 +31,8 @@ spmenu.col_caretfg: #a9b1d6 spmenu.col_border: #7da6ff spmenu.col_modefg: #1a1b26 spmenu.col_modebg: #ff7a93 +spmenu.col_capsfg: #1a1b26 +spmenu.col_capsbg: #b9f27c spmenu.col_sgr0: #32344a spmenu.col_sgr1: #f7768e spmenu.col_sgr2: #9ece6a