[hackers] [dwm] calculate window/monitor intersection || Connor Lane Smith
changeset: 1587:d77d6ee75bdd
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sun Nov 06 20:31:29 2011 +0100
files: dwm.c
description:
calculate window/monitor intersection
diff -r 6e8f617a87ba -r d77d6ee75bdd dwm.c
--- a/dwm.c Sun Nov 06 20:30:06 2011 +0100
+++ b/dwm.c Sun Nov 06 20:31:29 2011 +0100
_AT_@ -43,7 +43,8 @@
/* macros */
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
-#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
+#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
+ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MAX(A, B) ((A) > (B) ? (A) : (B))
_AT_@ -203,8 +204,8 @@
static Client *nexttiled(Client *c);
static void pop(Client *);
static void propertynotify(XEvent *e);
-static Monitor *ptrtomon(int x, int y);
static void quit(const Arg *arg);
+static Monitor *recttomon(int x, int y, int w, int h);
static void resize(Client *c, int x, int y, int w, int h, Bool interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
_AT_@ -1248,7 +1249,7 @@
}
} while(ev.type != ButtonRelease);
XUngrabPointer(dpy, CurrentTime);
- if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
+ if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
sendmon(c, m);
selmon = m;
focus(NULL);
_AT_@ -1305,21 +1306,24 @@
}
}
-Monitor *
-ptrtomon(int x, int y) {
- Monitor *m;
-
- for(m = mons; m; m = m->next)
- if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
- return m;
- return selmon;
-}
-
void
quit(const Arg *arg) {
running = False;
}
+Monitor *
+recttomon(int x, int y, int w, int h) {
+ Monitor *m, *r = selmon;
+ int a, area = 0;
+
+ for(m = mons; m; m = m->next)
+ if((a = INTERSECT(x, y, w, h, m)) > area) {
+ area = a;
+ r = m;
+ }
+ return r;
+}
+
void
resize(Client *c, int x, int y, int w, int h, Bool interact) {
if(applysizehints(c, &x, &y, &w, &h, interact))
_AT_@ -1383,7 +1387,7 @@
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
XUngrabPointer(dpy, CurrentTime);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
- if((m = ptrtomon(c->x + c->w / 2, c->y + c->h / 2)) != selmon) {
+ if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
sendmon(c, m);
selmon = m;
focus(NULL);
_AT_@ -2051,7 +2055,7 @@
Monitor *m;
if(w == root && getrootptr(&x, &y))
- return ptrtomon(x, y);
+ return recttomon(x, y, 1, 1);
for(m = mons; m; m = m->next)
if(w == m->barwin)
return m;
Received on Sun Nov 06 2011 - 20:36:43 CET
This archive was generated by hypermail 2.3.0
: Sun Nov 06 2011 - 20:48:06 CET