Configuration of dwm for Mac Computers
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.

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