summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@sendula.com>2021-04-13 00:21:44 +0100
committerdavidovski <david@sendula.com>2021-04-13 00:21:44 +0100
commitd6bb142887b06b2d92de359d5784b7ac40fe734d (patch)
treefa34fdd18352c2d9ebda80eb435de20dc3b318e3
parentdc1db3a1f58b1bd7004153b2f04e85e719489209 (diff)
added basic scrolling
-rw-r--r--anyscroll.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/anyscroll.c b/anyscroll.c
index ab24876..c441bb8 100644
--- a/anyscroll.c
+++ b/anyscroll.c
@@ -9,9 +9,25 @@
static Display *dpy;
static int scr, sw, sh;
-static int sx, sy;
+static int sx = -1, sy = -1;
static Window root;
+
+static void scroll(int v) {
+ int btn;
+ if (v > 0) btn = 4;
+ else if (v < 0) btn = 5;
+ else return;
+
+ for (int i = 0; i < abs(v); i++) {
+ XTestFakeButtonEvent(dpy, btn, True, CurrentTime);
+ XFlush(dpy);
+// usleep(100000);
+ XTestFakeButtonEvent(dpy, btn, False, CurrentTime);
+ XFlush(dpy);
+ }
+}
+
static void select_events(Display *dpy, Window win) {
XIEventMask evmasks[1];
unsigned char mask1[(XI_LASTEVENT + 7)/8];
@@ -44,8 +60,10 @@ static void* loop() {
getmousepos(&px, &py);
dx = px - lx;
dy = py - ly;
- printf("(%d, %d) from (%d, %d)\n", px, py, sx, sy);
- sleep(1);
+
+ if (sx != -1 && sy != -1) scroll(dy);
+ printf("%d, %d with deltas (%d, %d)\n", sx, sy, dx, dy);
+ sleep(0.1);
}
@@ -53,9 +71,7 @@ static void* loop() {
static void mouse_down(XIRawEvent *xev) {
getmousepos(&sx, &sy);
-
printf("Button pressed %d @ %d, %d\n", xev->detail, sx, sy);
-
}
static void mouse_up(XIRawEvent *xev) {