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. XGrabServer(dpy);
  43. XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
  44. for(;;) {
  45. XMaskEvent(dpy, MouseMask, &ev);
  46. switch(ev.type) {
  47. default: break;
  48. case MotionNotify:
  49. XUngrabServer(dpy);
  50. mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
  51. XResizeWindow(dpy, c->win, c->w, c->h);
  52. XGrabServer(dpy);
  53. break;
  54. case ButtonRelease:
  55. resize(c);
  56. XUngrabServer(dpy);
  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. XGrabServer(dpy);
  76. for(;;) {
  77. XMaskEvent(dpy, MouseMask, &ev);
  78. switch (ev.type) {
  79. default: break;
  80. case MotionNotify:
  81. XUngrabServer(dpy);
  82. c->x = old_cx + (ev.xmotion.x - x1);
  83. c->y = old_cy + (ev.xmotion.y - y1);
  84. XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
  85. XGrabServer(dpy);
  86. break;
  87. case ButtonRelease:
  88. resize(c);
  89. XUngrabServer(dpy);
  90. XUngrabPointer(dpy, CurrentTime);
  91. return;
  92. }
  93. }
  94. }