[hackers] [wmii] cleanup

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri, 01 Jun 2007 01:09:19 -0000

changeset: 2087:0d7f136f4a38
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Apr 16 22:47:32 2007 -0400
summary: cleanup

diff -r 8525b7a3c7b9 -r 0d7f136f4a38 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Mon Apr 16 22:02:29 2007 -0400
+++ b/cmd/wmii/fns.h Mon Apr 16 22:47:32 2007 -0400
@@ -182,3 +182,4 @@ uint textwidth(Font *font, char *text);
 uint textwidth(Font *font, char *text);
 uint labelh(Font *font);
 Atom xatom(char *name);
+int grabpointer(Window *w, Window *confine, Cursor cur, int mask);
diff -r 8525b7a3c7b9 -r 0d7f136f4a38 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Mon Apr 16 22:02:29 2007 -0400
+++ b/cmd/wmii/mouse.c Mon Apr 16 22:47:32 2007 -0400
@@ -276,6 +276,13 @@ warppointer(int x, int y) {
                 /* target */ x, y);
 }
 
+void
+translate(Window *src, Window *dst, int sx, int sy, int *dx, int *dy) {
+ XWindow w;
+
+ XTranslateCoordinates(display, src->w, dst->w, sx, sy, dx, dy, &w);
+}
+
 static void
 do_managed_move(Client *c) {
         Rectangle frect, ofrect;
@@ -287,10 +294,7 @@ do_managed_move(Client *c) {
         f = c->sel;
 
         XSync(display, False);
- if(XGrabPointer(display, c->framewin->w, False,
- MouseMask, GrabModeAsync, GrabModeAsync,
- None, cursor[CurMove], CurrentTime
- ) != GrabSuccess)
+ if(!grabpointer(c->framewin, nil, cursor[CurMove], MouseMask))
                 return;
         XGrabServer(display);
 
@@ -301,6 +305,23 @@ do_managed_move(Client *c) {
         for(;;) {
                 XMaskEvent(display, MouseMask | ExposureMask, &ev);
                 switch (ev.type) {
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
+ case MotionNotify:
+ ofrect = frect;
+ x = ev.xmotion.x_root;
+ y = ev.xmotion.y_root;
+
+ find_droppoint(f, x, y, &frect, False);
+
+ if(!eqrect(frect, ofrect)) {
+ xorrect(ofrect);
+ xorrect(frect);
+ }
+ break;
                 case ButtonRelease:
                         xorrect(frect);
 
@@ -310,22 +331,6 @@ do_managed_move(Client *c) {
                         XUngrabPointer(display, CurrentTime);
                         XSync(display, False);
                         return;
- case MotionNotify:
- ofrect = frect;
- x = ev.xmotion.x_root;
- y = ev.xmotion.y_root;
-
- find_droppoint(f, x, y, &frect, False);
-
- if(!eqrect(frect, ofrect)) {
- xorrect(ofrect);
- xorrect(frect);
- }
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- default: break;
                 }
         }
 }
@@ -355,12 +360,11 @@ mouse_resizecolframe(Frame *f, Align ali
         }
         for(fp = a->frame; fp; fp = fp->anext)
                 if(fp->anext == f) break;
-
         if(align&EAST)
                 d = d->next;
 
- minw = Dx(screen->rect)/NCOL;
- minh = frame_delta_h() + labelh(def.font);
+ if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
+ return;
 
         if(align&NORTH) {
                 r.min.y = (fp ? fp->rect.min.y : screen->rect.min.y);
@@ -369,9 +373,6 @@ mouse_resizecolframe(Frame *f, Align ali
                 r.min.y = f->rect.min.y;
                 r.max.y = (f->anext ? f->anext->rect.max.y : a->rect.max.y);
         }
- r.min.y += minh;
- r.max.y -= minh;
-
         if(align&WEST) {
                 r.min.x = (ap ? ap->rect.min.x : screen->rect.min.x);
                 r.max.x = a->rect.max.x;
@@ -379,8 +380,12 @@ mouse_resizecolframe(Frame *f, Align ali
                 r.min.x = a->rect.min.x;
                 r.max.x = (a->next ? a->next->rect.max.x : screen->rect.max.x);
         }
+ minw = Dx(screen->rect)/NCOL;
+ minh = frame_delta_h() + labelh(def.font);
         r.min.x += minw;
         r.max.x -= minw;
+ r.min.y += minh;
+ r.max.y -= minh;
 
         cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
         mapwin(cwin);
@@ -391,18 +396,8 @@ mouse_resizecolframe(Frame *f, Align ali
         else
                 r.min.y = r.max.y - 1;
         r.max.y = r.min.y + 2;
+
         hwin = gethsep(r);
-
- if(XGrabPointer(
- display, scr.root.w,
- /* owner_events*/ False,
- /* event_mask */ MouseMask,
- /* kbd, mouse */ GrabModeAsync, GrabModeAsync,
- /* confine_to */ cwin->w,
- /* cursor */ cursor[CurSizing],
- /* time */ CurrentTime
- ) != GrabSuccess)
- goto done;
         
         x = ((align&WEST) ? f->rect.min.x : f->rect.max.x);
         y = ((align&NORTH) ? f->rect.min.y : f->rect.max.y);
@@ -411,6 +406,25 @@ mouse_resizecolframe(Frame *f, Align ali
         for(;;) {
                 XMaskEvent(display, MouseMask | ExposureMask, &ev);
                 switch (ev.type) {
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
+ case MotionNotify:
+ x = ev.xmotion.x_root;
+ y = ev.xmotion.y_root;
+
+ if(align&WEST)
+ r.min.x = x;
+ else
+ r.max.x = x;
+ r.min.y = ((align&SOUTH) ? y : y-1);
+ r.max.y = r.min.y+2;
+
+ setdiv(d, x);
+ reshapewin(hwin, r);
+ break;
                 case ButtonRelease:
                         if(align&WEST)
                                 r.min.x = x;
@@ -434,31 +448,11 @@ mouse_resizecolframe(Frame *f, Align ali
                         else
                                 y = f->rect.max.y - 2;
                         warppointer(x, y);
-
- XUngrabPointer(display, CurrentTime);
- XSync(display, False);
                         goto done;
- case MotionNotify:
- x = ev.xmotion.x_root;
- y = ev.xmotion.y_root;
-
- if(align&WEST)
- r.min.x = x;
- else
- r.max.x = x;
- r.min.y = ((align&SOUTH) ? y : y-1);
- r.max.y = r.min.y+2;
-
- setdiv(d, x);
- reshapewin(hwin, r);
- break;
- case Expose:
- dispatch_event(&ev);
- break;
- default: break;
                 }
         }
 done:
+ XUngrabPointer(display, CurrentTime);
         destroywindow(cwin);
         destroywindow(hwin);
 }
@@ -471,8 +465,9 @@ mouse_resizecol(Divide *d) {
         Divide *dp;
         View *v;
         Area *a;
+ Rectangle r;
         uint minw;
- int x, y, x2;
+ int x, y;
 
         v = screen->sel;
 
@@ -483,101 +478,76 @@ mouse_resizecol(Divide *d) {
         if(a == nil || a->next == nil)
                 return;
 
+ if(!grabpointer(&scr.root, cwin, cursor[CurInvisible], MouseMask))
+ return;
+
+ querypointer(&scr.root, &x, &y);
+
         minw = Dx(screen->rect)/NCOL;
-
- querypointer(&scr.root, &x, &y);
- x = a->rect.min.x + minw;
- x2 = a->next->rect.max.x - minw;
-
- cwin = createwindow(&scr.root, Rect(x, y, x2, y+1), 0, InputOnly, &wa, 0);
+ r.min.x = a->rect.min.x + minw;
+ r.max.x = a->next->rect.max.x - minw;
+ r.min.y = y;
+ r.max.y = y+1;
+ cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
         mapwin(cwin);
 
- if(XGrabPointer(
- display, scr.root.w,
- /* owner_events*/ False,
- /* event_mask */ MouseMask,
- /* kbd, mouse */ GrabModeAsync, GrabModeAsync,
- /* confine_to */ cwin->w,
- /* cursor */ cursor[CurInvisible],
- /* time */ CurrentTime
- ) != GrabSuccess)
- goto done;
-
- querypointer(&scr.root, &x, &y);
         for(;;) {
                 XMaskEvent(display, MouseMask | ExposureMask, &ev);
                 switch (ev.type) {
- case ButtonRelease:
- resize_column(a, x - a->rect.min.x);
-
- XUngrabPointer(display, CurrentTime);
- XSync(display, False);
- goto done;
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
                 case MotionNotify:
                         x = ev.xmotion.x_root;
                         setdiv(d, x);
                         break;
- case Expose:
- dispatch_event(&ev);
- break;
- default: break;
+ case ButtonRelease:
+ resize_column(a, x - a->rect.min.x);
+ goto done;
                 }
         }
 done:
+ XUngrabPointer(display, CurrentTime);
         destroywindow(cwin);
 }
 
 void
 do_mouse_resize(Client *c, Bool opaque, Align align) {
+ XEvent ev;
+ Rectangle *rects;
+ Rectangle ofrect, frect, origin;
         Align grav;
- XWindow dummy;
         Cursor cur;
- XEvent ev;
- Rectangle *rects, ofrect, frect, origin;
- int snap, dx, dy, pt_x, pt_y, hr_x, hr_y;
+ int dx, dy, pt_x, pt_y, hr_x, hr_y;
+ float rx, ry, hrx, hry;
         uint num;
         Bool floating;
- float rx, ry, hrx, hry;
         Frame *f;
 
         f = c->sel;
- floating = f->area->floating;
+
+ if(!f->area->floating) {
+ if(align==CENTER)
+ do_managed_move(c);
+ else
+ mouse_resizecolframe(f, align);
+ return;
+ }
+
         origin = frect = f->rect;
+ rects = rects_of_view(f->area->view, &num, (opaque ? c->frame : nil));
+
         cur = cursor_of_quad(align);
- if(floating) {
- rects = rects_of_view(f->area->view, &num, (opaque ? c->frame : nil));
- snap = def.snap;
- }else{
- mouse_resizecolframe(f, align);
- return;
- rects = nil;
- snap = 0;
- }
-
- if(align == CENTER) {
- if(!opaque)
- cur = cursor[CurInvisible];
- if(!floating) {
- do_managed_move(c);
- return;
- }
- }
+ if((align==CENTER) && !opaque)
+ cur = cursor[CurInvisible];
 
         querypointer(c->framewin, &pt_x, &pt_y);
         rx = (float)pt_x / Dx(frect);
         ry = (float)pt_y /Dy(frect);
 
- if(XGrabPointer(
- /* display */ display,
- /* window */ c->framewin->w,
- /* owner_events */ False,
- /* event_mask */ MouseMask,
- /* pointer_mode */ GrabModeAsync,
- /* keyboard_mode */ GrabModeAsync,
- /* confine_to */ None,
- /* cursor */ cur,
- /* time */ CurrentTime
- ) != GrabSuccess)
+ if(!grabpointer(c->framewin, nil, cur, MouseMask))
                 return;
 
         querypointer(&scr.root, &pt_x, &pt_y);
@@ -590,12 +560,7 @@ do_mouse_resize(Client *c, Bool opaque,
                 if(align&EAST) dx += hr_x;
                 if(align&WEST) dx -= hr_x;
 
- XTranslateCoordinates(display,
- /* src, dst */ c->framewin->w, scr.root.w,
- /* src x,y */ dx, dy,
- /* dest x,y */ &pt_x, &pt_y,
- /* child */ &dummy
- );
+ translate(c->framewin, &scr.root, dx, dy, &pt_x, &pt_y);
                 warppointer(pt_x, pt_y);
         }
         else if(f->client->fullscreen) {
@@ -623,35 +588,11 @@ do_mouse_resize(Client *c, Bool opaque,
         for(;;) {
                 XMaskEvent(display, MouseMask | ExposureMask, &ev);
                 switch (ev.type) {
- case ButtonRelease:
- if(!opaque)
- xorborder(frect);
-
- if(!floating)
- resize_colframe(f, &frect);
- else
- resize_client(c, &frect);
-
- if(!opaque) {
- XTranslateCoordinates(display,
- /* src, dst */ c->framewin->w, scr.root.w,
- /* src_x */ (Dx(frect) * rx),
- /* src_y */ (Dy(frect) * ry),
- /* dest x,y */ &pt_x, &pt_y,
- /* child */ &dummy
- );
- if(pt_y > screen->brect.min.y)
- pt_y = screen->brect.min.y - 1;
- warppointer(pt_x, pt_y);
- XUngrabServer(display);
- }else
- map_client(c);
-
- free(rects);
-
- XUngrabPointer(display, CurrentTime);
- XSync(display, False);
- return;
+ default:
+ break;
+ case Expose:
+ dispatch_event(&ev);
+ break;
                 case MotionNotify:
                         ofrect = frect;
                         dx = ev.xmotion.x_root;
@@ -671,10 +612,7 @@ do_mouse_resize(Client *c, Bool opaque,
                         origin = constrain(origin);
                         frect = origin;
 
- if(floating)
- grav = snap_rect(rects, num, &frect, &align, snap);
- else
- grav = align^CENTER;
+ grav = snap_rect(rects, num, &frect, &align, def.snap);
 
                         apply_sizehints(c, &frect, floating, True, grav);
                         frect = constrain(frect);
@@ -687,11 +625,26 @@ do_mouse_resize(Client *c, Bool opaque,
                                 xorborder(frect);
                         }
                         break;
- case Expose:
- dispatch_event(&ev);
- break;
- default:
- break;
+ case ButtonRelease:
+ if(!opaque)
+ xorborder(frect);
+
+ resize_client(c, &frect);
+
+ if(!opaque) {
+ translate(c->framewin, &scr.root,
+ (Dx(frect)*rx), (Dy(frect)*ry),
+ &pt_x, &pt_y);
+ if(pt_y > screen->brect.min.y)
+ pt_y = screen->brect.min.y - 1;
+ warppointer(pt_x, pt_y);
+ XUngrabServer(display);
+ }else
+ map_client(c);
+
+ free(rects);
+ XUngrabPointer(display, CurrentTime);
+ return;
                 }
         }
 }
Received on Fri Jun 01 2007 - 03:09:18 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:55 UTC