Clavier/doc/design.org

4.6 KiB

Clavier

A kmonad-like tool, written and configured in Common Lisp.

Benefits

  1. Configuration is code, not data or a cut-down DSL - the full power of Common Lisp is at your disposal. A lot of feature requests in kmonad basically stem from the configuration being data, not code.
  2. No need to restart for configuration to take effect - using SLIME or Sly, send Lisp expressions to the running program and make edit-restart-test cycles a thing of the past.

Some other kmonad shortcomings we seek to address -

  1. multiple input devices per configuration
  2. include other configurations (since the configuration format is a programming language, we get this for free)
  3. work with any keys, e.g. you can swap " and '
  4. make program- or window-specific keybindings

Other things we aim to make possible -

  1. assigning keys/chords to other keys/chords
  2. defining modal editing/navigation layers (like Vim) which work in any application
  3. defining your own input methods (e.g. Devanagari iTrans)

Some examples of what's possible -

  • Swapping ' and ", if you use a language like Lisp
  • Swapping Esc and Caps Lock.
  • Binding a key to insert (), "", <> etc as pairs and place the cursor between the inserted pair.
  • Having Left Shift insert () when tapped, and act as Shift when held.
  • Having Space act as Ctrl when held, reducing pinky fatigue and hand movement when pressing Ctrl-based bindings.
  • Fans of modal editing may now have rudimentary support for it in any application
  • Binding C-m or C-j to Enter
  • Terminal fans might like to bind…
    C-h to Backspace
    C-w to C-Backspace (delete previous word), and
    C-u to Shift-Home Backspace (delete to start of line),
    …so you can have these familiar bindings in any applications you use, and reduce hand movement.
  • Emacs users might appreciate binding…
    C-n and C-p to Down and Up,
    C-f and C-b to Right and Left,
    C-a and C-e to Home and End,
    C-/ to C-z (undo),
    C-d to Delete, M-d to C-Delete or C-S-Right C-x (cut next word), etc
    …in all non-Emacs applications.

Design notes

raw input events (key down/key up) -> translator* -> output events

A translator translates input to output. Each translator is associated with one or more predicates; if all the predicates pass, the translator takes effect, and could result in…

  1. a simple translation - e.g. pressing ' sends ", pressing Caps Lock sends Esc, etc
  2. a complex translation - pressing C-h sends Backspace, pressing C-w sends C-Backspace, etc
  3. sending no output, but changing the state of the tool. e.g. change of layers or layout

Layouts are implemented as groups of predicates.

Types of predicates

  1. Input pattern - a predicate matched against the raw input events. Could be a key down, a key up, a key up of a specific key received after some time of a key down of a specific key, etc. This makes it a superset of kmonad's "button definition commands".
  2. Program/window predicates
  3. Device predicates - could be an input device (laptop keyboard, USB keyboard), or a combination of devices (so input from any of those devices will match).
  4. or any other Lisp function

We can have macros which apply one or more predicates to all enclosed translators, so that configuration may be arranged in arbitrary ways, e.g. grouped by devices, or by programs, etc.

GUI for displaying and modifying layouts.

Configuration interface

  1. (make-input-pattern FOO &rest input-pattern-spec) - DSL to concisely define common input patterns; return an input pattern object. Also define a predicate called (input-pattern-FOO-p input), suitable for association with a translator.
  2. (make-translator input &key predicates output) - return a translator object converting INPUT to OUTPUT if PREDICATES are true.
  3. (with-predicates (predicates) &rest translators) - associate PREDICATES to all TRANSLATORS
  4. (make-device FOO ...) - define device. Also defines a (device-FOO-p input) which contains OS-specific code to check if input is from device FOO.

—-

That sounds way better than kmonad already. More flexible, and fewer concepts, meaning easier learning…

Alternative context-oriented programming design using ContextL

The operating system, active input device, application in focus, etc become contexts.

Receiving contexts from other applications over IPC