Skip to content

Commit

Permalink
[Keymap] Remove LAYOUT_kc macros from edvorakjp keymaps (qmk#12217)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaew authored Apr 10, 2021
1 parent 0c29e3d commit 3aa3ba0
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 193 deletions.
28 changes: 9 additions & 19 deletions users/edvorakjp/edvorakjp.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
#include "edvorakjp.h"

void matrix_init_user(void) {
edvorakjp_status_init();
matrix_init_keymap();
edvorakjp_status_init();
matrix_init_keymap();
}

__attribute__ ((weak))
void matrix_init_keymap() {}
__attribute__((weak)) void matrix_init_keymap() {}

uint32_t layer_state_set_user(uint32_t state) {
state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
return layer_state_set_keymap(state);
state = update_tri_layer_state(state, L_EDVORAKJP_LOWER, L_EDVORAKJP_RAISE, L_EDVORAKJP_ADJUST);
return layer_state_set_keymap(state);
}

__attribute__ ((weak))
uint32_t layer_state_set_keymap(uint32_t state) {
return state;
}
__attribute__((weak)) uint32_t layer_state_set_keymap(uint32_t state) { return state; }

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return process_record_keymap(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);
bool process_record_user_result = process_record_keymap(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);
return process_record_user_result;
}

__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
__attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; }
86 changes: 53 additions & 33 deletions users/edvorakjp/edvorakjp.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,76 @@
#ifndef EDVORAKJP
#define EDVORAKJP
#pragma once

#include "quantum.h"
#include "action_layer.h"

#define EECONFIG_EDVORAK (uint8_t *)20

// clang-format off
#define __EDVORAKJP_BASE_L1__ KC_QUOTE, KC_COMMA, KC_DOT, KC_Y, KC_Q
#define __EDVORAKJP_BASE_L2__ KC_A, LALT_T(KC_O), LGUI_T(KC_E), LCTL_T(KC_I), KC_U
#define __EDVORAKJP_BASE_L3__ KC_SCOLON, KC_X, KC_C, KC_V, KC_Z

#define __EDVORAKJP_BASE_R1__ KC_F, KC_G, KC_R, KC_W, KC_P
#define __EDVORAKJP_BASE_R2__ KC_D, RSFT_T(KC_T), RGUI_T(KC_N), RALT_T(KC_S), KC_M
#define __EDVORAKJP_BASE_R3__ KC_H, KC_J, KC_K, KC_L, KC_B

#define __EDVORAKJP_NUMBER_L__ KC_1, LALT_T(KC_2), LGUI_T(KC_3), LCTL_T(KC_4), KC_5
#define __EDVORAKJP_NUMBER_R__ KC_6, RSFT_T(KC_7), RGUI_T(KC_8), RALT_T(KC_9), KC_0

#define __EDVORAKJP_FUNCTION_L__ KC_F1, KC_F2, LALT_T(KC_F3), LGUI_T(KC_F4), LCTL_T(KC_F5), KC_F6
#define __EDVORAKJP_FUNCTION_R__ KC_F7, RSFT_T(KC_F8), RGUI_T(KC_F9), RALT_T(KC_F10), KC_F11, KC_F12

#define __EDVORAKJP_SYMBOL_L__ KC_EXCLAIM, KC_AT, KC_HASH, KC_DOLLAR
#define __EDVORAKJP_SYMBOL_R__ KC_PERCENT, KC_CIRCUMFLEX, KC_AMPERSAND, KC_ASTERISK

#define __EDVORAKJP_BRACKET_L__ KC_LEFT_CURLY_BRACE, KC_LBRACKET, KC_LEFT_PAREN
#define __EDVORAKJP_BRACKET_R__ KC_RIGHT_PAREN, KC_RBRACKET, KC_RIGHT_CURLY_BRACE

#define __EDVORAKJP_PAGE__ KC_HOME, KC_PGDOWN, KC_PGUP, KC_END
#define __EDVORAKJP_CURSOR__ KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT

#define LA_TAB LALT_T(KC_TAB)
#define LS_SPC LSFT_T(KC_SPACE)
#define RC_BSPC RCTL_T(KC_BSPACE)
#define RC_DEL RCTL_T(KC_DELETE)
#define RG_ENT RGUI_T(KC_ENTER)

#define LOWER_TD TD(TD_EDVORAKJP_LOWER)
#define RAISE_TD TD(TD_EDVORAKJP_RAISE)
// clang-format on

extern keymap_config_t keymap_config;

enum edvorakjp_layers {
_EDVORAK = 0,
_LOWER,
_RAISE,
_ADJUST,
_EXTRA,
L_EDVORAKJP_BASE = 0,
L_EDVORAKJP_LOWER,
L_EDVORAKJP_RAISE,
L_EDVORAKJP_ADJUST,
L_EDVORAKJP_EXTRA,
};

enum edvorakjp_keycodes {
EDVORAK = SAFE_RANGE,
LOWER,
RAISE,
KC_MAC,
KC_WIN,
KC_JPN,
KC_ENG,
NEW_SAFE_RANGE
KC_EDVORAKJP_LOWER = SAFE_RANGE,
KC_EDVORAKJP_RAISE,
KC_MAC,
KC_WIN,
KC_JPN,
KC_ENG,
NEW_SAFE_RANGE,
};

#define KC_LC(k) LCTL_T(KC_##k)
#define KC_LS(k) LSFT_T(KC_##k)
#define KC_LA(k) LALT_T(KC_##k)
#define KC_LG(k) LGUI_T(KC_##k)
#define KC_RC(k) RCTL_T(KC_##k)
#define KC_RS(k) RSFT_T(KC_##k)
#define KC_RG(k) RGUI_T(KC_##k)
#define KC_RA(k) RALT_T(KC_##k)

enum tap_dance_code {
TD_LOWER = 0,
TD_RAISE
TD_EDVORAKJP_LOWER = 0,
TD_EDVORAKJP_RAISE,
};

// base
void dvorakj_layer_off(void);
void matrix_init_user(void);
void matrix_init_keymap(void);
void matrix_init_user(void);
void matrix_init_keymap(void);
uint32_t layer_state_set_user(uint32_t state);
uint32_t layer_state_set_keymap(uint32_t state);
bool process_record_user(uint16_t keycode, keyrecord_t *record);
bool process_record_keymap(uint16_t keycode, keyrecord_t *record);
bool process_record_user(uint16_t keycode, keyrecord_t *record);
bool process_record_keymap(uint16_t keycode, keyrecord_t *record);

// status
void edvorakjp_status_init(void);
Expand All @@ -66,5 +88,3 @@ bool process_record_edvorakjp_swap_scln(uint16_t keycode, keyrecord_t *record);
bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record);
bool process_record_layer(uint16_t keycode, keyrecord_t *record);
bool process_record_ime(uint16_t keycode, keyrecord_t *record);

#endif // EDVORAKJP
122 changes: 61 additions & 61 deletions users/edvorakjp/edvorakjp_process_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,81 @@ static uint16_t time_on_pressed;
*/
bool process_record_edvorakjp_swap_scln(uint16_t keycode, keyrecord_t *record) {
#ifdef SWAP_SCLN
static const uint8_t shift_bits = MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT);
static uint8_t last_mods_status;
if (keycode == KC_SCLN) {
if (record->event.pressed) {
last_mods_status = get_mods();
static const uint8_t shift_bits = MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT);
static uint8_t last_mods_status;
if (keycode == KC_SCLN) {
if (record->event.pressed) {
last_mods_status = get_mods();

// invert shift_bits
if (last_mods_status & shift_bits) {
set_mods(last_mods_status & ~shift_bits);
} else {
set_mods(last_mods_status | MOD_BIT(KC_LSFT));
}
} else {
set_mods(last_mods_status);
last_mods_status = 0;
// invert shift_bits
if (last_mods_status & shift_bits) {
set_mods(last_mods_status & ~shift_bits);
} else {
set_mods(last_mods_status | MOD_BIT(KC_LSFT));
}
} else {
set_mods(last_mods_status);
last_mods_status = 0;
}
}
}
#endif
return true;
return true;
}

bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_MAC:
case KC_WIN:
if (record->event.pressed) {
set_enable_kc_lang(keycode == KC_MAC);
}
return false;
}
return true;
switch (keycode) {
case KC_MAC:
case KC_WIN:
if (record->event.pressed) {
set_enable_kc_lang(keycode == KC_MAC);
}
return false;
}
return true;
}

bool process_record_layer(uint16_t keycode, keyrecord_t *record) {
#if TAP_DANCE_ENABLE != yes
switch (keycode) {
case LOWER:
if (record->event.pressed) {
layer_on(_LOWER);
time_on_pressed = record->event.time;
} else {
layer_off(_LOWER);
switch (keycode) {
case KC_EDVORAKJP_LOWER:
if (record->event.pressed) {
layer_on(L_EDVORAKJP_LOWER);
time_on_pressed = record->event.time;
} else {
layer_off(L_EDVORAKJP_LOWER);

if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
set_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) {
set_japanese_mode(false);
}
time_on_pressed = 0;
}
return false;
case KC_EDVORAKJP_RAISE:
if (record->event.pressed) {
layer_on(L_EDVORAKJP_RAISE);
time_on_pressed = record->event.time;
} else {
layer_off(L_EDVORAKJP_RAISE);

if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
set_japanese_mode(true);
}
time_on_pressed = 0;
}
return false;
}
if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
set_japanese_mode(true);
}
time_on_pressed = 0;
}
return false;
}
#endif
return true;
return true;
}

bool process_record_ime(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_JPN:
case KC_ENG:
if (record->event.pressed) {
set_japanese_mode(keycode == KC_JPN);
}
return false;
}
return true;
switch (keycode) {
case KC_JPN:
case KC_ENG:
if (record->event.pressed) {
set_japanese_mode(keycode == KC_JPN);
}
return false;
}
return true;
}
58 changes: 25 additions & 33 deletions users/edvorakjp/edvorakjp_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,55 @@
#include "edvorakjp.h"

typedef union {
uint8_t raw;
struct {
bool enable_kc_lang; // for macOS
};
uint8_t raw;
struct {
bool enable_kc_lang; // for macOS
};
} edvorakjp_config_t;
static edvorakjp_config_t edvorakjp_config;

typedef struct {
bool japanese_mode;
bool japanese_mode;
} edvorakjp_state_t;
static edvorakjp_state_t edvorakjp_state;

/*
* private methods
*/
uint8_t eeconfig_read_edvorakjp(void) {
return eeprom_read_byte(EECONFIG_EDVORAK);
}
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 eeconfig_update_edvorakjp(uint8_t val) { eeprom_update_byte(EECONFIG_EDVORAK, val); }

/*
* public methods
*/
void edvorakjp_status_init(void) {
edvorakjp_state.japanese_mode = false;
edvorakjp_config.raw = eeconfig_read_edvorakjp();
edvorakjp_state.japanese_mode = false;
edvorakjp_config.raw = eeconfig_read_edvorakjp();
}

bool get_enable_kc_lang(void) {
return edvorakjp_config.enable_kc_lang;
}
bool get_enable_kc_lang(void) { return edvorakjp_config.enable_kc_lang; }

void set_enable_kc_lang(bool new_state) {
edvorakjp_config.enable_kc_lang = new_state;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
edvorakjp_config.enable_kc_lang = new_state;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
}

bool get_japanese_mode(void) {
return edvorakjp_state.japanese_mode;
}
bool get_japanese_mode(void) { return edvorakjp_state.japanese_mode; }

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

0 comments on commit 3aa3ba0

Please sign in to comment.