JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
make it easier for the user, if Xinerama support is given, always use the screen...
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 364d65b..4a8c2a9 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -39,6 +39,9 @@
 #include <X11/Xlib.h>
 #include <X11/Xproto.h>
 #include <X11/Xutil.h>
+#ifdef XINERAMA
+#include <X11/extensions/Xinerama.h>
+#endif
 
 /* macros */
 #define MAX(a, b)       ((a) > (b) ? (a) : (b))
@@ -1039,16 +1042,19 @@ movemouse(Client *c) {
                        XSync(dpy, False);
                        nx = ocx + (ev.xmotion.x - x1);
                        ny = ocy + (ev.xmotion.y - y1);
-                       if(abs(wx - nx) < snap)
-                               nx = wx;
-                       else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < snap)
-                               nx = wx + ww - c->w - 2 * c->bw;
-                       if(abs(wy - ny) < snap)
-                               ny = wy;
-                       else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < snap)
-                               ny = wy + wh - c->h - 2 * c->bw;
-                       if(!c->isfloating && lt->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
-                               togglefloating(NULL);
+                       if(snap && nx >= wx && nx <= wx + ww
+                               && ny >= wy && ny <= wy + wh) {
+                               if(abs(wx - nx) < snap)
+                                       nx = wx;
+                               else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < snap)
+                                       nx = wx + ww - c->w - 2 * c->bw;
+                               if(abs(wy - ny) < snap)
+                                       ny = wy;
+                               else if(abs((wy + wh) - (ny + c->h + 2 * c->bw)) < snap)
+                                       ny = wy + wh - c->h - 2 * c->bw;
+                               if(!c->isfloating && lt->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
+                                       togglefloating(NULL);
+                       }
                        if(!lt->arrange || c->isfloating)
                                resize(c, nx, ny, c->w, c->h, False);
                        break;
@@ -1193,8 +1199,12 @@ resizemouse(Client *c) {
                        XSync(dpy, False);
                        nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
                        nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
-                       if(!c->isfloating && lt->arrange && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) {
-                               togglefloating(NULL);
+
+                       if(snap && nw >= wx && nw <= wx + ww
+                               && nh >= wy && nh <= wy + wh) {
+                               if(!c->isfloating && lt->arrange
+                                  && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
+                                       togglefloating(NULL);
                        }
                        if(!lt->arrange || c->isfloating)
                                resize(c, c->x, c->y, nw, nh, True);
@@ -1572,22 +1582,32 @@ updatebar(void) {
 
 void
 updategeom(void) {
-       unsigned int i;
-
-#ifdef CUSTOMGEOM /* define your own if you are Xinerama user */
-       CUSTOMGEOM
-#else
-       /* bar geometry*/
-       bx = 0;
-       by = showbar ? (topbar ? 0 : sh - bh) : -bh;
-       bw = sw;
+       int i;
+#ifdef XINERAMA
+       XineramaScreenInfo *info = NULL;
 
        /* window area geometry */
-       wx = sx;
-       wy = showbar && topbar ? sy + bh : sy;
-       ww = sw;
-       wh = showbar ? sh - bh : sh;
+       if(XineramaIsActive(dpy)) {
+               info = XineramaQueryScreens(dpy, &i);
+               wx = info[0].x_org;
+               wy = showbar && topbar ? info[0].y_org + info[0].height + bh : info[0].y_org;
+               ww = info[0].width;
+               wh = showbar ? info[0].height - bh : info[0].height;
+               XFree(info);
+       }
+       else
 #endif
+       {
+               wx = sx;
+               wy = showbar && topbar ? sy + bh : sy;
+               ww = sw;
+               wh = showbar ? sh - bh : sh;
+       }
+
+       /* bar geometry*/
+       bx = wx;
+       by = showbar ? (topbar ? 0 : wy + wh) : -bh;
+       bw = ww;
 
        /* update layout geometries */
        for(i = 0; i < LENGTH(layouts); i++)