nsxivc8fcc3d
Wrap the pointer when the edge of the window is reached
+22 −3
1 file changed
- M commands.c +22 −3
| @@ -289,10 +289,29 @@ bool i_drag(arg_t a) | |||
| 289 | 289 | case MotionNotify: | |
| 290 | 290 | x = e.xmotion.x; | |
| 291 | 291 | y = e.xmotion.y; | |
| 292 | − | if (x >= 0 && x <= win.w && y >= 0 && y <= win.h) { | |
| 293 | − | dx += x - ox; | |
| 294 | − | dy += y - oy; | |
| 292 | + | ||
| 293 | + | #define WARP(x, y) \ | |
| 294 | + | XWarpPointer(win.env.dpy, \ | |
| 295 | + | None, win.xwin, \ | |
| 296 | + | 0, 0, 0, 0, \ | |
| 297 | + | x, y); \ | |
| 298 | + | ox = x, oy = y; \ | |
| 299 | + | break | |
| 300 | + | ||
| 301 | + | /* wrap the mouse around */ | |
| 302 | + | if(x < 0){ | |
| 303 | + | WARP(win.w, y); | |
| 304 | + | }else if(x > win.w){ | |
| 305 | + | WARP(0, y); | |
| 306 | + | }else if(y < 0){ | |
| 307 | + | WARP(x, win.h); | |
| 308 | + | }else if(y > win.h){ | |
| 309 | + | WARP(x, 0); | |
| 295 | 310 | } | |
| 311 | + | ||
| 312 | + | dx += x - ox; | |
| 313 | + | dy += y - oy; | |
| 314 | + | ||
| 296 | 315 | ox = x; | |
| 297 | 316 | oy = y; | |
| 298 | 317 | break; | |