[hackers] [wmii] Ameliorate the mouse.c rat's nest.

From: Kris Maglione <jg_AT_suckless.org>
Date: Wed Jan 23 06:18:35 2008

changeset: 2255:f8a79755e0f5
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Jan 23 00:13:33 2008 -0500
summary: Ameliorate the mouse.c rat's nest.

diff -r 7e260e5ef3f5 -r f8a79755e0f5 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Tue Jan 22 21:21:59 2008 -0500
+++ b/cmd/wmii/fns.h Wed Jan 23 00:13:33 2008 -0500
@@ -185,7 +185,8 @@ void vdebug(int, const char*, va_list);
 void vdebug(int, const char*, va_list);
 
 /* mouse.c */
-void mouse_resize(Client*, bool opaque, Align);
+void mouse_movegrabbox(Client*);
+void mouse_resize(Client*, Align);
 void mouse_resizecol(Divide*);
 void grab_button(XWindow, uint button, ulong mod);
 Align snap_rect(Rectangle *rects, int num, Rectangle *current, Align *mask, int snapw);
diff -r 7e260e5ef3f5 -r f8a79755e0f5 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Tue Jan 22 21:21:59 2008 -0500
+++ b/cmd/wmii/frame.c Wed Jan 23 00:13:33 2008 -0500
@@ -154,7 +154,7 @@ bdown_event(Window *w, XButtonEvent *e)
                 switch(e->button) {
                 case Button1:
                         focus(c, false);
- mouse_resize(c, false, Center);
+ mouse_resize(c, Center);
                         break;
                 case Button2:
                         frame_restack(f, nil);
@@ -163,7 +163,7 @@ bdown_event(Window *w, XButtonEvent *e)
                         break;
                 case Button3:
                         focus(c, false);
- mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root)));
+ mouse_resize(c, quadrant(f->r, Pt(e->x_root, e->y_root)));
                         break;
                 default:
                         XAllowEvents(display, ReplayPointer, e->time);
@@ -178,10 +178,10 @@ bdown_event(Window *w, XButtonEvent *e)
                                 view_restack(f->view);
                         }
                         if(rect_haspoint_p(Pt(e->x, e->y), f->grabbox))
- mouse_resize(c, true, Center);
+ mouse_movegrabbox(c);
                         else if(f->area->floating)
                                 if(!e->subwindow && !rect_haspoint_p(Pt(e->x, e->y), f->titlebar))
- mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root)));
+ mouse_resize(c, quadrant(f->r, Pt(e->x_root, e->y_root)));
 
                         if(f->client != selclient())
                                 focus(c, false);
diff -r 7e260e5ef3f5 -r f8a79755e0f5 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Tue Jan 22 21:21:59 2008 -0500
+++ b/cmd/wmii/mouse.c Wed Jan 23 00:13:33 2008 -0500
@@ -46,7 +46,7 @@ framerect(Framewin *f) {
                 r = rectsubpt(r, Pt(Dx(r)/2, 0));
         }
         r = rectaddpt(r, f->pt);
-
+
         /* Keep onscreen */
         p = ZP;
         p.x -= min(0, r.min.x);
@@ -68,9 +68,11 @@ framewin(Frame *f, Point pt, int orienta
         Framewin *fw;
 
         fw = emallocz(sizeof *fw);
- wa.override_redirect = True;
+ wa.override_redirect = true;
         wa.event_mask = ExposureMask;
- fw->w = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput, &wa, CWEventMask);
+ fw->w = createwindow(&scr.root, Rect(0, 0, 1, 1),
+ scr.depth, InputOutput,
+ &wa, CWEventMask);
         fw->w->aux = fw;
         sethandler(fw->w, &handlers);
 
@@ -224,149 +226,6 @@ hplace(Framewin *fw, Point pt) {
         pt.y = a->r.min.y;
         frameadjust(fw, pt, OVert, Dy(a->r));
         reshapewin(fw->w, framerect(fw));
-}
-
-static void
-do_managed_move(Client *c) {
- Rectangle r;
- WinAttr wa;
- XEvent ev;
- Framewin *fw;
- Window *cwin;
- Frame *f, *fprev, *fnext;
- Point pt, pt2;
- int y;
-
- focus(c, false);
- f = c->sel;
-
- pt = querypointer(&scr.root);
-
- pt2.x = f->area->r.min.x;
- pt2.y = pt.y;
- fw = framewin(f, pt2, OHoriz, Dx(f->area->r));
-
- r = screen->r;
- r.min.y += fw->grabbox.min.y + Dy(fw->grabbox)/2;
- r.max.y = r.min.y + 1;
- cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
- mapwin(cwin);
-
-horiz:
- ungrabpointer();
- if(!grabpointer(&scr.root, nil, cursor[CurIcon], MouseMask))
- goto done;
- warppointer(pt);
- vplace(fw, pt);
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- pt.x = ev.xmotion.x_root;
- pt.y = ev.xmotion.y_root;
-
- vplace(fw, pt);
- break;
- case ButtonRelease:
- switch(ev.xbutton.button) {
- case 1:
- /* TODO: Fix... Tangled, broken mess. */
- fprev = f->aprev;
- fnext = f->anext;
- column_remove(f);
- if(fnext
- && (!fprev || (fw->fprev != fprev)
- && (fw->fprev != fprev->aprev))) {
- fnext->r.min.y = f->r.min.y;
- frame_resize(fnext, fnext->r);
- }
- else if(fprev) {
- if(fw->fprev == fprev->aprev) {
- fw->fprev = fprev->aprev;
- fprev->r = f->r;
- }else
- fprev->r.max.y = f->r.max.y;
- frame_resize(fprev, fprev->r);
- }
-
- column_insert(fw->ra, f, fw->fprev);
-
- r = fw->fprev_r;
- if(f->aprev) {
- f->aprev->r.max.y = r.min.y;
- frame_resize(f->aprev, f->aprev->r);
- }else
- r.min.y = f->area->r.min.y;
-
- if(f->anext)
- r.max.y = f->anext->r.min.y;
- else
- r.max.y = f->area->r.max.y;
-
- frame_resize(f, fw->fprev_r);
-
- view_arrange(f->view);
- goto done;
- }
- break;
- case ButtonPress:
- switch(ev.xbutton.button) {
- case 2:
- goto vert;
- }
- break;
- }
- }
-vert:
- y = pt.y;
- ungrabpointer();
- if(!grabpointer(&scr.root, cwin, cursor[CurIcon], MouseMask))
- goto done;
- hplace(fw, pt);
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- pt.x = ev.xmotion.x_root;
- pt.y = ev.xmotion.y_root;
-
- hplace(fw, pt);
- break;
- case ButtonRelease:
- switch(ev.xbutton.button) {
- case 1:
- if(fw->ra) {
- fw->ra = column_new(f->view, fw->ra, 0);
- area_moveto(fw->ra, f);
- view_arrange(f->view); /* I hate this. */
- }
- goto done;
- case 2:
- pt.y = y;
- goto horiz;
- }
- break;
- }
- }
-done:
- ungrabpointer();
- framedestroy(fw);
- destroywindow(cwin);
-
- pt = addpt(f->r.min, f->grabbox.min);
- pt.x += Dx(f->grabbox)/2;
- pt.y += Dy(f->grabbox)/2;
- warppointer(pt);
 }
 
 static Window*
@@ -379,193 +238,6 @@ gethsep(Rectangle r) {
         mapwin(w);
         raisewin(w);
         return w;
-}
-
-static void
-mouse_resizecolframe(Frame *f, Align align) {
- WinAttr wa;
- XEvent ev;
- Window *cwin, *hwin;
- Divide *d;
- View *v;
- Area *a;
- Rectangle r;
- Point pt, min;
-
- assert((align&(East|West)) != (East|West));
- assert((align&(North|South)) != (North|South));
-
- v = screen->sel;
- for(a = v->area->next, d = divs; a; a = a->next, d = d->next)
- if(a == f->area) break;
-
- if(align&East)
- d = d->next;
-
- min.x = Dx(v->r)/NCOL;
- min.y = /*frame_delta_h() +*/ labelh(def.font);
- if(align&North) {
- if(f->aprev) {
- r.min.y = f->aprev->r.min.y + min.y;
- r.max.y = f->r.max.y - min.y;
- }else {
- r.min.y = a->r.min.y;
- r.max.y = r.min.y + 1;
- }
- }else {
- if(f->anext) {
- r.max.y = f->anext->r.max.y - min.y;
- r.min.y = f->r.min.y + min.y;
- }else {
- r.max.y = a->r.max.y;
- r.min.y = r.max.y - 1;
- }
- }
- if(align&West) {
- if(a->prev != v->area) {
- r.min.x = a->prev->r.min.x + min.x;
- r.max.x = a->r.max.x - min.x;
- }else {
- r.min.x = a->r.min.x;
- r.max.x = r.min.x + 1;
- }
- }else {
- if(a->next) {
- r.max.x = a->next->r.max.x - min.x;
- r.min.x = a->r.min.x + min.x;
- }else {
- r.max.x = a->r.max.x;
- r.min.x = r.max.x - 1;
- }
- }
-
- cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
- mapwin(cwin);
-
- r = f->r;
- if(align&North)
- r.min.y--;
- else
- r.min.y = r.max.y - 1;
- r.max.y = r.min.y + 2;
-
- hwin = gethsep(r);
-
- if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
- goto done;
-
- pt.x = ((align&West) ? f->r.min.x : f->r.max.x);
- pt.y = ((align&North) ? f->r.min.y : f->r.max.y);
- warppointer(pt);
-
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- pt.x = ev.xmotion.x_root;
- pt.y = ev.xmotion.y_root;
-
- if(align&West)
- r.min.x = pt.x;
- else
- r.max.x = pt.x;
- r.min.y = ((align&South) ? pt.y : pt.y-1);
- r.max.y = r.min.y+2;
-
- div_set(d, pt.x);
- reshapewin(hwin, r);
- break;
- case ButtonRelease:
- r = f->r;
- if(align&West)
- r.min.x = pt.x;
- else
- r.max.x = pt.x;
- if(align&North)
- r.min.y = pt.y;
- else
- r.max.y = pt.y;
- column_resizeframe(f, r);
-
- /* XXX: Magic number... */
- if(align&West)
- pt.x = f->r.min.x + 4;
- else
- pt.x = f->r.max.x - 4;
- if(align&North)
- pt.y = f->r.min.y + 4;
- else
- pt.y = f->r.max.y - 4;
- warppointer(pt);
- goto done;
- }
- }
-done:
- ungrabpointer();
- destroywindow(cwin);
- destroywindow(hwin);
-}
-
-void
-mouse_resizecol(Divide *d) {
- WinAttr wa;
- XEvent ev;
- Window *cwin;
- Divide *dp;
- View *v;
- Area *a;
- Rectangle r;
- Point pt;
- uint minw;
-
- v = screen->sel;
-
- for(a = v->area->next, dp = divs; a; a = a->next, dp = dp->next)
- if(dp->next == d) break;
-
- /* Fix later */
- if(a == nil || a->next == nil)
- return;
-
- pt = querypointer(&scr.root);
-
- minw = Dx(v->r)/NCOL;
- r.min.x = a->r.min.x + minw;
- r.max.x = a->next->r.max.x - minw;
- r.min.y = pt.y;
- r.max.y = pt.y+1;
-
- cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
- mapwin(cwin);
-
- if(!grabpointer(&scr.root, cwin, cursor[CurNone], MouseMask))
- goto done;
-
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- pt.x = ev.xmotion.x_root;
- div_set(d, pt.x);
- break;
- case ButtonRelease:
- column_resize(a, pt.x - a->r.min.x);
- goto done;
- }
- }
-done:
- ungrabpointer();
- destroywindow(cwin);
 }
 
 static void
@@ -672,24 +344,383 @@ snap_rect(Rectangle *rects, int num, Rec
         return ret ^ *mask;
 }
 
-/* Grumble... Messy... TODO: Rewrite. */
+static int
+readmouse(Point *p, uint *button) {
+ XEvent ev;
+
+ for(;;) {
+ XMaskEvent(display, MouseMask|ExposureMask, &ev);
+ switch(ev.type) {
+ case Expose:
+ dispatch_event(&ev);
+ default:
+ continue;
+ case ButtonPress:
+ case ButtonRelease:
+ *button = ev.xbutton.button;
+ case MotionNotify:
+ p->x = ev.xmotion.x_root;
+ p->y = ev.xmotion.y_root;
+ break;
+ }
+ return ev.type;
+ }
+}
+
+static bool
+readmotion(Point *p) {
+ uint button;
+
+ for(;;)
+ switch(readmouse(p, &button)) {
+ case MotionNotify:
+ return true;
+ case ButtonRelease:
+ return false;
+ }
+}
+
+static void
+do_managed_move(Client *c) {
+ Rectangle r;
+ WinAttr wa;
+ Framewin *fw;
+ Window *cwin;
+ Frame *f, *fprev, *fnext;
+ Area *a;
+ Point pt, pt2;
+ uint button;
+ int y;
+
+ focus(c, false);
+ f = c->sel;
+
+ pt = querypointer(&scr.root);
+
+ pt2.x = f->area->r.min.x;
+ pt2.y = pt.y;
+ fw = framewin(f, pt2, OHoriz, Dx(f->area->r));
+
+ r = screen->r;
+ r.min.y += fw->grabbox.min.y + Dy(fw->grabbox)/2;
+ r.max.y = r.min.y + 1;
+ cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
+ mapwin(cwin);
+
+horiz:
+ ungrabpointer();
+ if(!grabpointer(&scr.root, nil, cursor[CurIcon], MouseMask))
+ goto done;
+
+ warppointer(pt);
+ vplace(fw, pt);
+ for(;;)
+ switch (readmouse(&pt, &button)) {
+ case MotionNotify:
+ vplace(fw, pt);
+ break;
+ case ButtonRelease:
+ if(button != 1)
+ continue;
+ /* TODO: Fix... Tangled, broken mess. */
+ fprev = f->aprev;
+ fnext = f->anext;
+ a = f->area;
+ column_remove(f);
+ if(fnext
+ && (!fprev || (fw->fprev != fprev)
+ && (fw->fprev != fprev->aprev))) {
+ fnext->r.min.y = f->r.min.y;
+ frame_resize(fnext, fnext->r);
+ }
+ else if(fprev) {
+ if(fw->fprev == fprev->aprev) {
+ fw->fprev = fprev->aprev;
+ fprev->r = f->r;
+ }else
+ fprev->r.max.y = f->r.max.y;
+ frame_resize(fprev, fprev->r);
+ }
+
+ column_insert(fw->ra, f, fw->fprev);
+
+ r = fw->fprev_r;
+ if(f->aprev) {
+ f->aprev->r.max.y = r.min.y;
+ frame_resize(f->aprev, f->aprev->r);
+ }else
+ r.min.y = f->area->r.min.y;
+
+ if(f->anext)
+ r.max.y = f->anext->r.min.y;
+ else
+ r.max.y = f->area->r.max.y;
+
+ frame_resize(f, fw->fprev_r);
+
+ if(!a->frame)
+ area_destroy(a);
+ view_arrange(f->view);
+ goto done;
+ case ButtonPress:
+ if(button == 2)
+ goto vert;
+ continue;
+ }
+vert:
+ y = pt.y;
+ ungrabpointer();
+ if(!grabpointer(&scr.root, cwin, cursor[CurIcon], MouseMask))
+ goto done;
+ hplace(fw, pt);
+ for(;;)
+ switch (readmouse(&pt, &button)) {
+ case MotionNotify:
+ hplace(fw, pt);
+ continue;
+ case ButtonPress:
+ if(button == 2) {
+ pt.y = y;
+ goto horiz;
+ }
+ continue;
+ case ButtonRelease:
+ if(button != 1)
+ continue;
+ if(fw->ra) {
+ fw->ra = column_new(f->view, fw->ra, 0);
+ area_moveto(fw->ra, f);
+ view_arrange(f->view); /* I hate this. */
+ }
+ goto done;
+ }
+
+done:
+ ungrabpointer();
+ framedestroy(fw);
+ destroywindow(cwin);
+
+ pt = addpt(f->r.min, f->grabbox.min);
+ pt.x += Dx(f->grabbox)/2;
+ pt.y += Dy(f->grabbox)/2;
+ warppointer(pt);
+}
+
+static void
+mouse_resizecolframe(Frame *f, Align align) {
+ WinAttr wa;
+ Window *cwin, *hwin;
+ Divide *d;
+ View *v;
+ Area *a;
+ Rectangle r;
+ Point pt, min;
+
+ assert((align&(East|West)) != (East|West));
+ assert((align&(North|South)) != (North|South));
+
+ v = screen->sel;
+ for(a = v->area->next, d = divs; a; a = a->next, d = d->next)
+ if(a == f->area) break;
+
+ if(align&East)
+ d = d->next;
+
+ min.x = Dx(v->r)/NCOL;
+ min.y = /*frame_delta_h() +*/ labelh(def.font);
+ if(align&North) {
+ if(f->aprev) {
+ r.min.y = f->aprev->r.min.y + min.y;
+ r.max.y = f->r.max.y - min.y;
+ }else {
+ r.min.y = a->r.min.y;
+ r.max.y = r.min.y + 1;
+ }
+ }else {
+ if(f->anext) {
+ r.max.y = f->anext->r.max.y - min.y;
+ r.min.y = f->r.min.y + min.y;
+ }else {
+ r.max.y = a->r.max.y;
+ r.min.y = r.max.y - 1;
+ }
+ }
+ if(align&West) {
+ if(a->prev != v->area) {
+ r.min.x = a->prev->r.min.x + min.x;
+ r.max.x = a->r.max.x - min.x;
+ }else {
+ r.min.x = a->r.min.x;
+ r.max.x = r.min.x + 1;
+ }
+ }else {
+ if(a->next) {
+ r.max.x = a->next->r.max.x - min.x;
+ r.min.x = a->r.min.x + min.x;
+ }else {
+ r.max.x = a->r.max.x;
+ r.min.x = r.max.x - 1;
+ }
+ }
+
+ cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
+ mapwin(cwin);
+
+ r = f->r;
+ if(align&North)
+ r.min.y--;
+ else
+ r.min.y = r.max.y - 1;
+ r.max.y = r.min.y + 2;
+
+ hwin = gethsep(r);
+
+ if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
+ goto done;
+
+ pt.x = ((align&West) ? f->r.min.x : f->r.max.x);
+ pt.y = ((align&North) ? f->r.min.y : f->r.max.y);
+ warppointer(pt);
+
+ while(readmotion(&pt)) {
+ if(align&West)
+ r.min.x = pt.x;
+ else
+ r.max.x = pt.x;
+ r.min.y = ((align&South) ? pt.y : pt.y-1);
+ r.max.y = r.min.y+2;
+
+ div_set(d, pt.x);
+ reshapewin(hwin, r);
+ }
+
+ r = f->r;
+ if(align&West)
+ r.min.x = pt.x;
+ else
+ r.max.x = pt.x;
+ if(align&North)
+ r.min.y = pt.y;
+ else
+ r.max.y = pt.y;
+ column_resizeframe(f, r);
+
+ /* XXX: Magic number... */
+ if(align&West)
+ pt.x = f->r.min.x + 4;
+ else
+ pt.x = f->r.max.x - 4;
+ if(align&North)
+ pt.y = f->r.min.y + 4;
+ else
+ pt.y = f->r.max.y - 4;
+ warppointer(pt);
+
+done:
+ ungrabpointer();
+ destroywindow(cwin);
+ destroywindow(hwin);
+}
+
 void
-mouse_resize(Client *c, bool grabbox, Align align) {
- XEvent ev;
+mouse_resizecol(Divide *d) {
+ WinAttr wa;
+ Window *cwin;
+ Divide *dp;
+ View *v;
+ Area *a;
+ Rectangle r;
+ Point pt;
+ uint minw;
+
+ v = screen->sel;
+
+ for(a = v->area->next, dp = divs; a; a = a->next, dp = dp->next)
+ if(dp->next == d) break;
+
+ /* Fix later */
+ if(a == nil || a->next == nil)
+ return;
+
+ pt = querypointer(&scr.root);
+
+ minw = Dx(v->r)/NCOL;
+ r.min.x = a->r.min.x + minw;
+ r.max.x = a->next->r.max.x - minw;
+ r.min.y = pt.y;
+ r.max.y = pt.y+1;
+
+ cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
+ mapwin(cwin);
+
+ if(!grabpointer(&scr.root, cwin, cursor[CurNone], MouseMask))
+ goto done;
+
+ while(readmotion(&pt))
+ div_set(d, pt.x);
+
+ column_resize(a, pt.x - a->r.min.x);
+
+done:
+ ungrabpointer();
+ destroywindow(cwin);
+}
+
+void
+mouse_movegrabbox(Client *c) {
+ Rectangle *rects;
+ Rectangle frect, origin;
+ Point pt, pt1;
+ Frame *f;
+ Align align, grav;
+ uint nrect;
+
+ f = c->sel;
+ if(!f->area->floating) {
+ do_managed_move(c);
+ return;
+ }
+
+ if(!grabpointer(c->framewin, nil, cursor[CurMove], MouseMask))
+ return;
+
+ rects = view_rects(f->view, &nrect, f);
+ origin = f->r;
+ frect = f->r;
+
+ pt1 = querypointer(&scr.root);
+ for(; readmotion(&pt); pt1=pt) {
+ origin = rectaddpt(origin, subpt(pt, pt1));
+ origin = constrain(origin);
+ frect = origin;
+
+ align = Center;
+ grav = snap_rect(rects, nrect, &frect, &align, def.snap);
+
+ frect = frame_hints(f, frect, Center);
+ frect = constrain(frect);
+ client_resize(c, frect);
+ }
+ client_resize(c, frect);
+
+ free(rects);
+ ungrabpointer();
+}
+
+void
+mouse_resize(Client *c, Align align) {
         Rectangle *rects;
         Rectangle frect, origin;
         Align grav;
         Cursor cur;
         Point d, pt, hr;
         float rx, ry, hrx, hry;
- uint num;
+ uint nrect;
         Frame *f;
 
         f = c->sel;
-
         if(f->client->fullscreen)
                 return;
-
         if(!f->area->floating) {
                 if(align==Center)
                         do_managed_move(c);
@@ -698,30 +729,28 @@ mouse_resize(Client *c, bool grabbox, Al
                 return;
         }
 
+ cur = quad_cursor(align);
+ if(align == Center)
+ cur = cursor[CurSizing];
+
+ if(!grabpointer(c->framewin, nil, cur, MouseMask))
+ return;
+
         origin = f->r;
         frect = f->r;
- rects = view_rects(f->area->view, &num, c->frame);
-
- cur = quad_cursor(align);
- if((align==Center) && !grabbox)
- cur = cursor[CurSizing];
+ rects = view_rects(f->area->view, &nrect, c->frame);
 
         pt = querypointer(c->framewin);
         rx = (float)pt.x / Dx(frect);
- ry = (float)pt.y /Dy(frect);
-
- if(!grabpointer(c->framewin, nil, cur, MouseMask))
- return;
+ ry = (float)pt.y / Dy(frect);
 
         pt = querypointer(&scr.root);
-
- hr = subpt(frect.max, frect.min);
- hr = divpt(hr, Pt(2, 2));
 
         SET(hrx);
         SET(hry);
-
         if(align != Center) {
+ hr = subpt(frect.max, frect.min);
+ hr = divpt(hr, Pt(2, 2));
                 d = hr;
                 if(align&North) d.y -= hr.y;
                 if(align&South) d.y += hr.y;
@@ -730,12 +759,15 @@ mouse_resize(Client *c, bool grabbox, Al
 
                 pt = addpt(d, f->r.min);
                 warppointer(pt);
- }
- else if(!grabbox) {
- hrx = (double)(Dx(screen->r) + Dx(frect) - 2 * labelh(def.font))
- / Dx(screen->r);
- hry = (double)(Dy(screen->r) + Dy(frect) - 3 * labelh(def.font))
- / Dy(screen->r);
+ }else {
+ hrx = (double)(Dx(screen->r)
+ + Dx(frect)
+ - 2 * labelh(def.font))
+ / Dx(screen->r);
+ hry = (double)(Dy(screen->r)
+ + Dy(frect)
+ - 3 * labelh(def.font))
+ / Dy(screen->r);
 
                 pt.x = frect.max.x - labelh(def.font);
                 pt.y = frect.max.y - labelh(def.font);
@@ -743,67 +775,51 @@ mouse_resize(Client *c, bool grabbox, Al
                 d.y = pt.y / hry;
 
                 warppointer(d);
- flushevents(PointerMotionMask, False);
- }
-
- for(;;) {
- XMaskEvent(display, MouseMask | ExposureMask, &ev);
- switch (ev.type) {
- default:
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- case MotionNotify:
- d.x = ev.xmotion.x_root;
- d.y = ev.xmotion.y_root;
-
- if(align == Center && !grabbox) {
- d.x = (d.x * hrx) - pt.x;
- d.y = (d.y * hry) - pt.y;
- }else
- d = subpt(d, pt);
- pt = addpt(pt, d);
-
- rect_morph(&origin, d, &align);
- origin = constrain(origin);
- frect = origin;
-
- grav = snap_rect(rects, num, &frect, &align, def.snap);
-
- frect = frame_hints(f, frect, grav);
- frect = constrain(frect);
-
- //reshapewin(c->framewin, frect);
- client_resize(c, frect);
- break;
- case ButtonRelease:
- client_resize(c, frect);
-
- if(!grabbox) {
- pt = translate(c->framewin, &scr.root,
- Pt(Dx(frect)*rx, Dy(frect)*ry));
- if(pt.y > screen->brect.min.y)
- pt.y = screen->brect.min.y - 1;
- warppointer(pt);
- }
-
- free(rects);
- ungrabpointer();
- return;
- }
- }
+ }
+ sync();
+ flushevents(PointerMotionMask, false);
+
+ while(readmotion(&d)) {
+ if(align == Center) {
+ d.x = (d.x * hrx) - pt.x;
+ d.y = (d.y * hry) - pt.y;
+ }else
+ d = subpt(d, pt);
+ pt = addpt(pt, d);
+
+ rect_morph(&origin, d, &align);
+ origin = constrain(origin);
+ frect = origin;
+
+ grav = snap_rect(rects, nrect, &frect, &align, def.snap);
+
+ frect = frame_hints(f, frect, grav);
+ frect = constrain(frect);
+
+ client_resize(c, frect);
+ }
+
+ pt = addpt(c->framewin->r.min,
+ Pt(Dx(frect) * rx,
+ Dy(frect) * ry));
+ if(pt.y > f->view->r.max.y)
+ pt.y = f->view->r.max.y - 1;
+ warppointer(pt);
+
+ free(rects);
+ ungrabpointer();
 }
 
 /* Doesn't belong here */
 void
 grab_button(XWindow w, uint button, ulong mod) {
- XGrabButton(display, button, mod, w, False, ButtonMask,
+ XGrabButton(display, button, mod, w, false, ButtonMask,
                         GrabModeSync, GrabModeSync, None, None);
         if((mod != AnyModifier) && (numlock_mask != 0)) {
- XGrabButton(display, button, mod | numlock_mask, w, False, ButtonMask,
+ XGrabButton(display, button, mod | numlock_mask, w, false, ButtonMask,
                         GrabModeSync, GrabModeAsync, None, None);
- XGrabButton(display, button, mod | numlock_mask | LockMask, w, False,
+ XGrabButton(display, button, mod | numlock_mask | LockMask, w, false,
                         ButtonMask, GrabModeSync, GrabModeAsync, None, None);
         }
 }
+
diff -r 7e260e5ef3f5 -r f8a79755e0f5 cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Tue Jan 22 21:21:59 2008 -0500
+++ b/cmd/wmii/x11.c Wed Jan 23 00:13:33 2008 -0500
@@ -106,6 +106,17 @@ rectsubpt(Rectangle r, Point p) {
         return r;
 }
 
+Rectangle
+rectsetorigin(Rectangle r, Point p) {
+ Rectangle ret;
+
+ ret.min.x = p.x;
+ ret.min.y = p.y;
+ ret.max.x = p.x + Dx(r);
+ ret.max.y = p.y + Dy(r);
+ return ret;
+}
+
 /* Formatters */
 static int
 Afmt(Fmt *f) {
diff -r 7e260e5ef3f5 -r f8a79755e0f5 include/x11.h
--- a/include/x11.h Tue Jan 22 21:21:59 2008 -0500
+++ b/include/x11.h Wed Jan 23 00:13:33 2008 -0500
@@ -239,6 +239,7 @@ Rectangle gravitate(Rectangle dst, Recta
 Rectangle gravitate(Rectangle dst, Rectangle src, Point grav);
 Rectangle insetrect(Rectangle, int);
 Rectangle rectaddpt(Rectangle, Point);
+Rectangle rectsetorigin(Rectangle, Point);
 Rectangle rectsubpt(Rectangle, Point);
 Handlers* sethandler(Window*, Handlers*);
 Rectangle sizehint(WinHints*, Rectangle);
Received on Wed Jan 23 2008 - 06:18:35 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:07 UTC