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.

148 lines
3.7 KiB

18 years ago
18 years ago
18 years ago
18 years ago
  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, spawn, { .argv = term } },
  19. { Mod1Mask, XK_w, spawn, { .argv = browse } },
  20. { Mod1Mask, XK_l, spawn, { .argv = xlock } },
  21. { Mod1Mask, XK_k, prevc, { 0 } },
  22. { Mod1Mask, XK_j, nextc, { 0 } },
  23. { Mod1Mask, XK_m, max, { 0 } },
  24. { Mod1Mask, XK_0, view, { .i = Tscratch } },
  25. { Mod1Mask, XK_1, view, { .i = Tdev } },
  26. { Mod1Mask, XK_2, view, { .i = Tirc } },
  27. { Mod1Mask, XK_3, view, { .i = Twww } },
  28. { Mod1Mask, XK_4, view, { .i = Twork } },
  29. { Mod1Mask, XK_space, tiling, { 0 } },
  30. { Mod1Mask | ShiftMask, XK_Return, zoom, { 0 } },
  31. { Mod1Mask | ShiftMask, XK_space, floating, { 0 } },
  32. { Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } },
  33. { Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } },
  34. { Mod1Mask | ShiftMask, XK_2, tag, { .i = Tirc } },
  35. { Mod1Mask | ShiftMask, XK_3, tag, { .i = Twww } },
  36. { Mod1Mask | ShiftMask, XK_4, tag, { .i = Twork } },
  37. { Mod1Mask | ShiftMask, XK_c, ckill, { 0 } },
  38. { Mod1Mask | ShiftMask, XK_q, quit, { 0 } },
  39. };
  40. /********** CUSTOMIZE **********/
  41. void
  42. update_keys(void)
  43. {
  44. static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
  45. unsigned int i;
  46. KeyCode code;
  47. for(i = 0; i < len; i++) {
  48. code = XKeysymToKeycode(dpy, key[i].keysym);
  49. XUngrabKey(dpy, code, key[i].mod, root);
  50. XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
  51. }
  52. }
  53. void
  54. keypress(XEvent *e)
  55. {
  56. XKeyEvent *ev = &e->xkey;
  57. static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
  58. unsigned int i;
  59. KeySym keysym;
  60. keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
  61. for(i = 0; i < len; i++)
  62. if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
  63. if(key[i].func)
  64. key[i].func(&key[i].arg);
  65. return;
  66. }
  67. }
  68. #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
  69. #define MouseMask (ButtonMask | PointerMotionMask)
  70. void
  71. mresize(Client *c)
  72. {
  73. XEvent ev;
  74. int ocx, ocy;
  75. ocx = c->x;
  76. ocy = c->y;
  77. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  78. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  79. return;
  80. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
  81. for(;;) {
  82. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  83. switch(ev.type) {
  84. default: break;
  85. case Expose:
  86. handler[Expose](&ev);
  87. break;
  88. case MotionNotify:
  89. XFlush(dpy);
  90. c->w = abs(ocx - ev.xmotion.x);
  91. c->h = abs(ocy - ev.xmotion.y);
  92. c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
  93. c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
  94. resize(c, True);
  95. break;
  96. case ButtonRelease:
  97. XUngrabPointer(dpy, CurrentTime);
  98. return;
  99. }
  100. }
  101. }
  102. void
  103. mmove(Client *c)
  104. {
  105. XEvent ev;
  106. int x1, y1, ocx, ocy, di;
  107. unsigned int dui;
  108. Window dummy;
  109. ocx = c->x;
  110. ocy = c->y;
  111. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  112. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  113. return;
  114. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  115. for(;;) {
  116. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  117. switch (ev.type) {
  118. default: break;
  119. case Expose:
  120. handler[Expose](&ev);
  121. break;
  122. case MotionNotify:
  123. XFlush(dpy);
  124. c->x = ocx + (ev.xmotion.x - x1);
  125. c->y = ocy + (ev.xmotion.y - y1);
  126. resize(c, False);
  127. break;
  128. case ButtonRelease:
  129. XUngrabPointer(dpy, CurrentTime);
  130. return;
  131. }
  132. }
  133. }