swaywm / swaylock

Screen locker for Wayland
MIT License
852 stars 202 forks source link

Strange input behavior after switching VTs #94

Open shroff opened 5 years ago

shroff commented 5 years ago

This seems to happen pretty consistently for me, that when I switch to a different VT and back, swaylock seems to start treating u as Esc (clearing input) and d as return (verifying password) - the reverse is not true. I can only unlock by logging into a different VT and running killall -9 swaylock.

Which flags I use don't seem to make a difference as calling swaylock -f from a terminal yields a the same result. I have to run with -f from a terminal since without it, swaylock crashes with wl_display@1: error 0: invalid object xx when I log in from a VT;

I have also attempted this on another machine and get the same result. swaylock -v reports 1.3, but pacman shows package version 1.4.2

shroff commented 5 years ago

Digging around with the code, it looks like the modifier key press state gets out of sync when you switch VTs, since the key release events don't get captured. A quick workaround is to press ctrl to reset state and it works fine after that.

Feel free to close or leave open to track.

michalrus commented 4 years ago

Feel free to close or leave open to track.

Let’s not close that, as that’s surely a bug!


Code to detect VT switches could be something like:

  int fd;
  if ((fd = open("/dev/console", O_NOCTTY)) < 0) {
    perror("open");
    _exit(-1);
  }

  for (;;) {
    struct vt_event ev;
    memset(&ev, 0, sizeof(ev));
    ev.event = VT_EVENT_SWITCH;
    if (ioctl(fd, VT_WAITEVENT, &ev) < 0) {
      perror("ioctl");
      _exit(-2);
    }
    handle_vt_switch(ev.oldev, ev.newev);
  }

oldev is the previous VT, and newev is the new one, as per https://github.com/torvalds/linux/blob/c0cc271173b2e1c2d8d0ceaef14e4dfa79eefc0d/include/uapi/linux/vt.h#L66-L78