Sample Header Ad - 728x90

libinput example program doesn't get any events

0 votes
1 answer
224 views
https://wayland.freedesktop.org/libinput/doc/latest/api/index.html Following the simple example program in their website i made the following , but the loop never executes , meaning no events where in the queue. Am i missing something ? Since this is the example in the website i expected it to work , or atleast enter the loop.
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static int open_restricted(const char *path, int flags, void *user_data) {
  int fd = open(path, flags);
  return fd < 0 ? -errno : fd;
}

static void close_restricted(int fd, void *user_data) { close(fd); }

const static struct libinput_interface interface = {
    .open_restricted = open_restricted,
    .close_restricted = close_restricted,
};

int main(void) {
  struct libinput *li;
  struct libinput_event *event;
  struct udev *udev_ctx = udev_new();
  assert(udev_ctx && "udev was null");

  li = libinput_udev_create_context(&interface, NULL, udev_ctx);
  assert(li != NULL && "li was null");
  libinput_udev_assign_seat(li, "seat0");
  libinput_dispatch(li);

  printf("Hello");

  while ((event = libinput_get_event(li)) != NULL) {

    printf("loop");
    // handle the event here

    libinput_event_destroy(event);
    libinput_dispatch(li);
  }

  libinput_unref(li);

  return 0;
}
system info:
- system: "x86_64-linux"
 - host os: Linux 6.6.31, NixOS, 24.05 (Uakari), 24.05.20240521.5710852
 - multi-user?: no
 - sandbox: yes
 - version: nix-env (Nix) 2.18.2
 - channels(root): "nixos-23.05"
 - nixpkgs: not found
--------

❯ libinput --version
1.25.0
--------

❯ systemctl --version
systemd 255 (255.6)
+PAM +AUDIT -SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 +PWQUALITY +P11KIT +QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK -XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified
Build with :
gcc -o test main.cpp pkg-config --cflags --libs libinput  pkg-config --cflags --libs libudev
Asked by Lampros (143 rep)
May 26, 2024, 10:56 AM
Last activity: Aug 25, 2024, 03:28 PM