Project main change: port to Wayland!

Welcome again!

The main summer project feature is you can record your own tests on Wayland. gnome-battery-bench is a battery testing software, so one of its features is recording actions on the computer such as keyboard keystrokes and mouse movements. However, that is not possible on Wayland because recording is X11 dependant nowadays, so our mission is get in working on Wayland.

To do that, we did a research about how Wayland works. The conclusion was Wayland has a strong security base and it is not possible to get input devices events from it. Talking with @jadahl and @garnacho at gnome-shell channel on GNOME chat, my mentor and I conclude to use libevdev to get mouse and keyboard events. Below there is a commented example of how to use the library:

struct libevdev *dev = NULL;
int fd;
int rc = 1;

#Open input event file corresponding to device you want to record.
fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
rc = libevdev_new_from_fd(fd, &dev);
if (rc < 0) {
    fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
    exit(1);
}
printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
printf("Input device ID: bus %#x vendor %#x product %#x\n",
    libevdev_get_id_bustype(dev),
    libevdev_get_id_vendor(dev),
    libevdev_get_id_product(dev));

#On this case, check device is a mouse
if (!libevdev_has_event_type(dev, EV_REL) ||
    !libevdev_has_event_code(dev, EV_KEY, BTN_LEFT)) {
    printf("This device does not look like a mouse\n");
    exit(1);
}
do {
    struct input_event ev;
    #Get event and print some information like event type and code
    rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
    if (rc == 0)
        printf("Event: %s %s %d\n",
            libevdev_event_type_get_name(ev.type),
            libevdev_event_code_get_name(ev.type, ev.code),
            ev.value);
} while (rc == 1 || rc == 0 || rc == -EAGAIN);

Using this, we trying to record all mouse and keyboards events:

  • Mouse left, right and middle button clicks.
  • Mouse movements.
  • Keyboard keystrokes.

Furthermore, we need to have the same test recording output file as X11 implementation. That could be challenging!

Thank you for reading!

One thought on “Project main change: port to Wayland!

Comments are closed.