aboutsummaryrefslogtreecommitdiffstats
path: root/users
diff options
context:
space:
mode:
authorCallum Oakley <hello@callumoakley.net>2020-09-09 23:37:34 +0100
committerGitHub <noreply@github.com>2020-09-09 15:37:34 -0700
commit3d4f0028d60cebc829ac9c947d1a61cc840d05c0 (patch)
treecc54048f38bd75f62de4d2f396359b4fa31b2711 /users
parent6e948feb6a33bcd1da45c5a590d0e6c241e1d879 (diff)
downloadfirmware-3d4f0028d60cebc829ac9c947d1a61cc840d05c0.tar.gz
firmware-3d4f0028d60cebc829ac9c947d1a61cc840d05c0.tar.bz2
firmware-3d4f0028d60cebc829ac9c947d1a61cc840d05c0.zip
[Keymap] major keymap overhaul (#10185)
* experiment with userspace * reorganise * readme * missing oneshot shift from ignored keys * recombine hands in layout macro
Diffstat (limited to 'users')
-rw-r--r--users/callum/callum.c130
-rw-r--r--users/callum/oneshot.c57
-rw-r--r--users/callum/oneshot.h31
-rw-r--r--users/callum/readme.md99
-rw-r--r--users/callum/rules.mk3
-rw-r--r--users/callum/swapper.c27
-rw-r--r--users/callum/swapper.h20
7 files changed, 367 insertions, 0 deletions
diff --git a/users/callum/callum.c b/users/callum/callum.c
new file mode 100644
index 000000000..4661902af
--- /dev/null
+++ b/users/callum/callum.c
@@ -0,0 +1,130 @@
+#include QMK_KEYBOARD_H
+
+#include "oneshot.h"
+#include "swapper.h"
+
+#define HOME G(KC_LEFT)
+#define END G(KC_RGHT)
+#define FWD G(KC_RBRC)
+#define BACK G(KC_LBRC)
+#define TABL G(S(KC_LBRC))
+#define TABR G(S(KC_RBRC))
+#define SPCL A(G(KC_LEFT))
+#define SPCR A(G(KC_RGHT))
+#define LA_SYM MO(SYM)
+#define LA_NAV MO(NAV)
+
+enum layers {
+ DEF,
+ SYM,
+ NAV,
+ NUM,
+};
+
+enum keycodes {
+ // Custom oneshot mod implementation with no timers.
+ OS_SHFT = SAFE_RANGE,
+ OS_CTRL,
+ OS_ALT,
+ OS_CMD,
+
+ SW_WIN, // Switch to next window (cmd-tab)
+ SW_LANG, // Switch to next input language (ctl-spc)
+};
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [DEF] = LAYOUT_callum(
+ KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_QUOT,
+ KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O,
+ KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH,
+ LA_NAV, KC_LSFT, KC_SPC, LA_SYM
+ ),
+
+ [SYM] = LAYOUT_callum(
+ KC_ESC, KC_LBRC, KC_LCBR, KC_LPRN, KC_TILD, KC_CIRC, KC_RPRN, KC_RCBR, KC_RBRC, KC_GRV,
+ KC_MINS, KC_ASTR, KC_EQL, KC_UNDS, KC_DLR, KC_HASH, OS_CMD, OS_ALT, OS_CTRL, OS_SHFT,
+ KC_PLUS, KC_PIPE, KC_AT, KC_BSLS, KC_PERC, XXXXXXX, KC_AMPR, KC_SCLN, KC_COLN, KC_EXLM,
+ _______, _______, _______, _______
+ ),
+
+ [NAV] = LAYOUT_callum(
+ KC_TAB, SW_WIN, TABL, TABR, KC_VOLU, RESET, HOME, KC_UP, END, KC_DEL,
+ OS_SHFT, OS_CTRL, OS_ALT, OS_CMD, KC_VOLD, KC_CAPS, KC_LEFT, KC_DOWN, KC_RGHT, KC_BSPC,
+ SPCL, SPCR, BACK, FWD, KC_MPLY, XXXXXXX, KC_PGDN, KC_PGUP, SW_LANG, KC_ENT,
+ _______, _______, _______, _______
+ ),
+
+ [NUM] = LAYOUT_callum(
+ KC_7, KC_5, KC_3, KC_1, KC_9, KC_8, KC_0, KC_2, KC_4, KC_6,
+ OS_SHFT, OS_CTRL, OS_ALT, OS_CMD, KC_F11, KC_F10, OS_CMD, OS_ALT, OS_CTRL, OS_SHFT,
+ KC_F7, KC_F5, KC_F3, KC_F1, KC_F9, KC_F8, KC_F12, KC_F2, KC_F4, KC_F6,
+ _______, _______, _______, _______
+ ),
+};
+
+bool is_oneshot_cancel_key(uint16_t keycode) {
+ switch (keycode) {
+ case LA_SYM:
+ case LA_NAV:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool is_oneshot_ignored_key(uint16_t keycode) {
+ switch (keycode) {
+ case LA_SYM:
+ case LA_NAV:
+ case KC_LSFT:
+ case OS_SHFT:
+ case OS_CTRL:
+ case OS_ALT:
+ case OS_CMD:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool sw_win_active = false;
+bool sw_lang_active = false;
+
+oneshot_state os_shft_state = os_up_unqueued;
+oneshot_state os_ctrl_state = os_up_unqueued;
+oneshot_state os_alt_state = os_up_unqueued;
+oneshot_state os_cmd_state = os_up_unqueued;
+
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ update_swapper(
+ &sw_win_active, KC_LGUI, KC_TAB, SW_WIN,
+ keycode, record
+ );
+ update_swapper(
+ &sw_lang_active, KC_LCTL, KC_SPC, SW_LANG,
+ keycode, record
+ );
+
+ update_oneshot(
+ &os_shft_state, KC_LSFT, OS_SHFT,
+ keycode, record
+ );
+ update_oneshot(
+ &os_ctrl_state, KC_LCTL, OS_CTRL,
+ keycode, record
+ );
+ update_oneshot(
+ &os_alt_state, KC_LALT, OS_ALT,
+ keycode, record
+ );
+ update_oneshot(
+ &os_cmd_state, KC_LCMD, OS_CMD,
+ keycode, record
+ );
+
+ return true;
+}
+
+layer_state_t layer_state_set_user(layer_state_t state) {
+ return update_tri_layer_state(state, SYM, NAV, NUM);
+}
diff --git a/users/callum/oneshot.c b/users/callum/oneshot.c
new file mode 100644
index 000000000..33ec3895e
--- /dev/null
+++ b/users/callum/oneshot.c
@@ -0,0 +1,57 @@
+#include "oneshot.h"
+
+void update_oneshot(
+ oneshot_state *state,
+ uint16_t mod,
+ uint16_t trigger,
+ uint16_t keycode,
+ keyrecord_t *record
+) {
+ if (keycode == trigger) {
+ if (record->event.pressed) {
+ // Trigger keydown
+ if (*state == os_up_unqueued) {
+ register_code(mod);
+ }
+ *state = os_down_unused;
+ } else {
+ // Trigger keyup
+ switch (*state) {
+ case os_down_unused:
+ // If we didn't use the mod while trigger was held, queue it.
+ *state = os_up_queued;
+ break;
+ case os_down_used:
+ // If we did use the mod while trigger was held, unregister it.
+ *state = os_up_unqueued;
+ unregister_code(mod);
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ if (record->event.pressed) {
+ if (is_oneshot_cancel_key(keycode) && *state != os_up_unqueued) {
+ // Cancel oneshot on designated cancel keydown.
+ *state = os_up_unqueued;
+ unregister_code(mod);
+ }
+ } else {
+ if (!is_oneshot_ignored_key(keycode)) {
+ // On non-ignored keyup, consider the oneshot used.
+ switch (*state) {
+ case os_down_unused:
+ *state = os_down_used;
+ break;
+ case os_up_queued:
+ *state = os_up_unqueued;
+ unregister_code(mod);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/users/callum/oneshot.h b/users/callum/oneshot.h
new file mode 100644
index 000000000..a6b8e1774
--- /dev/null
+++ b/users/callum/oneshot.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include QMK_KEYBOARD_H
+
+// Represents the four states a oneshot key can be in
+typedef enum {
+ os_up_unqueued,
+ os_up_queued,
+ os_down_unused,
+ os_down_used,
+} oneshot_state;
+
+// Custom oneshot mod implementation that doesn't rely on timers. If a mod is
+// used while it is held it will be unregistered on keyup as normal, otherwise
+// it will be queued and only released after the next non-mod keyup.
+void update_oneshot(
+ oneshot_state *state,
+ uint16_t mod,
+ uint16_t trigger,
+ uint16_t keycode,
+ keyrecord_t *record
+);
+
+// To be implemented by the consumer. Defines keys to cancel oneshot mods.
+bool is_oneshot_cancel_key(uint16_t keycode);
+
+// To be implemented by the consumer. Defines keys to ignore when determining
+// whether a oneshot mod has been used. Setting this to modifiers and layer
+// change keys allows stacking multiple oneshot modifiers, and carrying them
+// between layers.
+bool is_oneshot_ignored_key(uint16_t keycode);
diff --git a/users/callum/readme.md b/users/callum/readme.md
new file mode 100644
index 000000000..24b71038b
--- /dev/null
+++ b/users/callum/readme.md
@@ -0,0 +1,99 @@
+A keymap for 34 keys with 4 layers and no mod-tap.
+
+![](https://raw.githubusercontent.com/callum-oakley/keymap/master/keymap.svg)
+
+## Details
+
+- Hold `sym` to activate the symbols layer.
+- Hold `nav` to activate the navigation layer.
+- Hold `sym` and `nav` together to activate the numbers layer.
+- The home row modifiers are oneshot so that it's possible to modify the
+ keys on the base layer, where there are no dedicated modifiers.
+- `swap win` sends `cmd-tab` for changing focus in macOS but holds `cmd`
+ between consecutive presses.
+- `swap lang` behaves similarly but sends `ctrl-space`, for changing input
+ language in macOS.
+
+## Oneshot modifiers
+
+The home row modifiers can either be held and used as normal, or if no other
+keys are pressed while a modifier is down, the modifier will be queued and
+applied to the next non-modifier keypress. For example to type `shift-cmd-t`,
+type `sym-o-n` (or `nav-a-t`), release, then hit `t`.
+
+You can and should hit chords as fast as you like because there are no timers
+involved.
+
+Cancel unused modifiers by tapping `nav` or `sym`.
+
+### Userspace oneshot implementation
+
+For my usage patterns I was hitting stuck modifiers frequently with [`OSM`][]
+(maybe related to [#3963][]?). I'd like to try to help fix this in QMK proper,
+but implementing oneshot mods in userspace first was:
+
+1. Fun.
+2. A good exploration of how I think oneshot mods should work without timers.
+
+So in the meantime, this [userspace oneshot implementation][] is working well
+for me.
+
+## Swapper
+
+`swap win` sends `cmd-tab`, but holds `cmd` between consecutive keypresses.
+`cmd` is released when some other key is hit or released. For example
+
+ nav down, swap win, swap win, nav up -> cmd down, tab, tab, cmd up
+ nav down, swap win, enter -> cmd down, tab, cmd up, enter
+
+`swap lang` sends `ctrl-space` to swap input languages in macOS and behaves
+similarly.
+
+[Swapper implementation.][]
+
+## Why no mod-tap?
+
+[Mod-tap][] seems to be by far the most popular tool among users of tiny
+keyboards to answer the question of where to put the modifiers, and in the
+right hands it can clearly work brilliantly, but I've always found myself error
+prone and inconsistent with it.
+
+With dedicated modifiers, there are three ways one might type `ctrl-c`:
+
+ ctrl down, ctrl up, c down, c up
+ ctrl down, c down, ctrl up, c up
+ ctrl down, c down, c up, ctrl up
+
+Basically, you never have to worry about the keyups, as long as the keydowns
+occur in the correct order. Similarly, there are three ways one might type
+`ac`:
+
+ a down, a up, c down, c up
+ a down, c down, a up, c up
+ a down, c down, c up, a up
+
+Replace `a` with `ctrl` and this is exactly what we had before! So if we want
+to put `a` and `ctrl` on the same key we have a problem, because without
+considering timing these sequences become ambiguous. So let's consider timing.
+
+The solution to the ambiguity that QMK employs is to configure the
+`TAPPING_TERM` and consider a key held rather than tapped if it is held for
+long enough. My problem with this is that it forces you to slow down to use
+modifiers. By its very nature the tapping term must be longer than the longest
+you would ever hold a key while typing on the slowest laziest Sunday afternoon.
+I'm not typing at 100% speed at all times, but when I am, having to think about
+timing and consciously slow down for certain actions never fails to trip me up.
+
+So alas, mod-tap is not for me -- but if it works for you, more power to you.
+:)
+
+* * *
+
+[My github][]
+
+[`OSM`]: /docs/one_shot_keys.md
+[#3963]: https://github.com/qmk/qmk_firmware/issues/3963
+[userspace oneshot implementation]: oneshot.c
+[swapper implementation.]: swapper.c
+[Mod-tap]: https://github.com/qmk/qmk_firmware/blob/master/docs/mod_tap.md
+[My github]: https://github.com/callum-oakley
diff --git a/users/callum/rules.mk b/users/callum/rules.mk
new file mode 100644
index 000000000..2d98e02c5
--- /dev/null
+++ b/users/callum/rules.mk
@@ -0,0 +1,3 @@
+SRC += callum.c
+SRC += oneshot.c
+SRC += swapper.c
diff --git a/users/callum/swapper.c b/users/callum/swapper.c
new file mode 100644
index 000000000..736b2fef0
--- /dev/null
+++ b/users/callum/swapper.c
@@ -0,0 +1,27 @@
+#include "swapper.h"
+
+void update_swapper(
+ bool *active,
+ uint16_t cmdish,
+ uint16_t tabish,
+ uint16_t trigger,
+ uint16_t keycode,
+ keyrecord_t *record
+) {
+ if (keycode == trigger) {
+ if (record->event.pressed) {
+ if (!*active) {
+ *active = true;
+ register_code(cmdish);
+ }
+ register_code(tabish);
+ } else {
+ unregister_code(tabish);
+ // Don't unregister cmdish until some other key is hit or released.
+ }
+ } else if (*active) {
+ unregister_code(cmdish);
+ *active = false;
+ }
+}
+
diff --git a/users/callum/swapper.h b/users/callum/swapper.h
new file mode 100644
index 000000000..ad47fd96c
--- /dev/null
+++ b/users/callum/swapper.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include QMK_KEYBOARD_H
+
+// Implements cmd-tab like behaviour on a single key. On first tap of trigger
+// cmdish is held and tabish is tapped -- cmdish then remains held until some
+// other key is hit or released. For example:
+//
+// trigger, trigger, a -> cmd down, tab, tab, cmd up, a
+// nav down, trigger, nav up -> nav down, cmd down, tab, cmd up, nav up
+//
+// This behaviour is useful for more than just cmd-tab, hence: cmdish, tabish.
+void update_swapper(
+ bool *active,
+ uint16_t cmdish,
+ uint16_t tabish,
+ uint16_t trigger,
+ uint16_t keycode,
+ keyrecord_t *record
+);