Files
mesh-catalog/modules/triggerhappy/cmd/triggerhappy-tools/main.go
T
jochen afce6b03f4 triggerhappy: the machine's hotkeys as a module holding node-hotkeys (hq ADR 0212)
The laptop's model module owned triggerhappy's trigger file and service, although the daemon is a
general piece others have keys for. triggerhappy now owns the daemon, reads only the mesh's file,
runs every trigger as the account, and the model module contributes its vendor keys.
2026-10-04 16:50:57 +02:00

60 lines
2.1 KiB
Go

// triggerhappy's Go tools bundle (novox/hq ADR 0212): the holder of node-hotkeys. The daemon sees
// the keys the window manager never does — a laptop's vendor keys — and runs the trigger lines every
// module on the machine contributed. Served by the node's runtime as the operator account.
package main
import (
"fmt"
"os"
stdio "git.novox.be/novox/mesh-sdk/go"
)
func main() {
if err := stdio.Serve("", tools(NewMachine())); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func tools(m *Machine) []stdio.Tool {
return []stdio.Tool{
{
Name: "triggerhappy_keys",
Description: "Every hotkey trigger in force on this machine: the key, when it fires (pressed, held, " +
"released), the command it runs, the file it is in and the module that contributed it. " +
"Warns about a key bound twice for the same state, which fires both commands.",
Run: func(map[string]any) (any, error) { return m.Keys() },
},
{
Name: "triggerhappy_devices",
Description: "The input devices the hotkey daemon reads: each event device's name and what it reports.",
Run: func(map[string]any) (any, error) { return m.Devices() },
},
{
Name: "triggerhappy_dump",
Description: "Listen for key events for a few seconds and say which key names arrive, so a key's name " +
"can be found for a new trigger: press the key while this runs. Needs sudo -n for the devices.",
Input: map[string]any{
"seconds": map[string]any{"type": "integer", "description": "how long to listen (default 5, at most 20)"},
},
Run: func(args map[string]any) (any, error) {
s := 5
if v, ok := args["seconds"].(float64); ok {
s = int(v)
}
if s < 1 || s > 20 {
return nil, fmt.Errorf("seconds is 1 to 20")
}
return m.Dump(s)
},
},
{
Name: "triggerhappy_check",
Description: "Whether the hotkey daemon is as the mesh declares it: running, as the operator's account, " +
"reading only the mesh's trigger file, with no key bound twice.",
Run: func(map[string]any) (any, error) { return m.Check() },
},
}
}