Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions abs-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ int init_uinput(int tmin_x, int tmax_x, int tmin_y, int tmax_y) {

if (ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0 ||
ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) < 0 ||
ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH) < 0 ||
ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_PEN) < 0 ||
ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0 ||
ioctl(fd, UI_SET_ABSBIT, ABS_X) < 0 ||
ioctl(fd, UI_SET_ABSBIT, ABS_Y) < 0 ||
ioctl(fd, UI_SET_ABSBIT, ABS_PRESSURE) < 0 ||
ioctl(fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT) < 0 ||
ioctl(fd, UI_SET_EVBIT, EV_SYN) < 0) {
perror("ioctl uinput setup");
close(fd);
Expand All @@ -152,6 +156,8 @@ int init_uinput(int tmin_x, int tmax_x, int tmin_y, int tmax_y) {
uidev.absmax[ABS_X] = tmax_x;
uidev.absmin[ABS_Y] = tmin_y;
uidev.absmax[ABS_Y] = tmax_y;
uidev.absmin[ABS_PRESSURE] = 0;
uidev.absmax[ABS_PRESSURE] = 8191;

ssize_t wrote = write(fd, &uidev, sizeof(uidev));
if (wrote != (ssize_t)sizeof(uidev)) {
Expand All @@ -167,6 +173,20 @@ int init_uinput(int tmin_x, int tmax_x, int tmin_y, int tmax_y) {
return fd;
}

static inline bool emit_pen_tool_state(void) {
struct input_event ev[2] = {
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 }
};

ssize_t wrote = write(tab_fd, ev, sizeof(ev));
if (wrote != (ssize_t)sizeof(ev)) {
perror("write BTN_TOOL_PEN");
return false;
}
return true;
}

static inline int test_bit(int bit, const unsigned long *array) {
return (array[bit / (8 * sizeof(unsigned long))] >> (bit % (8 * sizeof(unsigned long)))) & 1;
}
Expand Down Expand Up @@ -438,7 +458,10 @@ int main(int argc, char *argv[]) {


int x = 0, y = 0;
int x_old = -1, y_old = -1;
int pressure = 0;
bool is_down = false;
bool got_x = false;
bool got_y = false;
bool active;

if (config.enable_tosu == true) {
Expand Down Expand Up @@ -468,6 +491,10 @@ int main(int argc, char *argv[]) {
set_grab(fd, &grabbed, active);

if (active == true) {
if (!emit_pen_tool_state()) {
break;
}

if (poll(&pfd, 1, -1) <= 0)
continue;
if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
Expand All @@ -485,39 +512,45 @@ int main(int argc, char *argv[]) {
if (rd != sizeof(ev))
continue;

bool x_dirty = false;
bool y_dirty = false;

if (ev.type == EV_ABS) {
if (ev.code == ABS_X && ev.value != x_old) {
if (ev.code == ABS_X) {
x = ev.value;
x_dirty = true;
got_x = true;
}
else if (ev.code == ABS_Y && ev.value != y_old) {
else if (ev.code == ABS_Y) {
y = ev.value;
y_dirty = true;
got_y = true;
}

if (x_dirty || y_dirty) {
if (!emit_abs_delta(x, y, x_dirty, y_dirty)) {
}
else if (ev.type == EV_SYN && ev.code == SYN_REPORT) {
if (got_x && got_y) {
if (!emit_abs_delta(x, y, true, true)) {
Comment on lines +527 to +528

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Emit movement when either axis changes per frame

Many evdev tablets emit only the axis that changed before SYN_REPORT (e.g., pure horizontal movement can be ABS_X only). The new if (got_x && got_y) condition drops those frames, so single-axis motion is not forwarded until the other axis changes, which makes the cursor stall or jump and is a functional regression from the previous x_dirty || y_dirty behavior.

Useful? React with 👍 / 👎.

break;
}
x_old = x;
y_old = y;
got_x = false;
got_y = false;
}
}

if (config.enable_buttons &&
ev.type == EV_KEY &&
ev.code == BTN_LEFT) {
is_down = (ev.value != 0);
if (is_down) {
pressure = 8191;
} else {
pressure = 0;
}
(void)pressure;

struct input_event btn[2] = {
struct input_event btn[3] = {
{ .type = EV_KEY, .code = BTN_LEFT, .value = ev.value },
{ .type = EV_KEY, .code = BTN_TOUCH, .value = is_down ? 1 : 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 }
};
ssize_t bw = write(tab_fd, btn, sizeof(btn));
if (bw != (ssize_t)sizeof(btn)) {
perror("write BTN_LEFT");
perror("write BTN_LEFT/BTN_TOUCH");
break;
}
}
Expand Down