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.

137 lines
3.1 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "dwm.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. #include <X11/keysym.h>
  10. /********** CUSTOMIZE **********/
  11. const char *term[] = {
  12. "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
  13. "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
  14. };
  15. const char *browse[] = { "firefox", NULL };
  16. const char *xlock[] = { "xlock", NULL };
  17. static Key key[] = {
  18. { Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
  19. { Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
  20. { Mod1Mask, XK_l, (void (*)(void *))spawn, xlock },
  21. { Mod1Mask, XK_k, sel, "prev" },
  22. { Mod1Mask, XK_j, sel, "next" },
  23. { Mod1Mask, XK_t, tiling, NULL },
  24. { Mod1Mask, XK_f, tiling, NULL },
  25. { Mod1Mask, XK_m, max, NULL },
  26. { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
  27. { Mod1Mask | ShiftMask, XK_q, quit, NULL },
  28. };
  29. /********** CUSTOMIZE **********/
  30. void
  31. update_keys(void)
  32. {
  33. unsigned int i, len;
  34. KeyCode code;
  35. len = sizeof(key) / sizeof(key[0]);
  36. for(i = 0; i < len; i++) {
  37. code = XKeysymToKeycode(dpy, key[i].keysym);
  38. XUngrabKey(dpy, code, key[i].mod, root);
  39. XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
  40. }
  41. }
  42. void
  43. keypress(XEvent *e)
  44. {
  45. XKeyEvent *ev = &e->xkey;
  46. unsigned int i, len;
  47. KeySym keysym;
  48. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  49. len = sizeof(key) / sizeof(key[0]);
  50. for(i = 0; i < len; i++)
  51. if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
  52. if(key[i].func)
  53. key[i].func(key[i].aux);
  54. return;
  55. }
  56. }
  57. #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
  58. #define MouseMask (ButtonMask | PointerMotionMask)
  59. void
  60. mresize(Client *c)
  61. {
  62. XEvent ev;
  63. int ocx, ocy;
  64. ocx = c->x;
  65. ocy = c->y;
  66. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  67. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  68. return;
  69. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
  70. for(;;) {
  71. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  72. switch(ev.type) {
  73. default: break;
  74. case Expose:
  75. handler[Expose](&ev);
  76. break;
  77. case MotionNotify:
  78. XFlush(dpy);
  79. c->w = abs(ocx - ev.xmotion.x);
  80. c->h = abs(ocy - ev.xmotion.y);
  81. c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
  82. c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
  83. resize(c);
  84. break;
  85. case ButtonRelease:
  86. XUngrabPointer(dpy, CurrentTime);
  87. return;
  88. }
  89. }
  90. }
  91. void
  92. mmove(Client *c)
  93. {
  94. XEvent ev;
  95. int x1, y1, ocx, ocy, di;
  96. unsigned int dui;
  97. Window dummy;
  98. ocx = c->x;
  99. ocy = c->y;
  100. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  101. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  102. return;
  103. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  104. for(;;) {
  105. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  106. switch (ev.type) {
  107. default: break;
  108. case Expose:
  109. handler[Expose](&ev);
  110. break;
  111. case MotionNotify:
  112. XFlush(dpy);
  113. c->x = ocx + (ev.xmotion.x - x1);
  114. c->y = ocy + (ev.xmotion.y - y1);
  115. resize(c);
  116. break;
  117. case ButtonRelease:
  118. XUngrabPointer(dpy, CurrentTime);
  119. return;
  120. }
  121. }
  122. }