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.

100 lines
2.6 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->r[RFloat].width = abs(x1 - x2);
  16. c->r[RFloat].height = abs(y1 - y2);
  17. c->r[RFloat].width -=
  18. (c->r[RFloat].width - c->size.base_width) % c->size.width_inc;
  19. c->r[RFloat].height -=
  20. (c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
  21. if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
  22. c->r[RFloat].width = c->size.min_width;
  23. if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
  24. c->r[RFloat].height = c->size.min_height;
  25. if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
  26. c->r[RFloat].width = c->size.max_width;
  27. if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
  28. c->r[RFloat].height = c->size.max_height;
  29. c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
  30. c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
  31. }
  32. void
  33. mresize(Client *c)
  34. {
  35. XEvent ev;
  36. int old_cx, old_cy;
  37. old_cx = c->r[RFloat].x;
  38. old_cy = c->r[RFloat].y;
  39. if(XGrabPointer(dpy, c->win, 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,
  44. c->r[RFloat].width, c->r[RFloat].height);
  45. for(;;) {
  46. XMaskEvent(dpy, MouseMask, &ev);
  47. switch(ev.type) {
  48. default: break;
  49. case MotionNotify:
  50. XUngrabServer(dpy);
  51. mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
  52. resize(c);
  53. XGrabServer(dpy);
  54. break;
  55. case ButtonRelease:
  56. XUngrabPointer(dpy, CurrentTime);
  57. return;
  58. }
  59. }
  60. }
  61. void
  62. mmove(Client *c)
  63. {
  64. XEvent ev;
  65. int x1, y1, old_cx, old_cy, di;
  66. unsigned int dui;
  67. Window dummy;
  68. old_cx = c->r[RFloat].x;
  69. old_cy = c->r[RFloat].y;
  70. if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync,
  71. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  72. return;
  73. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  74. XGrabServer(dpy);
  75. for(;;) {
  76. XMaskEvent(dpy, MouseMask, &ev);
  77. switch (ev.type) {
  78. default: break;
  79. case MotionNotify:
  80. XUngrabServer(dpy);
  81. c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
  82. c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
  83. resize(c);
  84. XGrabServer(dpy);
  85. break;
  86. case ButtonRelease:
  87. XUngrabServer(dpy);
  88. XUngrabPointer(dpy, CurrentTime);
  89. return;
  90. }
  91. }
  92. }