From 842f37310165203f4eb39e1b9b76e4829a43a4de Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:24:26 -0400 Subject: [PATCH] switch from keyd to kanata more reliable, doesn't break on update. also allows the escape key to timeout and turn into lctrl after 1 second, which might be nicer behavior --- modules/nixos/graphical/polybar.nix | 6 ----- modules/nixos/hardware/keyboard.nix | 41 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/modules/nixos/graphical/polybar.nix b/modules/nixos/graphical/polybar.nix index 0f4f9e1..239d89d 100644 --- a/modules/nixos/graphical/polybar.nix +++ b/modules/nixos/graphical/polybar.nix @@ -209,12 +209,6 @@ label-foreground = config.theme.colors.base06; # format-background = colors.background; }; - "module/keyboard" = { - type = "custom/text"; - content = "󰌌"; - click-left = "doas systemctl restart keyd"; - content-foreground = config.theme.colors.base04; - }; "module/power" = { type = "custom/text"; content = "  "; diff --git a/modules/nixos/hardware/keyboard.nix b/modules/nixos/hardware/keyboard.nix index a818660..9e51fbb 100644 --- a/modules/nixos/hardware/keyboard.nix +++ b/modules/nixos/hardware/keyboard.nix @@ -1,9 +1,4 @@ -{ - config, - pkgs, - lib, - ... -}: +{ config, lib, ... }: { config = lib.mkIf config.physical { @@ -17,24 +12,30 @@ autoRepeatInterval = 40; }; - # Use capslock as escape and/or control - services.keyd = { + # Swap Caps-Lock with Escape when pressed or LCtrl when held/combined with others + # Inspired by: https://www.youtube.com/watch?v=XuQVbZ0wENE + services.kanata = { enable = true; - keyboards = { - default = { - ids = [ "*" ]; - settings = { - main = { - capslock = "overload(control, esc)"; - }; - }; - }; + keyboards.default = { + devices = [ + "/dev/input/by-id/usb-Logitech_Logitech_G710_Keyboard-event-kbd" + "/dev/input/by-id/usb-Logitech_Logitech_G710_Keyboard-if01-event-kbd" + ]; + extraDefCfg = "process-unmapped-keys yes"; + config = '' + (defsrc + caps + ) + (defalias + escctrl (tap-hold-press 1000 1000 esc lctrl) + ) + (deflayer base + @escctrl + ) + ''; }; }; - # For some reason, keyd doesn't restart properly when updating - system.activationScripts.keyd.text = "${pkgs.systemd}/bin/systemctl restart keyd.service"; - # Enable num lock on login home-manager.users.${config.user}.xsession.numlock.enable = true; };