mouse.c
changeset 31 386649deb651
parent 26 e8f627998d6f
child 41 fc9ccd34b8ab
equal deleted inserted replaced
30:2e0fb4130bfb 31:386649deb651
    10 
    10 
    11 #include "wm.h"
    11 #include "wm.h"
    12 
    12 
    13 #define ButtonMask      (ButtonPressMask | ButtonReleaseMask)
    13 #define ButtonMask      (ButtonPressMask | ButtonReleaseMask)
    14 #define MouseMask       (ButtonMask | PointerMotionMask)
    14 #define MouseMask       (ButtonMask | PointerMotionMask)
    15 
       
    16 static void
       
    17 mmatch(Client *c, int x1, int y1, int x2, int y2)
       
    18 {
       
    19 	c->w = abs(x1 - x2);
       
    20 	c->h = abs(y1 - y2);
       
    21 	if(c->incw)
       
    22 		c->w -= (c->w - c->basew) % c->incw;
       
    23 	if(c->inch)
       
    24 		c->h -= (c->h - c->baseh) % c->inch;
       
    25 	if(c->minw && c->w < c->minw)
       
    26 		c->w = c->minw;
       
    27 	if(c->minh && c->h < c->minh)
       
    28 		c->h = c->minh;
       
    29 	if(c->maxw && c->w > c->maxw)
       
    30 		c->w = c->maxw;
       
    31 	if(c->maxh && c->h > c->maxh)
       
    32 		c->h = c->maxh;
       
    33 	c->x = (x1 <= x2) ? x1 : x1 - c->w;
       
    34 	c->y = (y1 <= y2) ? y1 : y1 - c->h;
       
    35 }
       
    36 
    15 
    37 void
    16 void
    38 mresize(Client *c)
    17 mresize(Client *c)
    39 {
    18 {
    40 	XEvent ev;
    19 	XEvent ev;
    53 		case Expose:
    32 		case Expose:
    54 			handler[Expose](&ev);
    33 			handler[Expose](&ev);
    55 			break;
    34 			break;
    56 		case MotionNotify:
    35 		case MotionNotify:
    57 			XFlush(dpy);
    36 			XFlush(dpy);
    58 			mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
    37 			c->w = abs(old_cx - ev.xmotion.x);
    59 			XResizeWindow(dpy, c->win, c->w, c->h);
    38 			c->h = abs(old_cy - ev.xmotion.y);
       
    39 			c->x = (old_cx <= ev.xmotion.x) ? old_cx : old_cx - c->w;
       
    40 			c->y = (old_cy <= ev.xmotion.y) ? old_cy : old_cy - c->h;
       
    41 			resize(c);
    60 			break;
    42 			break;
    61 		case ButtonRelease:
    43 		case ButtonRelease:
    62 			resize(c);
       
    63 			XUngrabPointer(dpy, CurrentTime);
    44 			XUngrabPointer(dpy, CurrentTime);
    64 			return;
    45 			return;
    65 		}
    46 		}
    66 	}
    47 	}
    67 }
    48 }
    89 			break;
    70 			break;
    90 		case MotionNotify:
    71 		case MotionNotify:
    91 			XFlush(dpy);
    72 			XFlush(dpy);
    92 			c->x = old_cx + (ev.xmotion.x - x1);
    73 			c->x = old_cx + (ev.xmotion.x - x1);
    93 			c->y = old_cy + (ev.xmotion.y - y1);
    74 			c->y = old_cy + (ev.xmotion.y - y1);
    94 			XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
    75 			resize(c);
    95 			break;
    76 			break;
    96 		case ButtonRelease:
    77 		case ButtonRelease:
    97 			resize(c);
       
    98 			XUngrabPointer(dpy, CurrentTime);
    78 			XUngrabPointer(dpy, CurrentTime);
    99 			return;
    79 			return;
   100 		}
    80 		}
   101 	}
    81 	}
   102 }
    82 }