Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

  1. From 95463f58beb669d9221881deac3b6df7d9c4f162 Mon Sep 17 00:00:00 2001
  2. From: Klemens Nanni <kl3@posteo.org>
  3. Date: Fri, 2 Sep 2016 14:53:30 +0200
  4. Subject: [PATCH] Indicate the state of CapsLock through a different color
  5. ---
  6. config.def.h | 1 +
  7. slock.c | 15 ++++++++++++---
  8. 2 files changed, 13 insertions(+), 3 deletions(-)
  9. diff --git a/config.def.h b/config.def.h
  10. index 9855e21..6288856 100644
  11. --- a/config.def.h
  12. +++ b/config.def.h
  13. @@ -6,6 +6,7 @@ static const char *colorname[NUMCOLS] = {
  14. [INIT] = "black", /* after initialization */
  15. [INPUT] = "#005577", /* during input */
  16. [FAILED] = "#CC3333", /* wrong password */
  17. + [CAPS] = "red", /* CapsLock on */
  18. };
  19. /* treat a cleared input like a wrong password (color) */
  20. diff --git a/slock.c b/slock.c
  21. index d55eb3d..d7804f1 100644
  22. --- a/slock.c
  23. +++ b/slock.c
  24. @@ -18,6 +18,7 @@
  25. #include <X11/keysym.h>
  26. #include <X11/Xlib.h>
  27. #include <X11/Xutil.h>
  28. +#include <X11/XKBlib.h>
  29. #include "arg.h"
  30. #include "util.h"
  31. @@ -28,6 +29,7 @@ enum {
  32. INIT,
  33. INPUT,
  34. FAILED,
  35. + CAPS,
  36. NUMCOLS
  37. };
  38. @@ -130,16 +132,20 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
  39. {
  40. XRRScreenChangeNotifyEvent *rre;
  41. char buf[32], passwd[256], *inputhash;
  42. - int num, screen, running, failure, oldc;
  43. - unsigned int len, color;
  44. + int caps, num, screen, running, failure, oldc;
  45. + unsigned int len, color, indicators;
  46. KeySym ksym;
  47. XEvent ev;
  48. len = 0;
  49. + caps = 0;
  50. running = 1;
  51. failure = 0;
  52. oldc = INIT;
  53. + if (!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators))
  54. + caps = indicators & 1;
  55. +
  56. while (running && !XNextEvent(dpy, &ev)) {
  57. if (ev.type == KeyPress) {
  58. explicit_bzero(&buf, sizeof(buf));
  59. @@ -179,6 +185,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
  60. if (len)
  61. passwd[len--] = '\0';
  62. break;
  63. + case XK_Caps_Lock:
  64. + caps = !caps;
  65. + break;
  66. default:
  67. if (num && !iscntrl((int)buf[0]) &&
  68. (len + num < sizeof(passwd))) {
  69. @@ -187,7 +196,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
  70. }
  71. break;
  72. }
  73. - color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
  74. + color = len ? (caps ? CAPS : INPUT) : (failure || failonclear ? FAILED : INIT);
  75. if (running && oldc != color) {
  76. for (screen = 0; screen < nscreens; screen++) {
  77. XSetWindowBackground(dpy,
  78. --
  79. 2.11.0