nsxivd81442f
Own win method for mouse cursor location
+16 −6
3 files changed
- M commands.c +4 −6
- M window.c +11 −0
- M window.h +1 −0
| @@ -322,19 +322,17 @@ bool ci_scroll_to_edge(arg_t dir) | |||
| 322 | 322 | ||
| 323 | 323 | bool ci_drag(arg_t _) | |
| 324 | 324 | { | |
| 325 | − | int i, x, y; | |
| 325 | + | int x, y; | |
| 326 | 326 | float px, py; | |
| 327 | − | unsigned int ui; | |
| 328 | 327 | XEvent e; | |
| 329 | − | Window w; | |
| 330 | 328 | ||
| 331 | − | if ((int)(img.w * img.zoom) < win.w && (int)(img.h * img.zoom) < win.h) | |
| 332 | − | return false; | |
| 333 | − | if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &x, &y, &ui)) | |
| 329 | + | if ((int)(img.w * img.zoom) <= win.w && (int)(img.h * img.zoom) <= win.h) | |
| 334 | 330 | return false; | |
| 335 | 331 | ||
| 336 | 332 | win_set_cursor(&win, CURSOR_DRAG); | |
| 337 | 333 | ||
| 334 | + | win_cursor_pos(&win, &x, &y); | |
| 335 | + | ||
| 338 | 336 | for (;;) { | |
| 339 | 337 | px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8) | |
| 340 | 338 | * (win.w - img.w * img.zoom); | |
| @@ -470,3 +470,14 @@ void win_set_cursor(win_t *win, cursor_t cursor) | |||
| 470 | 470 | XFlush(win->env.dpy); | |
| 471 | 471 | } | |
| 472 | 472 | } | |
| 473 | + | ||
| 474 | + | void win_cursor_pos(win_t *win, int *x, int *y) | |
| 475 | + | { | |
| 476 | + | int i; | |
| 477 | + | unsigned int ui; | |
| 478 | + | Window w; | |
| 479 | + | ||
| 480 | + | if (!XQueryPointer(win->env.dpy, win->xwin, &w, &w, &i, &i, x, y, &ui)) | |
| 481 | + | *x = *y = 0; | |
| 482 | + | } | |
| 483 | + | ||
| @@ -106,5 +106,6 @@ int win_textwidth(const win_env_t*, const char*, unsigned int, bool); | |||
| 106 | 106 | ||
| 107 | 107 | void win_set_title(win_t*, const char*); | |
| 108 | 108 | void win_set_cursor(win_t*, cursor_t); | |
| 109 | + | void win_cursor_pos(win_t*, int*, int*); | |
| 109 | 110 | ||
| 110 | 111 | #endif /* WINDOW_H */ | |