commit 332b10f47dba755a91d9b7a8f1f30d0ffa1a14b4
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 15 Aug 2022 09:44:37 +0100
initial working version
Diffstat:
4 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,7 @@
+PROGRAM=adb-forward-touch
+default: $(PROGRAM)
+PREFIX ?= /usr/local
+
+install:
+ mkdir -p $(PREFIX)/bin
+ cp $(PROGRAM) $(PREFIX)/bin
diff --git a/adb-forward-touch.c b/adb-forward-touch.c
@@ -0,0 +1,72 @@
+#include <linux/uinput.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+
+
+
+void set_axis(int fd, unsigned short code, int max)
+{
+ struct uinput_abs_setup abs_setup;
+ memset(&abs_setup, 0, sizeof abs_setup);
+ abs_setup.code = code;
+ abs_setup.absinfo.maximum = max;
+ ioctl(fd, UI_SET_ABSBIT, code);
+ ioctl(fd, UI_ABS_SETUP, &abs_setup);
+}
+
+int main(void)
+{
+ struct uinput_setup usetup;
+ int i = 50;
+
+ FILE *from_android = popen("adb exec-out getevent /dev/input/event2", "r");
+
+ int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
+
+ ioctl(fd, UI_SET_EVBIT, EV_KEY);
+ ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH);
+
+ ioctl(fd, UI_SET_EVBIT, EV_ABS);
+
+ set_axis(fd, ABS_X, 1079);
+ set_axis(fd, ABS_Y, 1919);
+ set_axis(fd, ABS_PRESSURE, 255);
+ set_axis(fd, ABS_MT_SLOT, 9);
+ set_axis(fd, ABS_MT_TOUCH_MAJOR, 15);
+ set_axis(fd, ABS_MT_TOUCH_MINOR, 15);
+ set_axis(fd, ABS_MT_ORIENTATION, 1);
+ set_axis(fd, ABS_MT_POSITION_X, 1079);
+ set_axis(fd, ABS_MT_POSITION_Y, 1919);
+ set_axis(fd, ABS_MT_TRACKING_ID, 65535);
+ set_axis(fd, ABS_MT_TOOL_TYPE, 15);
+ set_axis(fd, ABS_MT_PRESSURE, 255);
+
+ ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
+
+ memset(&usetup, 0, sizeof(usetup));
+ usetup.id.bustype = BUS_USB;
+ usetup.id.vendor = 0x06cb;
+ usetup.id.product = 0x0af9;
+ strcpy(usetup.name, "Synaptics s3203b");
+ ioctl(fd, UI_DEV_SETUP, &usetup);
+
+ ioctl(fd, UI_DEV_CREATE);
+
+ while (true) {
+ struct input_event ie;
+ if(fscanf(from_android, "%hx %hx %x",
+ &ie.type, &ie.code, &ie.value) == EOF)
+ break;
+ if(write(fd, &ie, sizeof(ie)) < 0)
+ break;
+ }
+
+ ioctl(fd, UI_DEV_DESTROY);
+ close(fd);
+
+ return 0;
+}
diff --git a/build.nix b/build.nix
@@ -0,0 +1 @@
+with import <nixpkgs> {} ; callPackage ./. {}
diff --git a/default.nix b/default.nix
@@ -0,0 +1,6 @@
+{ stdenv }: stdenv.mkDerivation {
+ name = "adb-forward-touch";
+ version = "0.5";
+ src = ./.;
+ makeFlags = [ "PREFIX=$$out" ];
+}