From ac3b9333d8b52001cee682bb833e145c5252f72d Mon Sep 17 00:00:00 2001
From: Christian Sandven <christian.sandven@kindly.ai>
Date: Fri, 13 Aug 2021 21:28:05 +0200
Subject: [PATCH] [Keyboard] Add optional colemak layout to keymap (#13217)

---
 .../keyprez/corgi/keymaps/default/keymap.c    | 47 ++++++++++++++++++-
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/keyboards/keyprez/corgi/keymaps/default/keymap.c b/keyboards/keyprez/corgi/keymaps/default/keymap.c
index a1f8164491..757b3fd1db 100644
--- a/keyboards/keyprez/corgi/keymaps/default/keymap.c
+++ b/keyboards/keyprez/corgi/keymaps/default/keymap.c
@@ -18,6 +18,7 @@
 // Defines names for use in layer keycodes and the keymap
 enum layer_names {
     _QWERTY,
+    _COLEMAK,
     _BASE,
     _FN,
     _LOWER,
@@ -25,6 +26,11 @@ enum layer_names {
     _CMD,
 };
 
+enum corgi_keycodes {
+    QWERTY = SAFE_RANGE,
+    COLEMAK
+};
+
 #define LOWER MO(_LOWER)
 #define RAISE MO(_RAISE)
 #define CMD   MO(_CMD)
@@ -49,6 +55,25 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
         KC_MUTE
     ),
 
+    /* Colemak
+     * ,-----------------------------------------------------------------------------------.
+     * | Tab  |   Q  |   W  |   F  |   P  |   G  |   J  |   L  |   U  |   Y  |   ;  | Bksp |
+     * |------+------+------+------+------+------+------+------+------+------+------+------|
+     * | Esc  |   A  |   R  |   S  |   T  |   D  |   H  |   N  |   E  |   I  |   O  |  "   |
+     * |------+------+------+------+------+------+------+------+------+------+------+------|
+     * | Shift|   Z  |   X  |   C  |   V  |   B  |   K  |   M  |   ,  |   .  |   /  |Enter |
+     * |------+------+------+------+------+------+------+------+------+------+------+------|
+     * | Brite| Ctrl | Alt  | GUI  |Lower |    Space    |Raise | Left | Down |  Up  |Right |
+    * `-----------------------------------------------------------------------------------'
+    */
+    [_COLEMAK] = LAYOUT(
+        KC_TAB,  KC_Q,    KC_W,    KC_F,    KC_P,    KC_G,    KC_J,    KC_L,    KC_U,    KC_Y,    KC_SCLN, KC_BSPC,
+        KC_ESC,  KC_A,    KC_R,    KC_S,    KC_T,    KC_D,    KC_H,    KC_N,    KC_E,    KC_I,    KC_O,    KC_QUOT,
+        KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_K,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_ENT ,
+        KC_LCTL, KC_LGUI, KC_LALT, CMD,     LOWER,   KC_SPC,  KC_SPC,  RAISE,   KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT,
+        KC_MUTE
+    ),
+
     /* Lower
      * ,-----------------------------------------------------------------------------------.
      * |   ~  |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  | Bksp |
@@ -99,9 +124,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
      * `-----------------------------------------------------------------------------------'
     */
     [_CMD] = LAYOUT(
-        _______, _______, _______, _______, _______, _______, _______, _______, KC_P1,   KC_P2,   KC_P3,   KC_PMNS,
+        _______, QWERTY,  _______, _______, _______, _______, _______, _______, KC_P1,   KC_P2,   KC_P3,   KC_PMNS,
         _______, _______, _______, _______, _______, _______, _______, _______, KC_P4,   KC_P5,   KC_P6,   KC_PPLS,
-        _______, _______, _______, _______, _______, _______, _______, _______, KC_P7,   KC_P8,   KC_P9,   _______,
+        _______, _______, _______, COLEMAK, _______, _______, _______, _______, KC_P7,   KC_P8,   KC_P9,   _______,
         _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P0,   KC_PDOT, _______,
         _______
     ),
@@ -111,3 +136,21 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
     tap_code(clockwise ? KC_VOLU : KC_VOLD);
     return true;
 }
+
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+    switch (keycode) {
+        case QWERTY:
+            if (record->event.pressed) {
+                set_single_persistent_default_layer(_QWERTY);
+            }
+            return false;
+            break;
+        case COLEMAK:
+            if (record->event.pressed) {
+                set_single_persistent_default_layer(_COLEMAK);
+            }
+            return false;
+            break;
+    }
+    return true;
+}