51 #define LENGTH(x) (sizeof x / sizeof x[0]) |
51 #define LENGTH(x) (sizeof x / sizeof x[0]) |
52 #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
52 #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
53 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
53 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
54 #define MAXTAGLEN 16 |
54 #define MAXTAGLEN 16 |
55 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
55 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) |
56 #define WIDTH(x) ((x)->w + 2*(x)->bw) |
56 #define WIDTH(x) ((x)->w + 2 * (x)->bw) |
57 #define HEIGHT(x) ((x)->h + 2*(x)->bw) |
57 #define HEIGHT(x) ((x)->h + 2 * (x)->bw) |
58 #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1)) |
58 #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1)) |
59 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height) |
59 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height) |
60 |
60 |
61 /* enums */ |
61 /* enums */ |
62 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
62 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
930 void |
930 void |
931 monocle(void) { |
931 monocle(void) { |
932 Client *c; |
932 Client *c; |
933 |
933 |
934 for(c = nexttiled(clients); c; c = nexttiled(c->next)) |
934 for(c = nexttiled(clients); c; c = nexttiled(c->next)) |
935 resize(c, wx, wy, ww - 2*c->bw, wh - 2*c->bw, resizehints); |
935 resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints); |
936 } |
936 } |
937 |
937 |
938 void |
938 void |
939 movemouse(const Arg *arg) { |
939 movemouse(const Arg *arg) { |
940 int x, y, ocx, ocy, di, nx, ny; |
940 int x, y, ocx, ocy, di, nx, ny; |
950 ocy = c->y; |
950 ocy = c->y; |
951 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
951 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
952 None, cursor[CurMove], CurrentTime) != GrabSuccess) |
952 None, cursor[CurMove], CurrentTime) != GrabSuccess) |
953 return; |
953 return; |
954 XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); |
954 XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); |
|
955 if(usegrab) |
|
956 XGrabServer(dpy); |
955 do { |
957 do { |
956 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
958 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
957 switch (ev.type) { |
959 switch (ev.type) { |
958 case ConfigureRequest: |
960 case ConfigureRequest: |
959 case Expose: |
961 case Expose: |
960 case MapRequest: |
962 case MapRequest: |
961 handler[ev.type](&ev); |
963 handler[ev.type](&ev); |
962 break; |
964 break; |
963 case MotionNotify: |
965 case MotionNotify: |
964 XSync(dpy, False); |
|
965 nx = ocx + (ev.xmotion.x - x); |
966 nx = ocx + (ev.xmotion.x - x); |
966 ny = ocy + (ev.xmotion.y - y); |
967 ny = ocy + (ev.xmotion.y - y); |
967 if(snap && nx >= wx && nx <= wx + ww |
968 if(snap && nx >= wx && nx <= wx + ww |
968 && ny >= wy && ny <= wy + wh) { |
969 && ny >= wy && ny <= wy + wh) { |
969 if(abs(wx - nx) < snap) |
970 if(abs(wx - nx) < snap) |
981 resize(c, nx, ny, c->w, c->h, False); |
982 resize(c, nx, ny, c->w, c->h, False); |
982 break; |
983 break; |
983 } |
984 } |
984 } |
985 } |
985 while(ev.type != ButtonRelease); |
986 while(ev.type != ButtonRelease); |
|
987 if(usegrab) |
|
988 XUngrabServer(dpy); |
986 XUngrabPointer(dpy, CurrentTime); |
989 XUngrabPointer(dpy, CurrentTime); |
987 } |
990 } |
988 |
991 |
989 Client * |
992 Client * |
990 nexttiled(Client *c) { |
993 nexttiled(Client *c) { |
1119 ocy = c->y; |
1122 ocy = c->y; |
1120 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
1123 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
1121 None, cursor[CurResize], CurrentTime) != GrabSuccess) |
1124 None, cursor[CurResize], CurrentTime) != GrabSuccess) |
1122 return; |
1125 return; |
1123 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
1126 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
|
1127 if(usegrab) |
|
1128 XGrabServer(dpy); |
1124 do { |
1129 do { |
1125 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
1130 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
1126 switch(ev.type) { |
1131 switch(ev.type) { |
1127 case ConfigureRequest: |
1132 case ConfigureRequest: |
1128 case Expose: |
1133 case Expose: |
1129 case MapRequest: |
1134 case MapRequest: |
1130 handler[ev.type](&ev); |
1135 handler[ev.type](&ev); |
1131 break; |
1136 break; |
1132 case MotionNotify: |
1137 case MotionNotify: |
1133 XSync(dpy, False); |
|
1134 nw = MAX(ev.xmotion.x - ocx - 2*c->bw + 1, 1); |
1138 nw = MAX(ev.xmotion.x - ocx - 2*c->bw + 1, 1); |
1135 nh = MAX(ev.xmotion.y - ocy - 2*c->bw + 1, 1); |
1139 nh = MAX(ev.xmotion.y - ocy - 2*c->bw + 1, 1); |
1136 |
1140 |
1137 if(snap && nw >= wx && nw <= wx + ww |
1141 if(snap && nw >= wx && nw <= wx + ww |
1138 && nh >= wy && nh <= wy + wh) { |
1142 && nh >= wy && nh <= wy + wh) { |
1144 resize(c, c->x, c->y, nw, nh, True); |
1148 resize(c, c->x, c->y, nw, nh, True); |
1145 break; |
1149 break; |
1146 } |
1150 } |
1147 } |
1151 } |
1148 while(ev.type != ButtonRelease); |
1152 while(ev.type != ButtonRelease); |
|
1153 if(usegrab) |
|
1154 XUngrabServer(dpy); |
1149 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
1155 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
1150 XUngrabPointer(dpy, CurrentTime); |
1156 XUngrabPointer(dpy, CurrentTime); |
1151 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
1157 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
1152 } |
1158 } |
1153 |
1159 |
1447 h = wh / n; |
1453 h = wh / n; |
1448 if(h < bh) |
1454 if(h < bh) |
1449 h = wh; |
1455 h = wh; |
1450 |
1456 |
1451 for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { |
1457 for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { |
1452 resize(c, x, y, w - 2*c->bw, /* remainder */ ((i + 1 == n) |
1458 if(i + 1 == n) { /* remainder */ |
1453 ? wy + wh - y : h) - 2*c->bw, resizehints); |
1459 if(wy + wh - y < bh) |
|
1460 resize(c, x, y, w - 2 * c->bw, wy + wh - y - 2 * c->bw, False); |
|
1461 else |
|
1462 resize(c, x, y, w - 2 * c->bw, wy + wh - y - 2 * c->bw, resizehints); |
|
1463 } |
|
1464 else |
|
1465 resize(c, x, y, w - 2 * c->bw, h - 2 * c->bw, resizehints); |
1454 if(h != wh) |
1466 if(h != wh) |
1455 y = c->y + HEIGHT(c); |
1467 y = c->y + HEIGHT(c); |
1456 } |
1468 } |
1457 } |
1469 } |
1458 |
1470 |