summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-11 21:54:10 +0700
committerPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-11 21:54:10 +0700
commit513286cf9873564879ee2e50e0e432429ee53a1e (patch)
tree3eb0cba61e134a008902ff2afacb5cbcaaf6f8e1
parent79de0cd11964e9205654498aa0027510e3c3535e (diff)
LSpace + RSpace = switch layer
-rw-r--r--keyboards/handwired/promethium/keymaps/priyadi/config.h2
-rw-r--r--keyboards/handwired/promethium/keymaps/priyadi/keymap.c91
2 files changed, 92 insertions, 1 deletions
diff --git a/keyboards/handwired/promethium/keymaps/priyadi/config.h b/keyboards/handwired/promethium/keymaps/priyadi/config.h
index 36baedd486..53059ca7d4 100644
--- a/keyboards/handwired/promethium/keymaps/priyadi/config.h
+++ b/keyboards/handwired/promethium/keymaps/priyadi/config.h
@@ -19,4 +19,6 @@
#define LAYOUT_NORMAN
#define LAYOUT_WORKMAN
+#define DOUBLESPACE_LAYER_ENABLE
+
#endif
diff --git a/keyboards/handwired/promethium/keymaps/priyadi/keymap.c b/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
index 2a21b4ba77..9fa038724a 100644
--- a/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
+++ b/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
@@ -25,6 +25,13 @@
#define KC_RALT MT(MOD_RALT, KC_SLCK)
bool capslock = false;
+#ifdef DOUBLESPACE_LAYER_ENABLE
+bool lspace_active = false;
+bool rspace_active = false;
+bool lspace_emitted = false;
+bool rspace_emitted = false;
+bool space_layer_entered = false;
+#endif
// glow
enum glow_modes {
@@ -55,6 +62,9 @@ enum layers {
_SYS,
};
+// double-space layer
+#define _SPACE _GUI
+
enum planck_keycodes {
// layouts
QWERTY = SAFE_RANGE,
@@ -77,6 +87,8 @@ enum planck_keycodes {
OSX,
// others
+ LSPACE,
+ RSPACE,
GLOW,
AUDIO
};
@@ -504,7 +516,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_QUOT, KC_ENT ,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
- KC_LCTL, KC_LALT, KC_LGUI, PUNC, NUM, KC_SPC, KC_SPC, FUNC, GREEK, KC_RGUI, KC_RALT, KC_RCTL
+ KC_LCTL, KC_LALT, KC_LGUI, PUNC, NUM, LSPACE, RSPACE, FUNC, GREEK, KC_RGUI, KC_RALT, KC_RCTL
),
/* Dvorak
@@ -745,7 +757,84 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
bool lshift = keyboard_report->mods & MOD_BIT(KC_LSFT);
bool rshift = keyboard_report->mods & MOD_BIT(KC_RSFT);
+#ifdef DOUBLESPACE_LAYER_ENABLE
+ // double-space: send space immediately if any other key depressed before space is released
+ if ((lspace_active ^ rspace_active)
+ && keycode != LSPACE
+ && keycode != RSPACE
+ && record->event.pressed)
+ {
+ if (lspace_active) {
+ if (!lspace_emitted) {
+ register_code(KC_SPC);
+ unregister_code(KC_SPC);
+ }
+ lspace_emitted = true;
+ }
+ if (rspace_active) {
+ if (!rspace_emitted) {
+ register_code(KC_SPC);
+ unregister_code(KC_SPC);
+ }
+ rspace_emitted = true;
+ }
+ }
+#endif
+
switch (keycode) {
+
+#ifdef DOUBLESPACE_LAYER_ENABLE
+ // double-space enter space layer
+ case LSPACE:
+ if (record->event.pressed) {
+ lspace_active = true;
+ if (rspace_active) {
+ layer_on(_SPACE);
+ space_layer_entered = true;
+ }
+ } else {
+ lspace_active = false;
+ if (space_layer_entered) {
+ layer_off(_SPACE);
+ if (!rspace_active) {
+ space_layer_entered = false;
+ }
+ } else {
+ if (!lspace_emitted) {
+ register_code(KC_SPC);
+ unregister_code(KC_SPC);
+ }
+ lspace_emitted = false;
+ }
+ }
+ return false;
+ break;
+ case RSPACE:
+ if (record->event.pressed) {
+ rspace_active = true;
+ if (lspace_active) {
+ layer_on(_SPACE);
+ space_layer_entered = true;
+ }
+ } else {
+ rspace_active = false;
+ if (space_layer_entered) {
+ layer_off(_SPACE);
+ if (!lspace_active) {
+ space_layer_entered = false;
+ }
+ } else {
+ if (!rspace_emitted) {
+ register_code(KC_SPC);
+ unregister_code(KC_SPC);
+ }
+ rspace_emitted = false;
+ }
+ }
+ return false;
+ break;
+#endif
+
// handle greek layer shift
// handle both shift = capslock
case KC_LSFT: