Sfoglia il codice sorgente

feat(kanata): add kanata for advanced keymapping

This commit introduces Kanata for advanced keymapping on macOS, replacing the previous `system.keyboard` configuration.

The key changes include:
- Enabling the `kanata` module for the `meili` host.
- A detailed `kanata.kbd` configuration with:
  - Home row modifiers.
  - Layers for symbols, numbers, and mouse control.
  - Specific device targeting for the internal keyboard.
- Updating the README with instructions for `kanata` and adding Brave Browser to the software list.
- Disabling the old `system.keyboard` mapping.
Zander Hawke 10 mesi fa
parent
commit
449e62e22b
5 ha cambiato i file con 59 aggiunte e 39 eliminazioni
  1. 7 0
      README.md
  2. 1 1
      hosts/meili/default.nix
  3. 31 22
      hosts/meili/kanata.kbd
  4. 14 10
      hosts/meili/system.nix
  5. 6 6
      modules/darwin/kanata.nix

+ 7 - 0
README.md

@@ -55,6 +55,12 @@ brew bundle
 #   -> Full Disk Access
 #   -> Add Ghostty
 
+# Add kanata to Input Monitoring
+# System Settings
+#   -> Privacy & Security
+#   -> Input Monitoring
+#   -> + /run/current-system/sw/bin/kanata
+
 # Apply system configuration one more time
 sudo darwin-rebuild switch --flake .#meili
 
@@ -98,6 +104,7 @@ sudo dnf install ghostty
 - **AeroSpace** - i3-style tiling window manager
 - **Ghostty** - Modern terminal emulator
 - **Zen Browser** - Privacy-focused browser
+- **Brave Browser** - Used for YouTube app window
 - **YubiKey** - Hardware security key support
 - **Fonts** - Custom font configuration
 

+ 1 - 1
hosts/meili/default.nix

@@ -3,7 +3,7 @@
   imports =
     [
       outputs.modules.global.nix-config
-      # ./kanata.nix
+      ./kanata.nix
       ./system.nix
       ./software.nix
     ]

+ 31 - 22
hosts/meili/kanata.kbd

@@ -3,13 +3,12 @@
 
 (defcfg
   process-unmapped-keys yes
-  ;; Adjust these paths based on your system
-  ;; macOS typically uses something like this:
-  ;; linux-dev /dev/input/by-path/your-keyboard-path
-  ;; For macOS, you might need to specify the input device differently
-
+  macos-dev-names-include (
+    "Apple Internal Keyboard / Trackpad"
+  )
   macos-dev-names-exclude (
     "Voyager"
+    "YubiKey OTP+FIDO+CCID"
   )
 )
 
@@ -18,7 +17,7 @@
        f1   f2                                      f10  f11  f12
   ;; grv  1    2    3    4    5    6    7    8    9    0    -    =    bspc
   ;; tab  q    w    e    r    t    y    u    i    o    p    [    ]    \
-       q    w    e    r    t    y    u    i    o    p
+  tab  q    w    e    r    t    y    u    i    o    p
   ;; caps a    s    d    f    g    h    j    k    l    ;    '    ret
   caps a    s    d    f    g    h    j    k    l    ;
   ;; lsft z    x    c    v    b    n    m    ,    .    /    rsft
@@ -27,38 +26,47 @@
                  lmet           spc           rmet
 )
 
-;; Base layer with home row modifiers and proper media keys
+;; base layer with home row modifiers and proper media keys
 (deflayer base
        brdn brup                                         mute vold volu
-       q    w    e    r    t    y    u    i    o    p
-  esc  @a   @s   @d   @f   g    h    @j   @k   @l   @;
+  tab  q    w    e    r    t    y    u    i    o    p
+  @esc @a   @s   @d   @f   g    h    @j   @k   @l   @;
        z    x    c    @v   b    n    m    ,    .    /
                  @lmet          spc           ret
 )
 
-;; Symbols layer
+;; symbols layer
 (deflayer symbols
        brdn brup                                         mute vold volu
-       S-1  S-2  S-3  S-4  S-5  S-6  S-7  S-[  S-]  S-8
-       `    S--  -    S-=  =    S-`  S-\  S-9  S-0  '
+  tab  S-1  S-2  S-3  S-4  S-5  S-6  S-7  S-[  S-]  S-8
+  @esc `    S--  -    S-=  =    S-`  S-\  S-9  S-0  '
        z    x    c    tab  b    /    \    [    ]    S-/
                  lmet           spc           ret
 )
 
-;; Numpad layer
+;; numpad layer
 (deflayer numbers
        brdn brup                                         mute vold volu
-       q    w    e    r    t    S-8  7    8    9    -
-       @a   @s   ,    .    g    /    4    5    6    S-=
+  tab  q    w    e    r    t    S-8  7    8    9    -
+  @esc @a   @s   ,    .    g    /    4    5    6    S-=
        z    x    c    v    b    =    1    2    3    ret
                  lmet           spc           0
 )
 
-;; Layer without modifiers - used temporarily when tapping home row keys
+;; layer without modifiers - used temporarily when tapping home row keys
 (deflayer nomods
        brdn brup                                         mute vold volu
-       q    w    e    r    t    y    u    i    o    p
-       a    s    d    f    g    h    j    k    l    ;
+  tab  q    w    e    r    t    y    u    i    o    p
+  esc  a    s    d    f    g    h    j    k    l    ;
+       z    x    c    v    b    n    m    ,    .    /
+                 lmet           spc           ret
+)
+
+;; mouse and arrow key layer
+(deflayer mouse
+       brdn brup                                         mute vold volu
+  tab  q    w    e    r    t    y    u    i    o    p
+  @esc @a   @s   @d   @f   g    left down up   right ;
        z    x    c    v    b    n    m    ,    .    /
                  lmet           spc           ret
 )
@@ -87,17 +95,18 @@
 
   ;; Home row modifiers with bilateral combinations
   ;; Left hand keys with LEFT-side modifiers
-  a (tap-hold-release-keys $tap-time $hold-time (multi a @tap) lctl $right-hand-keys)
+  a (tap-hold-release-keys $tap-time $hold-time (multi a @tap) lmet $right-hand-keys)
   s (tap-hold-release-keys $tap-time $hold-time (multi s @tap) lalt $right-hand-keys) 
-  d (tap-hold-release-keys $tap-time $hold-time (multi d @tap) lmet $right-hand-keys)
+  d (tap-hold-release-keys $tap-time $hold-time (multi d @tap) lctl $right-hand-keys)
   f (tap-hold-release-keys $tap-time $hold-time (multi f @tap) lsft $right-hand-keys)
   
   ;; Right hand keys with RIGHT-side modifiers
   j (tap-hold-release-keys $tap-time $hold-time (multi j @tap) rsft $left-hand-keys)
-  k (tap-hold-release-keys $tap-time $hold-time (multi k @tap) rmet $left-hand-keys)
+  k (tap-hold-release-keys $tap-time $hold-time (multi k @tap) rctl $left-hand-keys)
   l (tap-hold-release-keys $tap-time $hold-time (multi l @tap) ralt $left-hand-keys)
-  ; (tap-hold-release-keys $tap-time $hold-time (multi ; @tap) rctl $left-hand-keys)
+  ; (tap-hold-release-keys $tap-time $hold-time (multi ; @tap) rmet $left-hand-keys)
 
   v (tap-hold $tap-time $hold-time (multi v @tap) (layer-toggle numbers))
+  esc (tap-hold $tap-time $hold-time (multi esc @tap) (layer-toggle mouse))
   lmet (layer-toggle symbols)
 )

+ 14 - 10
hosts/meili/system.nix

@@ -4,16 +4,20 @@
   system = {
     primaryUser = "thomas";
 
-    keyboard = {
-      enableKeyMapping = true;
-      userKeyMapping = [
-        {
-          # map caps lock to skhd leader
-          HIDKeyboardModifierMappingSrc = 30064771129;
-          HIDKeyboardModifierMappingDst = 30064771298;
-        }
-      ];
-    };
+    # INFO: Using Kanata for this now.
+    # keyboard = {
+    #   enableKeyMapping = true;
+    #   userKeyMapping = [
+    #     # remap caps lock to escape
+    #     { HIDKeyboardModifierMappingSrc = 30064771129; HIDKeyboardModifierMappingDst = 30064771113; }
+    #     # remap left control to left command
+    #     { HIDKeyboardModifierMappingSrc = 30064771296; HIDKeyboardModifierMappingDst = 30064771296; }
+    #     # remap left command to left control
+    #     { HIDKeyboardModifierMappingSrc = 30064771299; HIDKeyboardModifierMappingDst = 30064771296; }
+    #     # remap right command to right control
+    #     { HIDKeyboardModifierMappingSrc = 30064771303; HIDKeyboardModifierMappingDst = 30064771300; }
+    #   ];
+    # };
 
     defaults = {
       # TODO: to make <C-Space> work, we need to disable these

+ 6 - 6
modules/darwin/kanata.nix

@@ -54,15 +54,15 @@ in
     # Install the driver during activation
     system.activationScripts.preActivation.text = ''
       echo "Installing Karabiner DriverKit VirtualHIDDevice..." >&2
-      
+
       # Check if already installed by looking for the system extension
       if ! systemextensionsctl list 2>/dev/null | grep -q "org.pqrs.Karabiner-DriverKit-VirtualHIDDevice"; then
         echo "Installing driver package..." >&2
         installer -pkg ${driverPkg} -target /
-        
+
         # Give it a moment to install
         sleep 2
-        
+
         # Try to activate the system extension
         if [ -f "/Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager" ]; then
           echo "Activating system extension..." >&2
@@ -78,16 +78,16 @@ in
     # Cleanup when disabled
     system.activationScripts.postActivation.text = lib.mkIf (!cfg.enable) ''
       echo "Cleaning up Karabiner DriverKit..." >&2
-      
+
       # Stop and remove launchd services
       for service in org.nixos.karabiner-vhiddaemon org.nixos.karabiner-vhidmanager; do
         launchctl unload "/Library/LaunchDaemons/$service.plist" 2>/dev/null || true
         rm -f "/Library/LaunchDaemons/$service.plist" 2>/dev/null || true
       done
-      
+
       # Remove the manager app copy
       rm -rf /Applications/.Nix-Karabiner-DriverKit/ 2>/dev/null || true
-      
+
       # Note: We don't uninstall the system extension as that requires manual user action
       # and the extension can be shared with other apps
       echo "Note: Karabiner system extension remains installed (can be removed manually in System Settings)" >&2