Problem is that when I use libevdev (which is needed for game controllers under Linux), it locks up x11 events until I produce an input on a game controller. Libevdev documentation is cryptic and incomplete, with many implementations using read() instead of libevdev_next_event() for some reason. Only help with it is how to configure it on various Linux distros, or that which library already solves this issue, except they would force me to use them for a lot of other things, and would still force me to write abstractions to make things looking nice.

all 6 comments

sorted by: hot top controversial new old
[–] 1 point 11 months ago (5 children)
  • [–] [S] 1 point 11 months ago (4 children)

    Did that too, still the lockup issue persisted.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 2 points 11 months ago (2 children)

    Their sample code:

    struct libevdev *dev = NULL;
     int fd;
     int rc = 1;
    
     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));
     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;
             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);
    

    Is definitely doing the polling in a blocking way. I think this is intended to be run on a separate thread, and you pass the inputs to your main application thread via some other mechanism.

    If your using the polling function, you should be able to do it in a single thread, but then you have to periodically check in between doing other work.

  • source
  • parent
  • hideshow 2 child comments
  • [–] [S] 2 points 11 months ago (1 child)

    The separate thread did the trick for the most part, now I'm having a different issue, where I'll likely need a debugger. Let's hope Seer works for me and I don't have to spend a month to learn GDB, just so I don't spend 30 mins every time I need to search for a feature I don't know.

  • source
  • parent
  • hideshow 1 child comment