aewl

annotate mouse.c @ 18:1efa34c6e1b6

added mouse-based resizals
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 21:24:10 +0200
parents
children b5510d0c6d43
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@18 19 c->r[RFloat].width = abs(x1 - x2);
garbeam@18 20 c->r[RFloat].height = abs(y1 - y2);
garbeam@18 21 c->r[RFloat].width -=
garbeam@18 22 (c->r[RFloat].width - c->size.base_width) % c->size.width_inc;
garbeam@18 23 c->r[RFloat].height -=
garbeam@18 24 (c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
garbeam@18 25 if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
garbeam@18 26 c->r[RFloat].width = c->size.min_width;
garbeam@18 27 if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
garbeam@18 28 c->r[RFloat].height = c->size.min_height;
garbeam@18 29 if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
garbeam@18 30 c->r[RFloat].width = c->size.max_width;
garbeam@18 31 if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
garbeam@18 32 c->r[RFloat].height = c->size.max_height;
garbeam@18 33 c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
garbeam@18 34 c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
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@18 43 old_cx = c->r[RFloat].x;
garbeam@18 44 old_cy = c->r[RFloat].y;
garbeam@18 45 if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@18 46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
garbeam@18 47 return;
garbeam@18 48 XGrabServer(dpy);
garbeam@18 49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
garbeam@18 50 c->r[RFloat].width, c->r[RFloat].height);
garbeam@18 51 for(;;) {
garbeam@18 52 XMaskEvent(dpy, MouseMask, &ev);
garbeam@18 53 switch(ev.type) {
garbeam@18 54 default: break;
garbeam@18 55 case MotionNotify:
garbeam@18 56 XUngrabServer(dpy);
garbeam@18 57 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
garbeam@18 58 resize(c);
garbeam@18 59 XGrabServer(dpy);
garbeam@18 60 break;
garbeam@18 61 case ButtonRelease:
garbeam@18 62 XUngrabPointer(dpy, CurrentTime);
garbeam@18 63 return;
garbeam@18 64 }
garbeam@18 65 }
garbeam@18 66 }
garbeam@18 67
garbeam@18 68 void
garbeam@18 69 mmove(Client *c)
garbeam@18 70 {
garbeam@18 71 XEvent ev;
garbeam@18 72 int x1, y1, old_cx, old_cy, di;
garbeam@18 73 unsigned int dui;
garbeam@18 74 Window dummy;
garbeam@18 75
garbeam@18 76 old_cx = c->r[RFloat].x;
garbeam@18 77 old_cy = c->r[RFloat].y;
garbeam@18 78 if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@18 79 None, cursor[CurMove], CurrentTime) != GrabSuccess)
garbeam@18 80 return;
garbeam@18 81 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
garbeam@18 82 XGrabServer(dpy);
garbeam@18 83 for(;;) {
garbeam@18 84 XMaskEvent(dpy, MouseMask, &ev);
garbeam@18 85 switch (ev.type) {
garbeam@18 86 default: break;
garbeam@18 87 case MotionNotify:
garbeam@18 88 XUngrabServer(dpy);
garbeam@18 89 c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
garbeam@18 90 c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
garbeam@18 91 resize(c);
garbeam@18 92 XGrabServer(dpy);
garbeam@18 93 break;
garbeam@18 94 case ButtonRelease:
garbeam@18 95 XUngrabServer(dpy);
garbeam@18 96 XUngrabPointer(dpy, CurrentTime);
garbeam@18 97 return;
garbeam@18 98 }
garbeam@18 99 }
garbeam@18 100 }