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.

104 lines
2.8 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, 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,
  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. XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height);
  53. XGrabServer(dpy);
  54. break;
  55. case ButtonRelease:
  56. resize(c);
  57. XUngrabServer(dpy);
  58. XUngrabPointer(dpy, CurrentTime);
  59. return;
  60. }
  61. }
  62. }
  63. void
  64. mmove(Client *c)
  65. {
  66. XEvent ev;
  67. int x1, y1, old_cx, old_cy, di;
  68. unsigned int dui;
  69. Window dummy;
  70. old_cx = c->r[RFloat].x;
  71. old_cy = c->r[RFloat].y;
  72. if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
  73. None, cursor[CurMove], CurrentTime) != GrabSuccess)
  74. return;
  75. XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
  76. XGrabServer(dpy);
  77. for(;;) {
  78. XMaskEvent(dpy, MouseMask, &ev);
  79. switch (ev.type) {
  80. default: break;
  81. case MotionNotify:
  82. XUngrabServer(dpy);
  83. c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
  84. c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
  85. XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
  86. c->r[RFloat].width, c->r[RFloat].height);
  87. XGrabServer(dpy);
  88. break;
  89. case ButtonRelease:
  90. resize(c);
  91. XUngrabServer(dpy);
  92. XUngrabPointer(dpy, CurrentTime);
  93. return;
  94. }
  95. }
  96. }