⇠ chan.dev / posts

Hold Space for OmniWM with Kanata

AI-assisted post: written by Pi from the setup we built together in one sitting.

I use OmniWM to tile windows on my Mac.

Its default leader is Option. Option is a terrible leader.

Option+arrow jumps words. Option+Shift+arrow selects words. Option+letter types ¡™£¢∞.

Every window shortcut was squatting on something I use while typing.

So I moved the whole thing under my thumb. Hold space, press a number, switch workspaces.

The plan

Two layers:

  1. OmniWM listens on a combo nobody types. Ctrl+Opt+Cmd+key, with Shift for the “move” variant.
  2. A remapper turns “space held” into that combo. Space+2 sends Ctrl+Opt+Cmd+2. Space+Shift+2 sends Ctrl+Opt+Cmd+Shift+2.

OmniWM never needs to know space is involved. And shift keeps meaning “move,” like it did before.

Why not Karabiner

I already had Karabiner Elements running my Dvorak layout. It can do a space layer. It can’t do it well.

The problem is rolls. Type in 2024 fast and your thumb is still on space when you hit 2. Karabiner sees “space held + 2” and switches workspaces. Or it loses the space.

kanata has primitives built for this:

  • tap-hold-release only commits to “hold” when another key is pressed and released while space is down. A roll releases space first, so it stays a space.
  • require-prior-idle says “if I typed anything in the last N ms, this is a tap. Don’t even think about it.”

That’s the whole reason I switched.

Moving Dvorak too

I forgot Karabiner was running my Dvorak mapping.

That’s fine. kanata does it the same way: the macOS input source stays “U.S.” and the base layer is Dvorak. defsrc is physical (QWERTY) positions. deflayer base is what they type.

The scary part is the handoff. If kanata isn’t running, I’m typing QWERTY. So the switch script checks the config, starts kanata, and rolls back to Karabiner on its own if kanata doesn’t come up.

It needed that rollback on the first run.

The config

(defcfg
process-unmapped-keys yes
)
(defsrc
esc
grv 1 2 3 4 5 6 7 8 9 0 - = bspc
tab q w e r t y u i o p [ ] \
caps a s d f g h j k l ; ' ret
lsft z x c v b n m , . / rsft
lctl lalt lmet spc rmet ralt
left down up rght home end
)
(defalias
;; tap = space, hold = nav. Typed anything in the last 150ms? Always space.
spcth (tap-hold-release 0 300 spc (layer-while-held nav) (require-prior-idle 150))
;; tap space, then press-and-hold it = hold Cmd+Tab
ctab (tap-hold-press 0 150 spc (multi lmet (macro tab)) (require-prior-idle 0))
spc (switch
((and (key-history spc 1) (key-timing 1 lt 250))) @ctab break
() @spcth break)
;; Dvorak "-" key: tap = hyphen, hold = control
quo (tap-hold-release 200 300 - lctl (require-prior-idle 150))
w1 C-A-M-1 w2 C-A-M-2 w3 C-A-M-3 w4 C-A-M-4 w5 C-A-M-5
w6 C-A-M-6 w7 C-A-M-7 w8 C-A-M-8 w9 C-A-M-9
wl C-A-M-left wd C-A-M-down wu C-A-M-up wr C-A-M-rght
wtab C-A-M-tab wret C-A-M-ret wgrv C-A-M-grv
whom C-A-M-home wend C-A-M-end
wt C-A-M-t wdot C-A-M-. wcom C-A-M-, wmin C-A-M-- weq C-A-M-=
wf C-A-M-f wb C-A-M-b wr2 C-A-M-r wl2 C-A-M-l wo C-A-M-o
)
;; Dvorak
(deflayer base
esc
grv 1 2 3 4 5 6 7 8 9 0 [ ] bspc
tab ' , . p y f g c r l / = \
lctl a o e u i d h t n s @quo ret
lsft ; q j k x b m w v z rsft
lctl lalt lmet @spc rmet ralt
left down up rght home end
)
;; Space held. Esc reloads this file.
(deflayer nav
lrld
@wgrv @w1 @w2 @w3 @w4 @w5 @w6 @w7 @w8 @w9 _ _ _ _
@wtab _ @wcom @wdot _ _ @wf _ _ @wr2 @wl2 _ @weq _
_ _ @wo _ _ _ _ _ @wt _ _ @wmin @wret
_ _ _ _ _ _ @wb _ _ _ _ _
_ _ _ _ _ _
@wl @wd @wu @wr @whom @wend
)

Letters in the nav layer are placed by the Dvorak letter they type. OmniWM’s old Option+T is now Space+T, wherever T lives.

Space+Esc is lrld: live reload. kanata runs as root, so restarting it means sudo. Reloading from the keyboard doesn’t.

OmniWM

OmniWM’s settings are TOML. I swapped every plain Option binding in one pass:

sed -i '' -E \
-e 's/^binding = "Option\+Shift\+/binding = "Control+Option+Command+Shift+/' \
-e 's/^binding = "Option\+/binding = "Control+Option+Command+/' \
~/.config/omniwm/settings.toml

OmniWM watches that file. No restart.

What bit me

Homebrew’s kanata didn’t work. Karabiner Elements 16 ships VirtualHIDDevice 8.x. kanata 1.12 (Homebrew) speaks the old protocol. You need 1.13, which was a prerelease. My install script downloads it directly.

Keep Karabiner Elements installed. kanata talks to Karabiner’s virtual keyboard daemon. Karabiner Elements runs that daemon. I just told Karabiner to ignore every device, so it stops grabbing the keyboard.

There are two permissions. Input Monitoring and Accessibility, both for /usr/local/bin/kanata. I granted the first, missed the second, and kanata exited. The auto-rollback put me back on Karabiner.

Tap/hold on Command is slow. I had left Command tap to backspace and right Command tap to enter. With tap-hold-release, Command doesn’t engage until you release the next key. Cmd+C fires on the C release. tap-hold-press fixes that, but brings back accidental Cmd+letter when you roll off backspace.

I deleted them. They weren’t worth it.

What I dropped

  • Command tap-to-backspace/enter. Slow or misfiring. Gone.
  • My Meh key and app launcher on left Control. Back to plain Control.
  • Mouse button 6 → Enter. kanata can’t see that button on macOS.

The keyboard does less now. What’s left I actually use.

Tuning

Two numbers decide how this feels:

  • 300 — how long space must be held alone to become the layer.
  • 150 — the “you were just typing” window.

If space misfires while typing, raise the second. If the layer feels sluggish, lower the first.