Added variable scroll speed and direction
This commit is contained in:
parent
ad3537ff69
commit
9087b1deba
21
anyscroll.c
21
anyscroll.c
|
@ -14,24 +14,32 @@ static int scr, sw, sh;
|
||||||
static int sx = -1, sy = -1;
|
static int sx = -1, sy = -1;
|
||||||
static Window root;
|
static Window root;
|
||||||
|
|
||||||
static const int direction = -1;
|
static int tx, ty;
|
||||||
static const int pixels_to_scroll = 16;
|
static int vx, vy;
|
||||||
|
|
||||||
|
static const int direction = -1; // direction to scroll in. 1 is natural, -1 is in direction of movement
|
||||||
|
static const int pixels_to_scroll = 8; // number of pixels to move before one scroll event
|
||||||
|
|
||||||
|
|
||||||
static void scroll(int v) {
|
static void scroll(int v) {
|
||||||
v = v * direction;
|
v = v * direction;
|
||||||
|
printf("scrolling with v of %d\n", v);
|
||||||
|
|
||||||
int btn;
|
int btn;
|
||||||
if (v > 0) btn = 4;
|
if (v > 0) btn = 4;
|
||||||
else if (v < 0) btn = 5;
|
else if (v < 0) btn = 5;
|
||||||
else return;
|
else return;
|
||||||
|
|
||||||
int times = ceil(abs(v) / pixels_to_scroll) + 1;
|
int times = abs(v);
|
||||||
for (int i = 0; i < times; i++) {
|
for (int i = 0; i < times; i++) {
|
||||||
|
tx++;
|
||||||
|
if (tx % pixels_to_scroll == 0) {
|
||||||
XTestFakeButtonEvent(dpy, btn, True, CurrentTime);
|
XTestFakeButtonEvent(dpy, btn, True, CurrentTime);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
XTestFakeButtonEvent(dpy, btn, False, CurrentTime);
|
XTestFakeButtonEvent(dpy, btn, False, CurrentTime);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void select_events(Display *dpy, Window win) {
|
static void select_events(Display *dpy, Window win) {
|
||||||
|
@ -69,7 +77,7 @@ static void* loop() {
|
||||||
if (sx != -1 && sy != -1) scroll(dy);
|
if (sx != -1 && sy != -1) scroll(dy);
|
||||||
|
|
||||||
if (dx != 0 | dy != 0) {
|
if (dx != 0 | dy != 0) {
|
||||||
printf("%d, %d with deltas (%d, %d)\n", sx, sy, dx, dy);
|
//printf("%d, %d with deltas (%d, %d)\n", sx, sy, dx, dy);
|
||||||
}
|
}
|
||||||
sleep(0.1);
|
sleep(0.1);
|
||||||
}
|
}
|
||||||
|
@ -128,8 +136,9 @@ int main(int argc, const char **argv) {
|
||||||
if (xev->detail == 2) mouse_up(xev);
|
if (xev->detail == 2) mouse_up(xev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//if (t - CurrentTime < 500) {
|
||||||
XFreeEventData(dpy, cookie);
|
// XFreeEventData(dpy, cookie);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
} // there is no way out of this loop lol
|
} // there is no way out of this loop lol
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
Loading…
Reference in New Issue