fix(hotkey): split platform files by platform+cgo build matrix

The `!darwin` guard on the modifier helpers was too broad: golang.design/x/
hotkey only exposes its Mod*/Key* constants from the darwin&&cgo, linux&&cgo
and windows backends, while the `!windows && !cgo` complement (e.g. Linux
cross-builds with CGO_ENABLED=0) falls back to a stub with no constants. That
made hk.ModCtrl/ModShift/KeyA... undefined and produced editor/vet warnings.

Realign the build tags with the upstream matrix and confine every hk.* constant
to a tagged file so the shared hotkey.go compiles everywhere. Also fix the
Linux mapping (option -> hk.Mod1; hk.ModAlt does not exist on X11).
This commit is contained in:
2026-07-04 15:26:07 +08:00
parent 5ce3eba455
commit 7c53c0f184
7 changed files with 69 additions and 13 deletions
@@ -1,10 +1,15 @@
//go:build darwin
//go:build darwin && cgo
package hotkey
import hk "golang.design/x/hotkey"
// macOS uses ⌘ as the primary modifier; Option corresponds to Alt.
//
// This file is gated on cgo because golang.design/x/hotkey only exposes the
// Mod* constants from its cgo-backed darwin implementation; with CGO_ENABLED=0
// the package falls back to a stub that defines no constants.
func modCmd() hk.Modifier { return hk.ModCmd }
func modCtrl() hk.Modifier { return hk.ModCtrl }
func modOption() hk.Modifier { return hk.ModOption }
func modShift() hk.Modifier { return hk.ModShift }