2

I've been trying to create a simple program using libevdev to make a virtual device that will simply move the mouse by 50 points on the X axis every second. The program runs just fine, however Xorg won't recognize the newly created virtual device.

I suppose it's going to be something trivial, but I cannot figure out what.

Xorgs' logs say:

[  5860.310] (II) config/udev: Adding input device test device Mouse (/dev/input/event18)
[  5860.310] (II) No input driver specified, ignoring this device.
[  5860.310] (II) This device may have been added with another device file.

The program:

#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static void check(int i) {
    if (i < 0) {        
        printf("%s\n", strerror(-i));
        exit(1);
    }
}

int main() {
    struct libevdev* evdev = libevdev_new();
    libevdev_set_name(evdev, "test device Mouse");
    libevdev_set_id_vendor(evdev, 0x1);
    libevdev_set_id_product(evdev, 0x1);
    libevdev_set_id_version(evdev, 0x1);
    libevdev_set_id_bustype(evdev, BUS_USB);

    check(libevdev_enable_event_type(evdev, EV_REL));
    check(libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL));
    check(libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL));
    check(libevdev_enable_event_code(evdev, EV_SYN, SYN_REPORT, NULL));

    struct libevdev_uinput* uinput;
    check(libevdev_uinput_create_from_device(evdev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput));

    for (int i = 0; i < 1000; i++) {
        check(libevdev_uinput_write_event(uinput, EV_REL, REL_X, 50));
        check(libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0));

        sleep(1);
    }
}

What am I doing wrong?

hoz
  • 176
  • 1
  • 7

1 Answers1

3

The issue was that mouse buttons need to be enabled for mouse movements to work.

Adding these lines fixes the issue:

check(libevdev_enable_event_type(evdev, EV_KEY));
check(libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL));
check(libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL));
hoz
  • 176
  • 1
  • 7