Skip to content

Commit

Permalink
Keymap: Refactor edvorakjp user library (qmk#4480)
Browse files Browse the repository at this point in the history
* Refactor edvorakjp user library

* add tap dance support

* update keymaps

* edvorakjp: add SWAP_SCLN option

* fix behavior of SWAP_SCLN
  • Loading branch information
epaew authored and rseymour committed Mar 13, 2019
1 parent 0c17a12 commit 0b8aa8e
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 255 deletions.
1 change: 1 addition & 0 deletions keyboards/helix/rev2/keymaps/edvorakjp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#undef TAPPING_FORCE_HOLD
#undef TAPPING_TERM
#define TAPPING_TERM 120
#define SWAP_SCLN

// If you need more program area, try select and reduce rgblight modes to use.

Expand Down
2 changes: 1 addition & 1 deletion keyboards/helix/rev2/keymaps/edvorakjp/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case KC_LOCK:
if (record->event.pressed) {
if (edvorakjp_config.enable_kc_lang) {
if (get_enable_kc_lang()) {
SEND_STRING( SS_LCTRL(SS_LSFT(SS_TAP(X_POWER))) );
} else {
SEND_STRING( SS_LGUI("l") );
Expand Down
2 changes: 1 addition & 1 deletion keyboards/helix/rev2/keymaps/edvorakjp/keymap_4rows.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[_EDVORAK] = LAYOUT_kc(
//,----+----+----+----+----+----. ,----+----+----+----+----+----.
LBRC,RBRC,COMM,DOT , P , Y , F , G , R , W , Q ,BSLS,
LBRC,RBRC,COMM,DOT , Y , P , F , G , R , W , Q ,BSLS,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
EQL , A , O , E , I , U , D , T , N , S , M ,MINS,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
Expand Down
2 changes: 1 addition & 1 deletion keyboards/helix/rev2/keymaps/edvorakjp/keymap_5rows.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//,----+----+----+----+----+----. ,----+----+----+----+----+----.
GRV ,EXLM, AT ,HASH,DLR ,PERC, CIRC,AMPR,ASTR,LPRN,RPRN,BSPC,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
LBRC,RBRC,COMM,DOT , P , Y , F , G , R , W , Q ,BSLS,
LBRC,RBRC,COMM,DOT , Y , P , F , G , R , W , Q ,BSLS,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
EQL , A , O , E , I , U , D , T , N , S , M ,MINS,
//|----+----+----+----+----+----+----. ,----|----+----+----+----+----+----|
Expand Down
15 changes: 5 additions & 10 deletions keyboards/helix/rev2/keymaps/edvorakjp/oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ void render_status(struct CharacterMatrix *matrix) {

// Render to mode icon
static char logo[][2][3] = {{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
if (edvorakjp_config.enable_kc_lang) {
matrix_write(matrix, logo[0][0]);
matrix_write_P(matrix, PSTR("\n"));
matrix_write(matrix, logo[0][1]);
} else {
matrix_write(matrix, logo[1][0]);
matrix_write_P(matrix, PSTR("\n"));
matrix_write(matrix, logo[1][1]);
}
int mode_number = get_enable_kc_lang() ? 0 : 1;
matrix_write(matrix, logo[mode_number][0]);
matrix_write(matrix, "\n");
matrix_write(matrix, logo[mode_number][1]);

// Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
char buf[40];
Expand Down Expand Up @@ -63,7 +58,7 @@ void render_status(struct CharacterMatrix *matrix) {
// Host Keyboard LED Status
char led[40];
snprintf(led, sizeof(led), "\n%s %s %s %s",
edvorakjp_config.enable_jp_extra_layer && japanese_mode ? "EXT" : " ",
get_enable_jp_extra_layer() && get_japanese_mode() ? "EXT" : " ",
(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NMLK" : " ",
(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
Expand Down
1 change: 1 addition & 0 deletions keyboards/iris/keymaps/edvorakjp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
#define MOUSEKEY_WHEEL_TIME_TO_MAX 20

#define TAPPING_TERM 120
#define SWAP_SCLN

#endif
7 changes: 2 additions & 5 deletions keyboards/iris/keymaps/edvorakjp/keymap.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include QMK_KEYBOARD_H
#include "action_layer.h"
#include "eeconfig.h"

#include "edvorakjp.h"

enum custom_keycodes {
Expand Down Expand Up @@ -32,7 +29,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
//,----+----+----+----+----+----. ,----+----+----+----+----+----.
GRV ,EXLM, AT ,HASH,DLR ,PERC, CIRC,AMPR,ASTR,LPRN,RPRN,BSPC,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
LBRC,RBRC,COMM,DOT , P , Y , F , G , R , W , Q ,BSLS,
LBRC,RBRC,COMM,DOT , Y , P , F , G , R , W , Q ,BSLS,
//|----+----+----+----+----+----| |----+----+----+----+----+----|
EQL , A , O , E , I , U , D , T , N , S , M ,MINS,
//|----+----+----+----+----+----+----. ,----|----+----+----+----+----+----|
Expand Down Expand Up @@ -134,7 +131,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case KC_LOCK:
if (record->event.pressed) {
if (edvorakjp_config.enable_kc_lang) {
if (get_enable_kc_lang()) {
SEND_STRING( SS_LCTRL(SS_LSFT(SS_TAP(X_POWER))) );
} else {
SEND_STRING( SS_LGUI("l") );
Expand Down
222 changes: 7 additions & 215 deletions users/edvorakjp/edvorakjp.c
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
#include "eeprom.h"
#include "edvorakjp.h"

bool japanese_mode;
uint16_t time_on_pressed;

edvorakjp_config_t edvorakjp_config;

uint8_t eeconfig_read_edvorakjp(void) {
return eeprom_read_byte(EECONFIG_EDVORAK);
}

void eeconfig_update_edvorakjp(uint8_t val) {
eeprom_update_byte(EECONFIG_EDVORAK, val);
}

void dvorakj_layer_off(void) {
layer_off(_EDVORAKJ1);
layer_off(_EDVORAKJ2);
}

void update_japanese_mode(bool new_state) {
japanese_mode = new_state;
if (japanese_mode) {
if (edvorakjp_config.enable_kc_lang) {
SEND_STRING(SS_TAP(X_LANG1));
} else {
SEND_STRING(SS_LALT("`"));
}
} else {
dvorakj_layer_off();
if (edvorakjp_config.enable_kc_lang) {
SEND_STRING(SS_TAP(X_LANG2));
} else {
SEND_STRING(SS_LALT("`"));
}
}
}

void matrix_init_user(void) {
japanese_mode = false;
time_on_pressed = 0;
edvorakjp_config.raw = eeconfig_read_edvorakjp();

edvorakjp_status_init();
matrix_init_keymap();
}

Expand All @@ -58,189 +23,16 @@ uint32_t layer_state_set_keymap(uint32_t state) {
return state;
}

/*
* Each process_record_* methods defined here are
* return false if handle edvorak_keycodes, or return true others.
*/
__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}

bool process_record_edvorakjp_ext(uint16_t keycode, keyrecord_t *record) {
if (!(edvorakjp_config.enable_jp_extra_layer &&\
(default_layer_state == 1UL<<_EDVORAK) &&\
japanese_mode &&\
record->event.pressed)) {
return true;
}

// consonant keys
// layer_on(J1) or layer_on(J2) are defined based on key positions.
switch (keycode) {
// right hand's left side w/o N
case KC_F:
case KC_G:
case KC_R:
case KC_D:
case KC_T:
case KC_B:
case KC_H:
case KC_J:
layer_on(_EDVORAKJ1);
register_code(keycode);
unregister_code(keycode);
return false;

// N: toggle layer
case KC_N:
biton32(layer_state) == _EDVORAK ? layer_on(_EDVORAKJ1) : dvorakj_layer_off();
register_code(keycode);
unregister_code(keycode);
return false;

// left hand and right hand's right side
case KC_X:
case KC_C:
case KC_V:
case KC_Z:
case KC_P:
case KC_Y:
case KC_W:
case KC_Q:
case KC_S:
case KC_M:
case KC_K:
case KC_L:
layer_on(_EDVORAKJ2);
register_code(keycode);
unregister_code(keycode);
return false;
}

// vowel keys, symbol keys and modifier keys
dvorakj_layer_off();
switch (keycode) {
// combination vowel keys
case KC_AI:
SEND_STRING("ai");
return false;
case KC_OU:
SEND_STRING("ou");
return false;
case KC_EI:
SEND_STRING("ei");
return false;
case KC_ANN:
SEND_STRING("ann");
return false;
case KC_ONN:
SEND_STRING("onn");
return false;
case KC_ENN:
SEND_STRING("enn");
return false;
case KC_INN:
SEND_STRING("inn");
return false;
case KC_UNN:
SEND_STRING("unn");
return false;

// AOEIU and other (symbol, modifier) keys
default:
return true;
}
}

bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_MAC:
edvorakjp_config.enable_kc_lang = true;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_WIN:
edvorakjp_config.enable_kc_lang = false;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_EXTON:
edvorakjp_config.enable_jp_extra_layer = true;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_EXTOFF:
edvorakjp_config.enable_jp_extra_layer = false;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
}
return true;
}

bool process_record_layer(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case EDVORAK:
if (record->event.pressed) {
set_single_persistent_default_layer(_EDVORAK);
}
return false;
case QWERTY:
if (record->event.pressed) {
dvorakj_layer_off();
set_single_persistent_default_layer(_QWERTY);
}
return false;
case LOWER:
if (record->event.pressed) {
layer_on(_LOWER);
time_on_pressed = record->event.time;
} else {
layer_off(_LOWER);

if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
update_japanese_mode(false);
}
time_on_pressed = 0;
}
return false;
case RAISE:
if (record->event.pressed) {
layer_on(_RAISE);
time_on_pressed = record->event.time;
} else {
layer_off(_RAISE);

if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
update_japanese_mode(true);
}
time_on_pressed = 0;
}
return false;
default:
return true;
}
}

bool process_record_ime(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_JPN:
if (record->event.pressed) {
update_japanese_mode(true);
}
return false;
case KC_ENG:
if (record->event.pressed) {
update_japanese_mode(false);
}
return false;
default:
return true;
}
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {

return process_record_keymap(keycode, record) &&\
process_record_edvorakjp_ext(keycode, record) &&\
process_record_edvorakjp_swap_scln(keycode, record) &&\
process_record_edvorakjp_config(keycode, record) &&\
process_record_layer(keycode, record) &&\
process_record_ime(keycode, record);
}

__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
Loading

0 comments on commit 0b8aa8e

Please sign in to comment.