initial working version

main
Daniel Barlow 2022-08-15 09:44:37 +01:00
commit 332b10f47d
4 changed files with 86 additions and 0 deletions

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
PROGRAM=adb-forward-touch
default: $(PROGRAM)
PREFIX ?= /usr/local
install:
mkdir -p $(PREFIX)/bin
cp $(PROGRAM) $(PREFIX)/bin

72
adb-forward-touch.c Normal file
View File

@ -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;
}

1
build.nix Normal file
View File

@ -0,0 +1 @@
with import <nixpkgs> {} ; callPackage ./. {}

6
default.nix Normal file
View File

@ -0,0 +1,6 @@
{ stdenv }: stdenv.mkDerivation {
name = "adb-forward-touch";
version = "0.5";
src = ./.;
makeFlags = [ "PREFIX=$$out" ];
}