Configuration file for DWM on MacBook Air
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.

102 lines
2.3 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * (C)opyright MMVI Kris Maglione <fbsdaemon@gmail.com>
  4. * See LICENSE file for license details.
  5. */
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <unistd.h>
  9. #include "wm.h"
  10. #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
  11. #define MouseMask (ButtonMask | PointerMotionMask)
  12. static void
  13. mmatch(Client *c, int x1, int y1, int x2, int y2)
  14. {
  15. c->w = abs(x1 - x2);
  16. c->h = abs(y1 - y2);
  17. if(c->incw)
  18. c->w -= (c->w - c->basew) % c->incw;
  19. if(c->inch)
  20. c->h -= (c->h - c->baseh) % c->inch;
  21. if(c->minw && c->w < c->minw)
  22. c->w = c->minw;
  23. if(c->minh && c->h < c->minh)
  24. c->h = c->minh;
  25. if(c->maxw && c->w > c->maxw)
  26. c->w = c->maxw;
  27. if(c->maxh && c->h > c->maxh)
  28. c->h = c->maxh;
  29. c->x = (x1 <= x2) ? x1 : x1 - c->w;
  30. c->y = (y1 <= y2) ? y1 : y1 - c->h;
  31. }
  32. void
  33. mresize(Client *c)
  34. {
  35. XEvent ev;
  36. int old_cx, old_cy;
  37. old_cx = c->x;
  38. old_cy = c->y;
  39. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  40. None, cursor[CurResize], CurrentTime) != GrabSuccess)
  41. return;
  42. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
  43. for(;;) {
  44. XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
  45. switch(ev.type) {
  46. default: break;
  47. case Expose:
  48. handler[Expose](&ev);
  49. break;
  50. case MotionNotify:
  51. XFlush(dpy);
  52. mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
  53. XResizeWindow(dpy, c->win, c->w, c->h);
  54. break;
  55. case ButtonRelease:
  56. resize(c);
  57. XUngrabPointer(dpy, CurrentTime);
  58. return;
  59. }
  60. }
  61. }
  62. void
  63. mmove(Client *c)
  64. {
  65. XEvent ev;
  66. int x1, y1, old_cx, old_cy, di;
  67. unsigned int dui;
  68. Window dummy;
  69. old_cx = c->x;
  70. old_cy = c->y;
  71. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  72. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  73. return;
  74. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  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->x = old_cx + (ev.xmotion.x - x1);
  85. c->y = old_cy + (ev.xmotion.y - y1);
  86. XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
  87. break;
  88. case ButtonRelease:
  89. resize(c);
  90. XUngrabPointer(dpy, CurrentTime);
  91. return;
  92. }
  93. }
  94. }