aewl

annotate mouse.c @ 30:2e0fb4130bfb

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