Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support old uinput interface #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
41 changes: 30 additions & 11 deletions Daemon/ydotoold.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,38 @@ static void uinput_setup(int fd, enum ydotool_uinput_setup_options setup_opt) {
}
}

static const struct uinput_setup usetup = {
.name = "ydotoold virtual device",
.id = {
.bustype = BUS_VIRTUAL,
.vendor = 0x2333,
.product = 0x6666,
.version = 1
int rc, version;
rc = ioctl(fd, UI_GET_VERSION, &version);

// https://kernel.org/doc/html/latest/input/uinput.html#uinput-old-interface
if (rc == 0 && version >= 5) {
static const struct uinput_setup usetup = {
.name = "ydotoold virtual device",
.id = {
.bustype = BUS_VIRTUAL,
.vendor = 0x2333,
.product = 0x6666,
.version = 1
}
};

if (ioctl(fd, UI_DEV_SETUP, &usetup)) {
perror("UI_DEV_SETUP ioctl failed");
exit(2);
}
};
} else {
// see /include/uapi/linux/uinput.h
static const struct uinput_user_dev uud = {
.name = "ydotoold virtual device",
.id = {
.bustype = BUS_VIRTUAL,
.vendor = 0x2333,
.product = 0x6666,
.version = 1
}
};

if (ioctl(fd, UI_DEV_SETUP, &usetup)) {
perror("UI_DEV_SETUP ioctl failed");
exit(2);
write(fd, &uud, sizeof(uud));
}

if (ioctl(fd, UI_DEV_CREATE)) {
Expand Down