# baskerville/sxhkd architecture

> Architecture diagram of the GitHub repository baskerville/sxhkd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baskerville/sxhkd
- Repository: https://github.com/baskerville/sxhkd

## Overview

sxhkd is an X daemon that reads shortcut bindings, grabs the corresponding keys or buttons, and runs configured commands when input matches. The documented configuration supports expanded shortcut/command sets and chained shortcuts; sampled code also shows matching state, lock handling, and optional status-FIFO output. The excerpts establish startup, configuration loading, and grabbing, but omit parts of event dispatch, so those runtime links are marked unverified rather than asserted as source-verified calls.

Main entry points: [`src/sxhkd.c`](https://github.com/baskerville/sxhkd/blob/master/src/sxhkd.c) (sxhkd daemon), [`src/types.c`](https://github.com/baskerville/sxhkd/blob/master/src/types.c) (Chord and chain matching), [`src/grab.c`](https://github.com/baskerville/sxhkd/blob/master/src/grab.c) (Input grabber), [`src/parse.c`](https://github.com/baskerville/sxhkd/blob/master/src/parse.c) (Config and key parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Daemon Runtime"]
  node_daemon["sxhkd daemon<br/>[sxhkd.c]"]
  node_xserver["X server"]
  node_grabber["Input grabber<br/>[grab.c]"]
  node_status["Status FIFO<br/>[sxhkd.c]"]
end

subgraph group_bindings["Bindings and Matching"]
  node_config["Binding configuration"]
  node_parser["Config and key parser<br/>[parse.c]"]
  node_keymap["Key symbol mapping<br/>[parse.c]"]
  node_hotkeys["Hotkey registry<br/>[types.c]"]
  node_matcher["Chord and chain matching<br/>[types.c]"]
end

subgraph group_execution["Command Execution"]
  node_runner["Shell command runner<br/>[helpers.c]"]
  node_shell["User shell"]
  node_commands["Configured commands"]
end

node_user(("Desktop user"))

node_user -->|"presses keys"| node_xserver
node_xserver -.->|"delivers events"| node_daemon
node_config -->|"provides bindings"| node_daemon
node_daemon -->|"loads config"| node_parser
node_parser -.->|"builds bindings"| node_hotkeys
node_daemon -->|"grabs bindings"| node_grabber
node_grabber -->|"requests grabs"| node_xserver
node_daemon -.->|"matches events"| node_matcher
node_matcher -->|"selects binding"| node_hotkeys
node_matcher -->|"writes progress"| node_status
node_daemon -->|"opens FIFO"| node_status
node_daemon -.->|"runs command"| node_runner
node_runner -->|"invokes shell"| node_shell
node_shell -->|"executes"| node_commands

click node_daemon "https://github.com/baskerville/sxhkd/blob/master/src/sxhkd.c"
click node_parser "https://github.com/baskerville/sxhkd/blob/master/src/parse.c"
click node_keymap "https://github.com/baskerville/sxhkd/blob/master/src/parse.c"
click node_hotkeys "https://github.com/baskerville/sxhkd/blob/master/src/types.c"
click node_matcher "https://github.com/baskerville/sxhkd/blob/master/src/types.c"
click node_grabber "https://github.com/baskerville/sxhkd/blob/master/src/grab.c"
click node_status "https://github.com/baskerville/sxhkd/blob/master/src/sxhkd.c"
click node_runner "https://github.com/baskerville/sxhkd/blob/master/src/helpers.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_daemon,node_xserver,node_grabber,node_status,node_user toneBlue
class node_config,node_parser,node_keymap,node_hotkeys,node_matcher toneAmber
class node_runner,node_shell,node_commands toneMint
```

## Components

### Daemon Runtime

- [sxhkd daemon](https://github.com/baskerville/sxhkd/blob/master/src/sxhkd.c): `src/sxhkd.c`
- **X server**
- [Input grabber](https://github.com/baskerville/sxhkd/blob/master/src/grab.c): `src/grab.c`
- [Status FIFO](https://github.com/baskerville/sxhkd/blob/master/src/sxhkd.c): `src/sxhkd.c`

### Bindings and Matching

- **Binding configuration**
- [Config and key parser](https://github.com/baskerville/sxhkd/blob/master/src/parse.c): `src/parse.c`
- [Key symbol mapping](https://github.com/baskerville/sxhkd/blob/master/src/parse.c): `src/parse.c`
- [Hotkey registry](https://github.com/baskerville/sxhkd/blob/master/src/types.c): `src/types.c`
- [Chord and chain matching](https://github.com/baskerville/sxhkd/blob/master/src/types.c): `src/types.c`

### Command Execution

- [Shell command runner](https://github.com/baskerville/sxhkd/blob/master/src/helpers.c): `src/helpers.c`
- **User shell**
- **Configured commands**

### Other components

- **Desktop user**

## Connections

- Desktop user → X server: presses keys (evidence: `README.md`)
- X server → sxhkd daemon: delivers events
- Binding configuration → sxhkd daemon: provides bindings (evidence: `README.md`)
- sxhkd daemon → Config and key parser: loads config (evidence: `src/sxhkd.c`)
- Config and key parser → Hotkey registry: builds bindings
- sxhkd daemon → Input grabber: grabs bindings (evidence: `src/sxhkd.c`)
- Input grabber → X server: requests grabs (evidence: `src/grab.c`)
- sxhkd daemon → Chord and chain matching: matches events
- Chord and chain matching → Hotkey registry: selects binding (evidence: `src/types.c`)
- Chord and chain matching → Status FIFO: writes progress (evidence: `src/types.c`)
- sxhkd daemon → Status FIFO: opens FIFO (evidence: `src/sxhkd.c`)
- sxhkd daemon → Shell command runner: runs command
- Shell command runner → User shell: invokes shell (evidence: `src/helpers.c`)
- User shell → Configured commands: executes
