Skip to content

Commit

Permalink
v2.0.0-beta
Browse files Browse the repository at this point in the history
keyd redux take 1.

A rewrite which simplifies the config format and provides a
solid foundation for incrementally introducing experimental
features.

Internally:

 - Modularized and rewrote most of the code
 - Added a mini testing framework (t/)

Externally:

 - Eliminated layer inheritance in favour of simple types.
 (layouts are now defined with `:layout` instead of `:main`)
 - Macros are now repeatable.
 - Overload now accepts a hold threshold timeout.
 - Config files are now vendor/product id oriented.
 - SIGUSR1 now triggers a config reload.
 - Modifiers are layers by default and can be extended directly.
 - Config files now end in `.conf`.
 - `layert()` is now `toggle()`.
 - All layers are 'modifier layers' (terminological change)
 - Eliminated the dedicated modifer layout.
 - Modifiers no longer apply to key sequences defined within a layer.
   (Layer sequences are now always executed verbatim.)

   The old behaviour was unintuitive and can be emulated using nested
   layers if necessary.
  • Loading branch information
rvaiya committed Dec 27, 2021
1 parent 9a424b4 commit 5feea0c
Show file tree
Hide file tree
Showing 68 changed files with 3,607 additions and 1,461 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
tags
bin/
*.gch
__pycache__
52 changes: 41 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
# v1.3.1
# v2.0-beta

- Fixed overload behaviour (see #34)
Major version update.

# v1.3.0
This breaks 1.x configs. The format may change slightly before leaving beta,
but once it does should remain backwards compatible for the foreseeable future.

- Adds the ability to swap layers mid-key (#48).
- Adds a panic key sequence (backspace + backslash + enter).
- Clears oneshot layers when undefined keys are pressed.
- Removes duplicate keycode names in `keyd -l`.
- Fixes accidental layer toggle bug (#44).
- Improves logging.
- Fixes support for keyboards with built in mice.
- Misc bugfixes.
A non exhaustive list of changes can be found below. It is best to forget
everything you know and read man page anew.

- Eliminated layer inheritance in favour of simple types.
(layouts are now defined with `:layout` instead of `:main`)
- Macros are now repeatable.
- Overload now accepts a hold threshold timeout.
- Config files are now vendor/product id oriented.
- SIGUSR1 now triggers a config reload.
- Modifiers are layers by default and can be extended directly.
- Config files now end in `.conf`.
- `layert()` is now `toggle()`.
- All layers are 'modifier layers' (terminological change)
- Eliminated the dedicated modifer layout.
- Modifiers no longer apply to key sequences defined within a layer.
(Layer entries are now always executed verbatim.)

The old behaviour was unintuitive and can be emulated using nested
layers if necessary.

For most old configs transitioning should be a simple matter of changing
the file extension from `.cfg` to `.conf`, replacing `layert` with
`toggle`, changing `:main` to `:layout` and adding

```
[ids]
*
[main]
```

to the top of the file.

More involved configs may need additional changes, but should be possible
to replicate using the new rules. If not, please file an issue on
[github](https://github.com/rvaiya/keyd/issues).

# v1.1.1

Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ LOCK_FILE="/var/lock/keyd.lock"
LOG_FILE="/var/log/keyd.log"
CONFIG_DIR="/etc/keyd"

VERSION=1.3.1
VERSION=2.0.0-beta
GIT_HASH=$(shell git describe --no-match --always --abbrev=40 --dirty)

CFLAGS=-DVERSION=\"$(VERSION)\" \
CFLAGS+=-DVERSION=\"$(VERSION)\" \
-DGIT_COMMIT_HASH=\"$(GIT_HASH)\" \
-DCONFIG_DIR=\"$(CONFIG_DIR)\" \
-DLOG_FILE=\"$(LOG_FILE)\" \
-DLOCK_FILE=\"$(LOCK_FILE)\"\
-I/usr/local/include\
-L/usr/local/lib
-L/usr/local/lib\

all:
mkdir -p bin
$(CC) $(CFLAGS) -O3 src/*.c -o bin/keyd -ludev
debug:
mkdir -p bin
$(CC) $(CFLAGS) -O3 src/*.c -o bin/keyd -ludev -pedantic -Wall -Wextra -g
man:
pandoc -s -t man man.md | gzip > keyd.1.gz
Expand All @@ -40,4 +41,8 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.service\
bin/keyd $(DESTDIR)$(PREFIX)/bin/keyd\
$(DESTDIR)$(PREFIX)/share/man/man1/keyd.1.gz

test: all
@cd t; \
for f in *.sh; do \
./$$f; \
done
73 changes: 48 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Impetus

Linux lacks a good key remapping solution. In order to achieve satisfactory
results a medley of tools need to be employed (e.g. xcape, xmodmap) with the end
results a medley of tools need to be employed (e.g xcape, xmodmap) with the end
result often being tethered to a specified environment (X11). keyd attempts to
solve this problem by providing a flexible system wide daemon which remaps keys
using kernel level input primitives (evdev, uinput).

# UPDATE
# UPDATE (v2.0.0-beta)

*Version 1.0.0 has just been released and includes some breaking changes. Please see the [changelog](CHANGELOG.md) for details.*
master is currently tracking `v2.0.0-beta`. If you are looking for something
a bit more stable you may be interested the [v1](https://github.com/rvaiya/keyd/tree/v1)
branch.

*If you are migrating your config from v1, please see the
[changelog](CHANGELOG.md) for a list of changes.*

# Features

Expand All @@ -32,7 +37,7 @@ Some of the more interesting ones include:
- Want to put the control and escape keys where God intended.
- Would like the ability to easily generate keycodes in other languages.
- Constantly fiddle with their key layout.
- Want an intuitive keyboard config format which is simple to grok.
- Want an inuitive keyboard config format which is simple to grok.
- Wish to be able to switch to a VT to debug something without breaking their keymap.
- Like tiny daemons that adhere to the Unix philosophy.

Expand Down Expand Up @@ -72,9 +77,15 @@ members, no personal responsibility is taken for them.

1. Install keyd

2. Put the following in `/etc/keyd/default.cfg`:
2. Put the following in `/etc/keyd/default.conf`:

```
[ids]
*
[main]
# Turns capslock into an escape key when pressed and a control key when held.
capslock = overload(C, esc)
Expand All @@ -87,37 +98,49 @@ esc = capslock
4. See the [man page](man.md) for a comprehensive list of config options.

*Note*: It is possible to render your machine unusable with a bad config file.
In the event of a rogue configuration the key sequence `backspace+slash+enter`
should terminate keyd. It is recommended that you avoid experimenting in
default.cfg (see the man page for keyboard specific configuration) so you can
plug in another keyboard which is unaffected by the changes.
Before proceeding ensure you have some way of killing keyd if things go wrong
(e.g ssh). It is recommended that you avoid experimenting in default.cfg (see
the man page for keyboard specific configuraiton) so you can plug in another
keyboard which is unaffected by the changes.

# Sample Config

leftshift = oneshot(S)
capslock = overload(symbols, esc)
[ids]

*

[main]

[symbols]
leftshift = oneshot(S)
capslock = overload(symbols, esc)

d = ~
f = /
...
[symbols]

d = ~
f = /
...

# Recommended config

Many users will probably not be interested in taking full advantage of keyd.
For those who seek simple quality of life improvements I can recommend the
following config:

leftshift = oneshot(S)
leftalt = oneshot(A)
rightalt = oneshot(G)
rightshift = oneshot(A)
leftmeta = oneshot(M)
rightmeta = oneshot(M)
[ids]

*

[main]

leftshift = oneshot(S)
leftalt = oneshot(A)
rightalt = oneshot(G)
rightshift = oneshot(A)
leftmeta = oneshot(M)
rightmeta = oneshot(M)

capslock = overload(C, esc)
insert = S-insert
capslock = overload(C, esc)
insert = S-insert

This remaps all modifiers to 'oneshot' keys and overloads the capslock key to
function as both escape (when tapped) and control (when held). Thus to produce
Expand Down Expand Up @@ -145,7 +168,7 @@ way to get comparable features. I became aware of kmonad after having published
keyd. While kmonad is a fine project with similar goals, it takes a different
approach and has a different design philosophy.

Notably keyd was written entirely in C with performance and simplicity in
Notably keyd was written entirely in C with performance and simplicitly in
mind and will likely never be as configurable as kmonad (which is extensible
in Haskell). Having said that, it supplies (in the author's opinion) the
most valuable features in less than 2000 lines of C while providing
Expand All @@ -155,7 +178,7 @@ a simple language agnostic config format.

If you feel something is missing or find a bug you are welcome to file an issue
on github. keyd has a minimalist (but sane) design philosophy which
intentionally omits certain features (e.g. unicode/executing arbitrary executables
intentionally omits certain features (e.g unicode/execing arbitrary executables
as root). Things which already exist in custom keyboard firmware like QMK are
good candidates for inclusion.

Expand Down
5 changes: 5 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Organize tests.
- Improve FAQ.
- Add more examples.
- Multi user support?
- Unicode support?
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: to use this, rename this file to `your keyboard name`.cfg and put in /etc/keyd/
# NOTE: to use this, rename this file to default.conf and put in /etc/keyd/

# Advanced use of capslock as a triple function key:
#
Expand All @@ -10,14 +10,24 @@
# - when 'capslock' is held, and the 'space' key is tapped, we enter a 3rd
# state for "VIM mode" where hjkl keys become arrow keys until capslock
# is released.
#
[ids]
*

[main]

capslock = overload(ctrl_vim, esc)

# ctrl_vim modifier layer; inherits from 'Ctrl' modifier layer

[ctrl_vim:C]

space = swap(vim_mode)

# vim_mode modifier layer; also inherits from 'Ctrl' modifier layer

[vim_mode:C]

h = left
j = down
k = up
Expand Down
7 changes: 6 additions & 1 deletion examples/mac_like.cfg → examples/macos.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: to use this, rename this file to `your keyboard name`.cfg and put in /etc/keyd/
# NOTE: to use this, rename this file to default.conf and put in /etc/keyd/

# Mac-Like Configuration Example
#
Expand All @@ -10,6 +10,11 @@
# in mutter to make it inert:
# - `gsettings set org.gnome.mutter overlay-key ''`

[ids]
*

[main]

# Create a new "Cmd" button, with various Mac OS-like features below
leftalt = layer(meta_mac)

Expand Down
Binary file modified keyd.1.gz
Binary file not shown.
Loading

0 comments on commit 5feea0c

Please sign in to comment.