Skip to content

Commit

Permalink
fix: segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 14, 2023
1 parent a90cae6 commit 5df40cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions app/src/main/cpp/touchpad_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Java_xtr_keymapper_server_InputService_startTouchpadDirect(JNIEnv *env, jobject
poll_fds.clear();
uinput_fds.clear();

printf("I: Searching for touchpad devices...\n");
for (auto & evdev : evdevNames) {
int device_fd = open(evdev.c_str(), O_RDWR);
if (device_fd < 0) {
Expand All @@ -170,7 +171,14 @@ Java_xtr_keymapper_server_InputService_startTouchpadDirect(JNIEnv *env, jobject
printf("device: %s\n", dev_name);
}

// Ignore virtual tablet
if (HasInputProp(device_fd, INPUT_PROP_POINTER)) {
printf("has INPUT_PROP_POINTER", dev_name);
} else {
close(device_fd);
continue;
}

// Ignore virtual tablet
if (strcmp(x_virtual_tablet, dev_name) == 0)
continue;

Expand All @@ -181,17 +189,13 @@ Java_xtr_keymapper_server_InputService_startTouchpadDirect(JNIEnv *env, jobject
continue;
}

printf(" adding touchpad device...\n", evdev.c_str());

if(HasInputProp(device_fd, INPUT_PROP_POINTER)) {
printf("\n%s has INPUT_PROP_POINTER\n ");
printf("add touchpad device: %s\n", evdev.c_str());
ioctl(device_fd, EVIOCGRAB, (void *)1);
poll_fds.push_back(pollfd{device_fd, POLLIN, 0});
uinput_fds.push_back(SetupUinputDevice(device_fd));
}

}
ioctl(device_fd, EVIOCGRAB, (void *)1);

poll_fds.push_back(pollfd{device_fd, POLLIN, 0});
uinput_fds.push_back(SetupUinputDevice(device_fd));
}
if (poll_fds.empty()) return;

looper = std::thread(start);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private boolean addNewDevices(String[] data) {
if (isWaylandClient) return true;
if( !currentDevice.equals(evdev) )
if (input_event[1].equals("EV_REL")) {
System.out.println("add device: " + evdev);
System.out.println("add mouse device: " + evdev);
currentDevice = evdev;
}
return true;
Expand Down

0 comments on commit 5df40cb

Please sign in to comment.