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.

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