Commit 64b93423 authored by abmyii's avatar abmyii
Browse files

Fix full input using fake input device

parent 47802f0e
......@@ -72,7 +72,9 @@ thread_local int dummy_tls[2];
struct libevdev *dev;
struct libevdev_uinput *uidev;
struct libevdev_uinput *uidev2;
bool lmb;
void shutdown(int)
{
......@@ -457,25 +459,24 @@ static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
}
bool lmb;
static void doptr(int buttonMask, int x, int y, rfbClientPtr cl)
{
int left_down = buttonMask & 0x1;
if (left_down) {
libevdev_uinput_write_event(uidev2, EV_ABS, ABS_MT_TRACKING_ID, 10);
libevdev_uinput_write_event(uidev2, EV_KEY, BTN_TOUCH, 1);
libevdev_uinput_write_event(uidev2, EV_KEY, BTN_TOOL_FINGER, 1);
libevdev_uinput_write_event(uidev2, EV_ABS, ABS_MT_POSITION_X, x*2.5);
libevdev_uinput_write_event(uidev2, EV_ABS, ABS_MT_POSITION_Y, y*2.5);
libevdev_uinput_write_event(uidev2, EV_SYN, SYN_REPORT, 0);
libevdev_uinput_write_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 10);
libevdev_uinput_write_event(uidev, EV_KEY, BTN_TOUCH, 1);
libevdev_uinput_write_event(uidev, EV_KEY, BTN_TOOL_FINGER, 1);
libevdev_uinput_write_event(uidev, EV_ABS, ABS_MT_POSITION_X, x*2.5);
libevdev_uinput_write_event(uidev, EV_ABS, ABS_MT_POSITION_Y, y*2.5);
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
lmb = true;
}
else if (lmb) {
libevdev_uinput_write_event(uidev2, EV_ABS, ABS_MT_TRACKING_ID, -1);
libevdev_uinput_write_event(uidev2, EV_KEY, BTN_TOUCH, 0);
libevdev_uinput_write_event(uidev2, EV_KEY, BTN_TOOL_FINGER, 0);
libevdev_uinput_write_event(uidev2, EV_SYN, SYN_REPORT, 0);
libevdev_uinput_write_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, -1);
libevdev_uinput_write_event(uidev, EV_KEY, BTN_TOUCH, 0);
libevdev_uinput_write_event(uidev, EV_KEY, BTN_TOOL_FINGER, 0);
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
lmb = false;
}
}
......@@ -550,16 +551,36 @@ try
bool query_params_only = false;
int capture_interval = 1;
// Fake keyboard device (https://stackoverflow.com/q/23092855)
// Fake input device (https://stackoverflow.com/q/23092855)
dev = libevdev_new();
libevdev_set_name(dev, "fake keyboard device");
libevdev_set_name(dev, "mirvncserver input device");
libevdev_set_id_vendor(dev, 0x1);
libevdev_set_id_product(dev, 0x1);
libevdev_set_id_version(dev, 0x1);
libevdev_set_id_bustype(dev, BUS_USB);
// (Absolute) pointer input (http://who-t.blogspot.com/2013/09/libevdev-accessing-and-modifying-devices.html)
struct input_absinfo abs;
abs.minimum = abs.resolution = abs.fuzz = abs.flat = 0;
libevdev_enable_event_type(dev, EV_ABS);
abs.maximum = 9;
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_SLOT, &abs);
libevdev_enable_event_type(dev, EV_REL);
libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
abs.maximum = 65535;
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_TRACKING_ID, &abs);
abs.maximum = 1080;
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_POSITION_X, &abs);
abs.maximum = 1920;
libevdev_enable_event_code(dev, EV_ABS, ABS_MT_POSITION_Y, &abs);
// Keyboard input
libevdev_enable_event_type(dev, EV_KEY);
libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
for (int i = 0; i < KEY_MAX; i++)
libevdev_enable_event_code(dev, EV_KEY, i, NULL);
......@@ -567,18 +588,6 @@ try
LIBEVDEV_UINPUT_OPEN_MANAGED,
&uidev);
// Touch event
int rc;
int fd;
const char *path;
struct libevdev *dev2;
fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
libevdev_new_from_fd(fd, &dev2);
libevdev_uinput_create_from_device(dev2,
LIBEVDEV_UINPUT_OPEN_MANAGED,
&uidev2);
//avoid unused warning/error
dummy_tls[0] = 0;
......@@ -715,8 +724,7 @@ try
// Clear libevdev devices
libevdev_uinput_destroy(uidev);
libevdev_free(dev2);
close(fd);
libevdev_free(dev);
return EXIT_SUCCESS;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment