Added variable scroll speed and direction
This commit is contained in:
parent
ad3537ff69
commit
9087b1deba
31
anyscroll.c
31
anyscroll.c
|
@ -14,23 +14,31 @@ 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++) {
|
||||||
XTestFakeButtonEvent(dpy, btn, True, CurrentTime);
|
tx++;
|
||||||
XFlush(dpy);
|
if (tx % pixels_to_scroll == 0) {
|
||||||
XTestFakeButtonEvent(dpy, btn, False, CurrentTime);
|
XTestFakeButtonEvent(dpy, btn, True, CurrentTime);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
|
XTestFakeButtonEvent(dpy, btn, False, CurrentTime);
|
||||||
|
XFlush(dpy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +69,7 @@ static void getmousepos(int *px, int *py) {
|
||||||
static void* loop() {
|
static void* loop() {
|
||||||
int px, py, lx, ly, dx, dy;
|
int px, py, lx, ly, dx, dy;
|
||||||
while (1) {
|
while (1) {
|
||||||
lx = px, ly = py;
|
lx = px, ly = py;
|
||||||
getmousepos(&px, &py);
|
getmousepos(&px, &py);
|
||||||
dx = px - lx;
|
dx = px - lx;
|
||||||
dy = py - ly;
|
dy = py - ly;
|
||||||
|
@ -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