rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.72k stars 157 forks source link

keyd on NixOS using ratpoison or awesome-wm #723

Open fvkd opened 4 months ago

fvkd commented 4 months ago

hi! thank you for the amazing app. I have a lenovo thinkpad t14s gen1 that I use as my daily machine. these are some powerful machines, but lenono borked the cooling on them pretty good and it has caused a majority of this model and gen to fry the keyboard circuits. unfortunately my machine is one in the bunch that has 'enter', 'backslash', 'backspace', 'f5' 'f9' and 'f10' dead in the water, right out the box or not too long after. the 3 years that I've had this laptop, I've either had to carry around my Keychron external QMK board with me or utilize 'input-remapper' or keyd. keyd is great, the best imo, as all of the rebinded keys work in x11 as intended when rebinded as well as in wayland, without any workarounds. I don't have to manually load keyd as with input-remapper, even though input-remapper has an 'auto-load' switch in it's gui (doesn't work anymore for me). I'm not shitting on input-remapper, it just has some downfalls and isn't really maintained frequently.

anyways, keyd has worked exactly as needed for me over the last couple of years. until a couple of months ago.

my solution to my useless 'enter', 'backslash' and 'backspace' buttons was to remap my trackpad's buttons to be 'thumb-cluster' buttons, like the ones on a Moonlander keyboard or any of the really nice happyhacking split ergo boards. keyd worked flawlessly for this without issue up until a couple of months ago. after using this setup (left trackpad button = shift, middle button = enter, right button = backspace) as thumb clusters, I am spoiled and can't even type at all on a fully working normal keyboard. I also loathe reverting back to lugging around an external keyboard.

the issue that I've been having the last 2 months is plugging my track/touchpad device id into the id's section produces the problem with touchpad movements being equivalent to:

  sudo keyd monitor device added: 0001:0001 AT Translated Set 2 keyboard (/dev/input/event0) device added: 04f3:0080 Elan Touchpad (/dev/input/event6) device added: 04f3:0080 Elan TrackPoint (/dev/input/event7) device added: 0fac:0ade keyd virtual keyboard (/dev/input/event9) device added: 0fac:1ade keyd virtual pointer (/dev/input/event10) device added: 05ac:024f Keychron Keychron K2 (/dev/input/event17) device added: 05ac:024f Keychron Keychron K2 (/dev/input/event18) device added: 047d:1020 Kensington Kensington Expert Mouse (/dev/input/event16) keyd virtual keyboard 0fac:0ade enter up Elan TrackPoint 04f3:0080 leftmouse down Elan TrackPoint 04f3:0080 leftmouse up Elan TrackPoint 04f3:0080 middlemouse down Elan TrackPoint 04f3:0080 middlemouse up Elan TrackPoint 04f3:0080 rightmouse down Elan TrackPoint 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 rightmouse up Elan Touchpad 04f3:0080 kpminus down Elan Touchpad 04f3:0080 numlock down Elan Touchpad 04f3:0080 kpminus up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 kpminus down Elan Touchpad 04f3:0080 numlock down Elan Touchpad 04f3:0080 kpminus up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 kpminus down Elan Touchpad 04f3:0080 numlock down Elan Touchpad 04f3:0080 kpminus up Elan Touchpad 04f3:0080 numlock up Elan Touchpad 04f3:0080 numlock up keyd virtual keyboard 0fac:0ade leftcontrol down keyd virtual keyboard 0fac:0ade c down

I've seen similar issues that people are having with keyd in other 'issues' threads. I had to reformat my system a few months ago, maybe something got jarred, but I'm using a NixOS, and my system setup is declarative. after reformatting I was simply back up and running with my system set up EXACTLY the same as it is now, but I'm getting this touchpad error. one thing that I've recently made note of, is that the device ID for the touchpad and trackpoint and their buttons, is that they both have the same device ID. I had to think back, but I rememebered that the device ID's were the same when keyd was working to remap my trackpad/touchpad buttons to be thumbclusters.

so I dug into my NixOS system config. here's my x11.nix:

`{ config, pkgs, ... }: {

Enable the X11 windowing system

services.xserver.enable = true;

config at '~/.xinitrc'

services.xserver.displayManager.startx.enable = true;

window manager

services.xserver.windowManager.ratpoison.enable = true;

Configure keymap in X11

services.xserver.xkb = { layout = "us"; variant = ""; }; } ` and here is my services.nix:

`{ config, pkgs, ... }: {

Printing configuration

services.printing.enable = false;

Touchpad configuration

services.xserver.libinput = { touchpad = { accelSpeed = "1.0"; tappingDragLock = false; naturalScrolling = false; clickMethod = "none"; tapping = false; disableWhileTyping = false; scrollMethod = "none"; horizontalScrolling = false; }; enable = true; };

ACPID

services.acpid.enable = true;

Enable input-remapper

services.input-remapper.enable = false;

Sound configuration

sound.enable = true; hardware = { pulseaudio.enable = false; ckb-next.enable = true; }; security.rtkit.enable = true; security.sudo.wheelNeedsPassword = false;

Pipewire configuration

services.pipewire = { enable = true; alsa = { enable = true; support32Bit = true; }; pulse.enable = true;

If you want to use JACK applications, uncomment this:

#jack.enable = true;

};

Enable Blueman Bluetooth service

services.blueman.enable = true; environment.systemPackages = with pkgs; [bluez bluez-tools]; hardware.bluetooth = { enable = true; powerOnBoot = true;

package = pkgs.bluez5-experimental;

package = pkgs.bluez;
settings.Policy.AutoEnable = "true";
settings.General = {
  Enable = "Source,Sink,Media,Socket";
  Name = "Hello";
  ControllerMode = "dual";
  FastConnectable = "true";
  Experimental = "true";
  KernelExperimental = "true";
};

};

Atuin configuration

services.atuin = { maxHistoryLength = 200000; host = "127.0.0.1"; enable = true; openFirewall = true; };

Emacs configuration

TODO: Edit to configure for Doom Emacs

services.emacs = { package = pkgs.emacs-gtk; enable = true; startWithGraphical = true; install = true; };

Enable non-root access to the firmware of QMK keyboards

hardware.keyboard.qmk.enable = true;

} `

noting that I have also rebuilt and rebooted with the # Touchpad configuration services.xserver.libinput = { touchpad = { accelSpeed = "1.0"; tappingDragLock = false; naturalScrolling = false; clickMethod = "none"; tapping = false; disableWhileTyping = false; scrollMethod = "none"; horizontalScrolling = false; }; enable = false; }; with the same touchpad touches problem.

I don't use gnome, I don't have it installed and never have on this setup, and there are no/haven't ever been any settings for gnome or it's services hand-rolled into my setup.

the keyd version that I had installed months ago when things worked as desired was 2.4.3, as is the version I'm using now.

the one thing I can think of that I haven't tried yet is moving the keyd install and config to my home-manager setup instead of my nixos system. when things worked as desired, keyd and it's config were installed and config'd from my nixos system setup/module as they are now.

also just realising that I haven't posted my NixOS keyd.nix config module in this yet, so for posterity:

`{pkgs, ...}: {

Install keyd package

environment.systemPackages = [pkgs.keyd];

Create keyd group

users.groups.keyd.name = "keyd";

Create systemd service

systemd.services.keyd = { description = "key remapping daemon"; requires = ["local-fs.target"]; after = ["local-fs.target"]; wantedBy = ["sysinit.target"]; serviceConfig = { Type = "simple"; ExecStart = "${pkgs.keyd}/bin/keyd";

Restart = "on-failure";

};

};

Add quirks to make touchpad's "disable-while-typing" work properly

environment.etc."libinput/local-overrides.quirks".text = '' [keyd] MatchUdevType=keyboard

MatchVendor=0xFAC

AttrKeyboardIntegration=internal

'';

Configuration for keyd

environment.etc."keyd/default.conf".text = '' [ids]

*

#05ac:024f

#04f3:0080

[main]

#leftshift = overload(shift, backspace)
rightshift = overload(shift, enter)
#meta = oneshot(meta)
meta = macro(C-y)
control = oneshot(control)

leftalt = oneshot(alt)
rightalt = oneshot(altgr)

capslock = overload(control, esc)

sysrq = backslash

wakeup = !

escape = `

` = backspace

#rightmouse = backspace

#middlemouse = enter

''; } `

I'd like to take this time to thank the chap that posted their keyd.nix in another issue thread here, I can't rememebe your name right off hand.

any help with this would be highly appreciated. thanks to all for taking your time to read this mess for any effort in helping resolve.

wmertens commented 4 months ago

@fvkd your formatting in the question is broken. I can't help, it seems to be a hotplug id issue, but I can offer you my keyd config:

# TODO add keyd group + palm rejection in nixpkgs; add support in stage1
{
  # make palm rejection work with keyd
  environment.etc."libinput/local-overrides.quirks".text = ''
    [Serial Keyboards]
    MatchUdevType=keyboard
    MatchName=keyd virtual keyboard
    AttrKeyboardIntegration=internal
  '';

  services.keyd = {
    enable = true;
    keyboards = {
      default = {
        ids = [ "*" ];
        # https://github.com/rvaiya/keyd/blob/master/docs/keyd.scdoc
        # play with it by
        # sudo bash -c 'cd /etc/keyd; cp -H default.conf t;mv -f t default.conf; chown wmertens default.conf'
        # and then edit /etc/keyd/default.conf + restart keyd
        # (be sure to retain the ids section at the top!)
        extraConfig = builtins.readFile ./keyd.conf;
      };
    };
  };
}

and then keyd.conf is the config without [id]. Writing it this way you'll get any fixes to the nixos keyd configuration.