xremap / nix-flake

MIT License
45 stars 12 forks source link

dwt not being respected in NixOS #76

Open rytswd opened 2 months ago

rytswd commented 2 months ago

Hi folks -- sorry this is probably my misconfiguration somewhere, but I haven't been able to pinpoint what I have got wrong for the dwt, disable while typing support on NixOS using this flake... I was following https://github.com/xremap/xremap/issues/152, but did not have too much luck with it either.

I'm using niri (https://github.com/YaLTeR/niri) which supports dwt from libinput, and when I stop xremap, I can confirm that dwt is suppressing the touchpad correctly. But when xremap is running, touchpad is still fully active, leading to so many unexpected cursor movements.

The below is the snippet of my setup using home-manager.

{ pkgs
, lib
, config
, inputs
, ...}:

{
  imports = [ inputs.xremap.homeManagerModules.default ];

  services.xremap = {
    enable = true;
    withWlroots = true;
    # Ensures I do not have to restart the service when definition changes
    watch = true;
    deviceNames = [
      "Asus Keyboard"
    ];
    yamlConfig = (builtins.readFile ./xremap.yaml);
  };
}

I thought I may need to add the touchpad into the deviceNames, but when I do that, it becomes completely unresponsive. I think I'm missing something quite basic, but if anyone could shed some light, that would be much appreciated!

VTimofeenko commented 2 months ago

I am using hyprland and the hyprland.conf's:

input {
...
    touchpad {
    ...
        disable_while_typing = true
    }

Works without setting any other settings in the system. Not sure how specifically hyprland interacts with libinput to make this setting work and why niri is different. Might be worth trying out in a dev vm.

One difference is that I am using a user service as opposed to HM one (config link)

rytswd commented 2 months ago

Thanks for the input @VTimofeenko -- I actually tried to do the same with Hyprland, but to no avail. The behaviour is the same between niri and Hyprland -- when I have xremap running, dwt setting gets ignored.

I appreciate the reference to your setup, I'll check more into that, and will report if I find anything 🙏

VTimofeenko commented 2 months ago

Can you try the system mode with niri but without application specifics? Something like this check's config.

rytswd commented 2 months ago

So I tried something like below using nixosModule

  services.xremap = {
    withWlroots = true;
    userName = "ryota";
    serviceMode = "user";
    watch = true;
    deviceNames = [
      "Asus Keyboard"
      # "ASUF1208:00 2808:0218 Touchpad"
    ];
    yamlConfig = (builtins.readFile ./tmp-xremap.yaml);
  };

This is still causing the same behaviour as home-manager setup, and I could confirm that's also the case with serviceMode = "system";.

One thing I could confirm is how the event ID gets updated when xremap is active.

With xremap running

$ libinput debug-events
event7  - ASUF1208:00 2808:0218 Touchpad: kernel bug: missing right button, assuming it is a clickpad.
-event3   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event4   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event0   DEVICE_ADDED            Power Button                      seat0 default group2  cap:k
-event2   DEVICE_ADDED            Lid Switch                        seat0 default group3  cap:S
-event1   DEVICE_ADDED            Sleep Button                      seat0 default group4  cap:k
-event5   DEVICE_ADDED            Yubico YubiKey OTP+FIDO+CCID      seat0 default group5  cap:k
-event11  DEVICE_ADDED            Asus Keyboard                     seat0 default group6  cap:kp left scroll-nat scroll-button
-event6   DEVICE_ADDED            ASUF1208:00 2808:0218 Mouse       seat0 default group7  cap:p left scroll-nat scroll-button
-event7   DEVICE_ADDED            ASUF1208:00 2808:0218 Touchpad    seat0 default group7  cap:pg  size 125x76mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on
-event12  DEVICE_ADDED            xremap                            seat0 default group8  cap:kp left scroll-nat scroll-button
 event12  KEYBOARD_KEY            +0.000s       *** (-1) pressed
a event12  KEYBOARD_KEY            +0.152s      *** (-1) released

Without xremap

$ libinput debug-events
event7  - ASUF1208:00 2808:0218 Touchpad: kernel bug: missing right button, assuming it is a clickpad.
-event3   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event4   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event0   DEVICE_ADDED            Power Button                      seat0 default group2  cap:k
-event2   DEVICE_ADDED            Lid Switch                        seat0 default group3  cap:S
-event1   DEVICE_ADDED            Sleep Button
-event5   DEVICE_ADDED            Yubico YubiKey OTP+FIDO+CCID      seat0 default group5  cap:k
-event11  DEVICE_ADDED            Asus Keyboard                     seat0 default group6  cap:kp left scroll-nat scroll-button
-event6   DEVICE_ADDED            ASUF1208:00 2808:0218 Mouse       seat0 default group7  cap:p left scroll-nat scroll-button
-event7   DEVICE_ADDED            ASUF1208:00 2808:0218 Touchpad    seat0 default group7  cap:pg  size 125x76mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on
-event11  KEYBOARD_KEY            +0.000s       *** (-1) pressed
a event11  KEYBOARD_KEY            +0.152s      *** (-1) released

For my case, event7 does have dwt-on, and seems to work correctly -- as in, without xremap, I get no event coming through with libinput debug-events when I'm typing. I'm assuming the translation from event11 (Asus Keyboard) to event12 (xremap) is affecting the dwt settings. Would you be able to check if you see a similar translation with your config?

VTimofeenko commented 2 months ago

Here's my outputs (hyprland, service running as my user from NixOS module).

I pressed "a" which is not remapped and "caps lock" which is rebound to "escape".

libinput debug-events
-event0   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event2   DEVICE_ADDED            Lid Switch                        seat0 default group2  cap:S
-event3   DEVICE_ADDED            Power Button                      seat0 default group3  cap:k
-event4   DEVICE_ADDED            FRMW0004:00 32AC:0006 Wireless Radio Control seat0 default group4  cap:k
-event5   DEVICE_ADDED            FRMW0004:00 32AC:0006 Consumer Control seat0 default group4  cap:kp scroll-nat
-event9   DEVICE_ADDED            PIXA3854:00 093A:0274 Mouse       seat0 default group5  cap:p left scroll-nat scroll-button
-event10  DEVICE_ADDED            PIXA3854:00 093A:0274 Touchpad    seat0 default group5  cap:pg  size 111x73mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on
-event1   DEVICE_ADDED            AT Translated Set 2 keyboard      seat0 default group6  cap:k
-event12  DEVICE_ADDED            xremap                            seat0 default group7  cap:kp left scroll-nat scroll-button
 event12  KEYBOARD_KEY            +0.000s   *** (-1) pressed
a event12  KEYBOARD_KEY            +0.042s  *** (-1) released
 event12  KEYBOARD_KEY            +1.438s   *** (-1) pressed
 event12  KEYBOARD_KEY            +1.438s   *** (-1) released
^[ event12  KEYBOARD_KEY            +7.381s *** (-1) pressed
 event12  KEYBOARD_KEY            +7.523s   *** (-1) pressed

Here's with xremap stopped:

-event0   DEVICE_ADDED            Video Bus                         seat0 default group1  cap:k
-event2   DEVICE_ADDED            Lid Switch                        seat0 default group2  cap:S
-event3   DEVICE_ADDED            Power Button                      seat0 default group3  cap:k
-event4   DEVICE_ADDED            FRMW0004:00 32AC:0006 Wireless Radio Control seat0 default group4  cap:k
-event5   DEVICE_ADDED            FRMW0004:00 32AC:0006 Consumer Control seat0 default group4  cap:kp scroll-nat
-event9   DEVICE_ADDED            PIXA3854:00 093A:0274 Mouse       seat0 default group5  cap:p left scroll-nat scroll-button
-event10  DEVICE_ADDED            PIXA3854:00 093A:0274 Touchpad    seat0 default group5  cap:pg  size 111x73mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on
-event1   DEVICE_ADDED            AT Translated Set 2 keyboard      seat0 default group6  cap:k
 event1   KEYBOARD_KEY            +0.000s   *** (-1) pressed
a event1   KEYBOARD_KEY            +0.049s  *** (-1) released
 event1   KEYBOARD_KEY            +1.167s   *** (-1) pressed
 event1   KEYBOARD_KEY            +1.247s   *** (-1) released
 event1   KEYBOARD_KEY            +6.070s   *** (-1) pressed
 event1   KEYBOARD_KEY            +6.550s   *** (-1) pressed
^C
rytswd commented 2 months ago

Thanks for the input! It does look like yours is behaving the same way as mine. Just to confirm, when you are typing something, you do not get any event coming through from the touchpad (in your case event10)?

VTimofeenko commented 2 months ago

Correct, here is my typing and the mouse cursor disappears roughly around third "a":

log ``` -event0 DEVICE_ADDED Video Bus seat0 default group1 cap:k -event2 DEVICE_ADDED Lid Switch seat0 default group2 cap:S -event3 DEVICE_ADDED Power Button seat0 default group3 cap:k -event4 DEVICE_ADDED FRMW0004:00 32AC:0006 Wireless Radio Control seat0 default group4 cap:k -event5 DEVICE_ADDED FRMW0004:00 32AC:0006 Consumer Control seat0 default group4 cap:kp scroll-nat -event9 DEVICE_ADDED PIXA3854:00 093A:0274 Mouse seat0 default group5 cap:p left scroll-nat scroll-button -event10 DEVICE_ADDED PIXA3854:00 093A:0274 Touchpad seat0 default group5 cap:pg size 111x73mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on -event1 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group6 cap:k -event12 DEVICE_ADDED xremap seat0 default group7 cap:kp left scroll-nat scroll-button event12 KEYBOARD_KEY +0.000s *** (-1) pressed a event12 KEYBOARD_KEY +0.089s *** (-1) released event12 KEYBOARD_KEY +0.286s *** (-1) pressed a event12 KEYBOARD_KEY +0.339s *** (-1) released event12 KEYBOARD_KEY +0.667s *** (-1) pressed a event12 KEYBOARD_KEY +0.754s *** (-1) released event12 KEYBOARD_KEY +3.760s *** (-1) pressed event12 KEYBOARD_KEY +3.946s *** (-1) pressed ```
rytswd commented 2 months ago

Thank you for the help -- could I bother you once more for another input from your setup?

I noticed I'm seeing the dwt enabled for the main keyboard, not to xremap, when running libinput debug-events --verbose:

$ libinput debug-events --verbose
libinput version: 1.26.1
(...snip...)
event16 - Asus Keyboard: is tagged by udev as: Keyboard Mouse
event16 - Asus Keyboard: device is a pointer
event16 - Asus Keyboard: device is a keyboard
  ... event2  - lid: keyboard paired with Lid Switch<->Asus Keyboard
event12 - HD-Audio Generic Mic: is tagged by udev as: Switch
event12 - not using input device '/dev/input/event12'
event14 - HD-Audio Generic Mic: is tagged by udev as: Switch
event14 - not using input device '/dev/input/event14'
event15 - HD-Audio Generic Headphone: is tagged by udev as: Switch
event15 - not using input device '/dev/input/event15'
event11 - ASUF1208:00 2808:0218 Mouse: is tagged by udev as: Mouse Pointingstick
event11 - ASUF1208:00 2808:0218 Mouse: device is a pointer
event13 - ASUF1208:00 2808:0218 Touchpad: is tagged by udev as: Touchpad
event13 - ASUF1208:00 2808:0218 Touchpad: kernel bug: missing right button, assuming it is a clickpad.
  ... event13 - thumb: enabled thumb detection (area)
event13 - ASUF1208:00 2808:0218 Touchpad: device is a touchpad
  ... event13 - lid: activated for ASUF1208:00 2808:0218 Touchpad<->Lid Switch
  ... event13 - palm: dwt activated with ASUF1208:00 2808:0218 Touchpad<->Asus Keyboard
event17 - xremap: is tagged by udev as: Keyboard Mouse
event17 - xremap: device is a pointer
event17 - xremap: device is a keyboard

This may be because of the timing xremap is loaded?

VTimofeenko commented 2 months ago

Sure. In both cases I pressed "a" and then ctrl-c to break event monitoring.

In my case the sequence does not matter of starting xremap does not matter. One interesting thing is that when xremap is started, I get dwt activated twice -- one for physical touchpad, another for xremap.

Log with xremap enabled ``` ❯ libinput version: 1.25.0 event0 - Video Bus: is tagged by udev as: Keyboard event0 - Video Bus: device is a keyboard event2 - Lid Switch: is tagged by udev as: Switch event2 - Lid Switch: device is a switch device event3 - Power Button: is tagged by udev as: Keyboard event3 - Power Button: device is a keyboard event8 - HD-Audio Generic HDMI/DP,pcm=3: is tagged by udev as: Switch event8 - not using input device '/dev/input/event8' event9 - HD-Audio Generic HDMI/DP,pcm=7: is tagged by udev as: Switch event9 - not using input device '/dev/input/event9' event10 - HD-Audio Generic HDMI/DP,pcm=8: is tagged by udev as: Switch event10 - not using input device '/dev/input/event10' event11 - HD-Audio Generic Headphone: is tagged by udev as: Switch event11 - not using input device '/dev/input/event11' event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: is tagged by udev as: Keyboard event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: device is a keyboard event5 - FRMW0004:00 32AC:0006 Consumer Control: is tagged by udev as: Keyboard event5 - FRMW0004:00 32AC:0006 Consumer Control: device is a keyboard event6 - PIXA3854:00 093A:0274 Mouse: is tagged by udev as: Mouse Pointingstick event6 - PIXA3854:00 093A:0274 Mouse: device is a pointer ... event7 - quirks: disabling EV_KEY BTN_RIGHT (0x1 0x111) event7 - PIXA3854:00 093A:0274 Touchpad: is tagged by udev as: Touchpad ... event7 - thumb: enabled thumb detection (area) event7 - PIXA3854:00 093A:0274 Touchpad: device is a touchpad ... event7 - lid: activated for PIXA3854:00 093A:0274 Touchpad<->Lid Switch event1 - AT Translated Set 2 keyboard: is tagged by udev as: Keyboard event1 - AT Translated Set 2 keyboard: device is a keyboard ... event2 - lid: keyboard paired with Lid Switch<->AT Translated Set 2 keyboard ... event7 - palm: dwt activated with PIXA3854:00 093A:0274 Touchpad<->AT Translated Set 2 keyboard event12 - xremap: is tagged by udev as: Keyboard Mouse event12 - xremap: device is a pointer event12 - xremap: device is a keyboard ... event2 - lid: keyboard paired with Lid Switch<->xremap ... event7 - palm: dwt activated with PIXA3854:00 093A:0274 Touchpad<->xremap -event0 DEVICE_ADDED Video Bus seat0 default group1 cap:k -event2 DEVICE_ADDED Lid Switch seat0 default group2 cap:S -event3 DEVICE_ADDED Power Button seat0 default group3 cap:k -event4 DEVICE_ADDED FRMW0004:00 32AC:0006 Wireless Radio Control seat0 default group4 cap:k -event5 DEVICE_ADDED FRMW0004:00 32AC:0006 Consumer Control seat0 default group4 cap:kp scroll-nat -event6 DEVICE_ADDED PIXA3854:00 093A:0274 Mouse seat0 default group5 cap:p left scroll-nat scroll-but ton -event7 DEVICE_ADDED PIXA3854:00 093A:0274 Touchpad seat0 default group5 cap:pg size 111x73mm tap(dl off ) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on -event1 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group6 cap:k -event12 DEVICE_ADDED xremap seat0 default group7 cap:kp left scroll-nat scroll-bu tton event12 KEYBOARD_KEY +0.000s *** (-1) pressed a event12 KEYBOARD_KEY +0.062s *** (-1) released 4: event7 - palm: keyboard timeout event12 KEYBOARD_KEY +2.977s *** (-1) pressed event12 KEYBOARD_KEY +3.051s *** (-1) pressed ^C event0 - Video Bus: device removed event2 - Lid Switch: device removed event3 - Power Button: device removed event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: device removed event5 - FRMW0004:00 32AC:0006 Consumer Control: device removed event6 - PIXA3854:00 093A:0274 Mouse: device removed event7 - PIXA3854:00 093A:0274 Touchpad: device removed event1 - AT Translated Set 2 keyboard: device removed event12 - xremap: device removed ```
Log with xremap stopped ``` ❯ libinput debug-events --verbose libinput version: 1.25.0 event0 - Video Bus: is tagged by udev as: Keyboard event0 - Video Bus: device is a keyboard event2 - Lid Switch: is tagged by udev as: Switch event2 - Lid Switch: device is a switch device event3 - Power Button: is tagged by udev as: Keyboard event3 - Power Button: device is a keyboard event8 - HD-Audio Generic HDMI/DP,pcm=8: is tagged by udev as: Switch event8 - not using input device '/dev/input/event8' event6 - HD-Audio Generic HDMI/DP,pcm=3: is tagged by udev as: Switch event6 - not using input device '/dev/input/event6' event7 - HD-Audio Generic HDMI/DP,pcm=7: is tagged by udev as: Switch event7 - not using input device '/dev/input/event7' event11 - HD-Audio Generic Headphone: is tagged by udev as: Switch event11 - not using input device '/dev/input/event11' event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: is tagged by udev as: Keyboard event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: device is a keyboard event5 - FRMW0004:00 32AC:0006 Consumer Control: is tagged by udev as: Keyboard event5 - FRMW0004:00 32AC:0006 Consumer Control: device is a keyboard event9 - PIXA3854:00 093A:0274 Mouse: is tagged by udev as: Mouse Pointingstick event9 - PIXA3854:00 093A:0274 Mouse: device is a pointer ... event10 - quirks: disabling EV_KEY BTN_RIGHT (0x1 0x111) event10 - PIXA3854:00 093A:0274 Touchpad: is tagged by udev as: Touchpad ... event10 - thumb: enabled thumb detection (area) event10 - PIXA3854:00 093A:0274 Touchpad: device is a touchpad ... event10 - lid: activated for PIXA3854:00 093A:0274 Touchpad<->Lid Switch event1 - AT Translated Set 2 keyboard: is tagged by udev as: Keyboard event1 - AT Translated Set 2 keyboard: device is a keyboard ... event2 - lid: keyboard paired with Lid Switch<->AT Translated Set 2 keyboard ... event10 - palm: dwt activated with PIXA3854:00 093A:0274 Touchpad<->AT Translated Set 2 keyboard -event0 DEVICE_ADDED Video Bus seat0 default group1 cap:k -event2 DEVICE_ADDED Lid Switch seat0 default group2 cap:S -event3 DEVICE_ADDED Power Button seat0 default group3 cap:k -event4 DEVICE_ADDED FRMW0004:00 32AC:0006 Wireless Radio Control seat0 default group4 cap:k -event5 DEVICE_ADDED FRMW0004:00 32AC:0006 Consumer Control seat0 default group4 cap:kp scroll-nat -event9 DEVICE_ADDED PIXA3854:00 093A:0274 Mouse seat0 default group5 cap:p left scroll-nat scroll-but ton -event10 DEVICE_ADDED PIXA3854:00 093A:0274 Touchpad seat0 default group5 cap:pg size 111x73mm tap(dl off ) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on dwtp-on -event1 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group6 cap:k event1 KEYBOARD_KEY +0.000s *** (-1) pressed a event1 KEYBOARD_KEY +0.092s *** (-1) released 4: event10 - palm: keyboard timeout event1 KEYBOARD_KEY +2.162s *** (-1) pressed event1 KEYBOARD_KEY +2.217s *** (-1) pressed ^C event0 - Video Bus: device removed event2 - Lid Switch: device removed event3 - Power Button: device removed event4 - FRMW0004:00 32AC:0006 Wireless Radio Control: device removed event5 - FRMW0004:00 32AC:0006 Consumer Control: device removed event9 - PIXA3854:00 093A:0274 Mouse: device removed event10 - PIXA3854:00 093A:0274 Touchpad: device removed event1 - AT Translated Set 2 keyboard: device removed ```
rytswd commented 2 months ago

Thank you so much, it's certainly acting differently in yours:

  ... event7  - palm: dwt activated with PIXA3854:00 093A:0274 Touchpad<->AT Translated Set 2 keyboard
event12 - xremap: is tagged by udev as: Keyboard Mouse
event12 - xremap: device is a pointer
event12 - xremap: device is a keyboard
  ... event2  - lid: keyboard paired with Lid Switch<->xremap
  ... event7  - palm: dwt activated with PIXA3854:00 093A:0274 Touchpad<->xremap

This is interesting, because it's doing the dwt setup first with the physical keyboard, and then also enabling xremap. It makes sense, but with my setup, I'm not seeing the latter part for xremap. I'm having a further read on libinput -- this doesn't seem to have anything to do with home-manager / NixOS user / system installation, but more to do with how the xremap is registered...

rytswd commented 2 months ago

Thanks for all the help @VTimofeenko, I at least got some solution!

I could make this work with the Device quirks, especially with local-overrides.quirks. I've got the following in my Nix code for now. (This is for NixOS rather than home-manager.)

{ pkgs
, lib
, config
, ...}:

{
  options = {
    devices.keyboard.enable = lib.mkEnableOption "Enable keyboard related adjustment.";
  };

  config = lib.mkIf config.devices.keyboard.enable {
    environment.etc."libinput/local-overrides.quirks".text =
      ''
        [xremap]
        MatchUdevType=keyboard
        AttrKeyboardIntegration=internal
      '';
  };
}

With this in place, the dwt correctly captures the input coming from xremap as well. I am using home-manager version of xremap, and that seems to work fine.

It is rather odd how I have to do this as there was a fix for this introduced from https://github.com/xremap/xremap/pull/196. I may get to digging into the bottom of this at some point, but for now, I'm quite happy at least there is a solution for dwt to work correctly!

VTimofeenko commented 2 months ago

Great! I will add this to the doc.

If you're feeling adventurous, you could try overriding the xremap input of this flake and pin it to the parent of the commit from that PR. The building machinery should work pretty much as is -- except maybe for the wlroots feature.

rytswd commented 2 months ago

I can see the latest version info with my xremap installation, but I can try specifying a commit indeed. There are some nuances with the above quirks addition, how it would affect all keyboards connected, not just xremap, so it would be the best if the upstream code can correctly handle this.

VTimofeenko commented 2 months ago

That's best reported upstream (well, in the xremap/xremap repo). This repo is only about nix packaging and modules.

rytswd commented 2 months ago

Ah yes, sorry I just meant that I should get to the bottom of this anyhow, because what I have got is probably because of some misconfiguration somewhere 😅 I'll report with my findings when I have more!