Krolyxon
Commit d81442f

Branches

Refs →

nsxivd81442f

Own win method for mouse cursor location

Author
Bert Münnich
Date
2017-10-05 13:47 +0200
Parent
b8fd923
Commit
d81442f55dd1414fd23617044ea157de8d9f1baa

+16 −6

3 files changed

  1. M commands.c +4 −6
  2. M window.c +11 −0
  3. M window.h +1 −0
M commands.c View
@@ -322,19 +322,17 @@ bool ci_scroll_to_edge(arg_t dir)
322322
323323 bool ci_drag(arg_t _)
324324 {
325− int i, x, y;
325+ int x, y;
326326 float px, py;
327− unsigned int ui;
328327 XEvent e;
329− Window w;
330328
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)
334330 return false;
335331
336332 win_set_cursor(&win, CURSOR_DRAG);
337333
334+ win_cursor_pos(&win, &x, &y);
335+
338336 for (;;) {
339337 px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
340338 * (win.w - img.w * img.zoom);
M window.c View
@@ -470,3 +470,14 @@ void win_set_cursor(win_t *win, cursor_t cursor)
470470 XFlush(win->env.dpy);
471471 }
472472 }
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+
M window.h View
@@ -106,5 +106,6 @@ int win_textwidth(const win_env_t*, const char*, unsigned int, bool);
106106
107107 void win_set_title(win_t*, const char*);
108108 void win_set_cursor(win_t*, cursor_t);
109+void win_cursor_pos(win_t*, int*, int*);
109110
110111 #endif /* WINDOW_H */