diff options
| author | Connor Lane Smith <cls@lubutu.com> | 2011-11-06 20:31:29 +0100 |
|---|---|---|
| committer | Connor Lane Smith <cls@lubutu.com> | 2011-11-06 20:31:29 +0100 |
| commit | 80a9da555e81a69ab2e2e8fa9b779fa087d6863c (patch) | |
| tree | 160e330c0afcdf92a978866de58f36750c6abe89 | |
| parent | honour fullscreen hint on map (diff) | |
| download | dwm-80a9da555e81a69ab2e2e8fa9b779fa087d6863c.tar.gz dwm-80a9da555e81a69ab2e2e8fa9b779fa087d6863c.zip | |
calculate window/monitor intersection
Diffstat (limited to '')
| -rw-r--r-- | dwm.c | 34 |
1 files changed, 19 insertions, 15 deletions
| @@ -43,7 +43,8 @@ | |||
| 43 | /* macros */ | 43 | /* macros */ |
| 44 | #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) | 44 | #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) |
| 45 | #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) | 45 | #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) |
| 46 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) | 46 | #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ |
| 47 | * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) | ||
| 47 | #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) | 48 | #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) |
| 48 | #define LENGTH(X) (sizeof X / sizeof X[0]) | 49 | #define LENGTH(X) (sizeof X / sizeof X[0]) |
| 49 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) | 50 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) |
| @@ -203,8 +204,8 @@ static void movemouse(const Arg *arg); | |||
| 203 | static Client *nexttiled(Client *c); | 204 | static Client *nexttiled(Client *c); |
| 204 | static void pop(Client *); | 205 | static void pop(Client *); |
| 205 | static void propertynotify(XEvent *e); | 206 | static void propertynotify(XEvent *e); |
| 206 | static Monitor *ptrtomon(int x, int y); | ||
| 207 | static void quit(const Arg *arg); | 207 | static void quit(const Arg *arg); |
| 208 | static Monitor *recttomon(int x, int y, int w, int h); | ||
| 208 | static void resize(Client *c, int x, int y, int w, int h, Bool interact); | 209 | static void resize(Client *c, int x, int y, int w, int h, Bool interact); |
| 209 | static void resizeclient(Client *c, int x, int y, int w, int h); | 210 | static void resizeclient(Client *c, int x, int y, int w, int h); |
| 210 | static void resizemouse(const Arg *arg); | 211 | static void resizemouse(const Arg *arg); |
| @@ -1248,7 +1249,7 @@ movemouse(const Arg *arg) { | |||
| 1248 | } | 1249 | } |
| 1249 | } while(ev.type != ButtonRelease); | 1250 | } while(ev.type != ButtonRelease); |
| 1250 | XUngrabPointer(dpy, CurrentTime); | 1251 | XUngrabPointer(dpy, CurrentTime); |
| 1251 | if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) { | 1252 | if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { |
| 1252 | sendmon(c, m); | 1253 | sendmon(c, m); |
| 1253 | selmon = m; | 1254 | selmon = m; |
| 1254 | focus(NULL); | 1255 | focus(NULL); |
| @@ -1305,21 +1306,24 @@ propertynotify(XEvent *e) { | |||
| 1305 | } | 1306 | } |
| 1306 | } | 1307 | } |
| 1307 | 1308 | ||
| 1308 | Monitor * | ||
| 1309 | ptrtomon(int x, int y) { | ||
| 1310 | Monitor *m; | ||
| 1311 | |||
| 1312 | for(m = mons; m; m = m->next) | ||
| 1313 | if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh)) | ||
| 1314 | return m; | ||
| 1315 | return selmon; | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | void | 1309 | void |
| 1319 | quit(const Arg *arg) { | 1310 | quit(const Arg *arg) { |
| 1320 | running = False; | 1311 | running = False; |
| 1321 | } | 1312 | } |
| 1322 | 1313 | ||
| 1314 | Monitor * | ||
| 1315 | recttomon(int x, int y, int w, int h) { | ||
| 1316 | Monitor *m, *r = selmon; | ||
| 1317 | int a, area = 0; | ||
| 1318 | |||
| 1319 | for(m = mons; m; m = m->next) | ||
| 1320 | if((a = INTERSECT(x, y, w, h, m)) > area) { | ||
| 1321 | area = a; | ||
| 1322 | r = m; | ||
| 1323 | } | ||
| 1324 | return r; | ||
| 1325 | } | ||
| 1326 | |||
| 1323 | void | 1327 | void |
| 1324 | resize(Client *c, int x, int y, int w, int h, Bool interact) { | 1328 | resize(Client *c, int x, int y, int w, int h, Bool interact) { |
| 1325 | if(applysizehints(c, &x, &y, &w, &h, interact)) | 1329 | if(applysizehints(c, &x, &y, &w, &h, interact)) |
| @@ -1383,7 +1387,7 @@ resizemouse(const Arg *arg) { | |||
| 1383 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); | 1387 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
| 1384 | XUngrabPointer(dpy, CurrentTime); | 1388 | XUngrabPointer(dpy, CurrentTime); |
| 1385 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | 1389 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
| 1386 | if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) { | 1390 | if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { |
| 1387 | sendmon(c, m); | 1391 | sendmon(c, m); |
| 1388 | selmon = m; | 1392 | selmon = m; |
| 1389 | focus(NULL); | 1393 | focus(NULL); |
| @@ -2051,7 +2055,7 @@ wintomon(Window w) { | |||
| 2051 | Monitor *m; | 2055 | Monitor *m; |
| 2052 | 2056 | ||
| 2053 | if(w == root && getrootptr(&x, &y)) | 2057 | if(w == root && getrootptr(&x, &y)) |
| 2054 | return ptrtomon(x, y); | 2058 | return recttomon(x, y, 1, 1); |
| 2055 | for(m = mons; m; m = m->next) | 2059 | for(m = mons; m; m = m->next) |
| 2056 | if(w == m->barwin) | 2060 | if(w == m->barwin) |
| 2057 | return m; | 2061 | return m; |
