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.

59 lines
1.4 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "wm.h"
  6. #include <X11/keysym.h>
  7. static const char *term[] = {
  8. "xterm", "-bg", "black", "-fg", "white", "-fn",
  9. "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0
  10. };
  11. static const char *proglist[] = {
  12. "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null "
  13. "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0
  14. };
  15. static Key key[] = {
  16. { Mod1Mask, XK_Return, run, term },
  17. { Mod1Mask, XK_p, run, proglist },
  18. { Mod1Mask, XK_k, sel, "prev" },
  19. { Mod1Mask, XK_j, sel, "next" },
  20. { Mod1Mask, XK_g, arrange, NULL },
  21. { Mod1Mask | ShiftMask, XK_c, kill, NULL },
  22. { Mod1Mask | ShiftMask, XK_q, quit, NULL },
  23. };
  24. void
  25. update_keys()
  26. {
  27. unsigned int i, len;
  28. KeyCode code;
  29. len = sizeof(key) / sizeof(key[0]);
  30. for(i = 0; i < len; i++) {
  31. code = XKeysymToKeycode(dpy, key[i].keysym);
  32. XUngrabKey(dpy, code, key[i].mod, root);
  33. XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
  34. }
  35. }
  36. void
  37. keypress(XEvent *e)
  38. {
  39. XKeyEvent *ev = &e->xkey;
  40. unsigned int i, len;
  41. KeySym keysym;
  42. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  43. len = sizeof(key) / sizeof(key[0]);
  44. for(i = 0; i < len; i++)
  45. if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
  46. if(key[i].func)
  47. key[i].func(key[i].aux);
  48. return;
  49. }
  50. }