From 705cd433c22aad00b12183eaa3bada50d90fd97b Mon Sep 17 00:00:00 2001 From: jonavin <71780717+Jonavin@users.noreply.github.com> Date: Tue, 28 Sep 2021 15:24:12 -0400 Subject: [Keymap] fix NKRO - switch to get_mods() and refactor encoder action code (#14278) Co-authored-by: Jonavin <=> --- keyboards/gmmk/pro/ansi/keymaps/jonavin/keymap.c | 37 +++++++++ keyboards/gmmk/pro/ansi/keymaps/jonavin/readme.md | 1 + keyboards/gmmk/pro/ansi/keymaps/jonavin/rules.mk | 2 +- .../keebio/quefrency/keymaps/jonavin/keymap.c | 55 +++++-------- .../mechwild/mercutio/keymaps/jonavin/keymap.c | 75 ++++++++---------- .../mechwild/murphpad/keymaps/jonavin/keymap.c | 89 +++++++++------------- 6 files changed, 126 insertions(+), 133 deletions(-) (limited to 'keyboards') diff --git a/keyboards/gmmk/pro/ansi/keymaps/jonavin/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/jonavin/keymap.c index 20a786feb7..f37abfac30 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/jonavin/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/jonavin/keymap.c @@ -78,6 +78,43 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #endif // COLEMAK_LAYER_ENABLE }; +#if defined(ENCODER_ENABLE) && !defined(ENCODER_DEFAULTACTIONS_ENABLE) // Encoder Functionality when not using userspace defaults + void encoder_action_rgbhue(bool clockwise) { + if (clockwise) + rgblight_increase_hue_noeeprom(); + else + rgblight_decrease_hue_noeeprom(); + } + + bool encoder_update_user(uint8_t index, bool clockwise) { + uint8_t mods_state = get_mods(); + if (mods_state & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers + encoder_action_layerchange(clockwise); + } else if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, Page up/dn + unregister_mods(MOD_BIT(KC_RSFT)); + encoder_action_navpage(clockwise); + register_mods(MOD_BIT(KC_RSFT)); + } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word + encoder_action_navword(clockwise); + } else if (mods_state & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, change rgb hue/colour + encoder_action_rgbhue(clockwise); + } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track + encoder_action_mediatrack(clockwise); + } else { + switch(get_highest_layer(layer_state)) { + case _FN1: + #ifdef IDLE_TIMEOUT_ENABLE + timeout_update_threshold(clockwise); + #endif + break; + default: + encoder_action_volume(clockwise); // Otherwise it just changes volume + break; + } + } + return true; + } +#endif // ENCODER_ENABLE && !ENCODER_DEFAULTACTIONS_ENABLE #ifdef RGB_MATRIX_ENABLE // Capslock, Scroll lock and Numlock indicator on Left side lights. diff --git a/keyboards/gmmk/pro/ansi/keymaps/jonavin/readme.md b/keyboards/gmmk/pro/ansi/keymaps/jonavin/readme.md index a6482baa56..2aa910e0c7 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/jonavin/readme.md +++ b/keyboards/gmmk/pro/ansi/keymaps/jonavin/readme.md @@ -12,6 +12,7 @@ - holding Left shift, change layers - holding right shift, Navigate page up/down - holding Left Ctrl, navigate prev/next word + - holding Right Ctrl, changes RGB hue/colour - holding Left Alt, change media prev/next track - default is change volume diff --git a/keyboards/gmmk/pro/ansi/keymaps/jonavin/rules.mk b/keyboards/gmmk/pro/ansi/keymaps/jonavin/rules.mk index b06ae1b6ad..81b84eea7f 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/jonavin/rules.mk +++ b/keyboards/gmmk/pro/ansi/keymaps/jonavin/rules.mk @@ -6,6 +6,6 @@ BOOTMAGIC_ENABLE = lite # Enable Bootmagic Lite TD_LSFT_CAPSLOCK_ENABLE = yes IDLE_TIMEOUT_ENABLE = yes STARTUP_NUMLOCK_ON = yes -ENCODER_DEFAULTACTIONS_ENABLE = yes +ENCODER_DEFAULTACTIONS_ENABLE = no COLEMAK_LAYER_ENABLE = yes #Enable Colemak layer / set to no to disable diff --git a/keyboards/keebio/quefrency/keymaps/jonavin/keymap.c b/keyboards/keebio/quefrency/keymaps/jonavin/keymap.c index 721148f4dc..415f554e26 100644 --- a/keyboards/keebio/quefrency/keymaps/jonavin/keymap.c +++ b/keyboards/keebio/quefrency/keymaps/jonavin/keymap.c @@ -57,46 +57,31 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { }; #ifdef ENCODER_ENABLE // Encoder Functionality -bool encoder_update_user(uint8_t index, bool clockwise) { - switch (index) - { - case 0: // first encoder (Left Macro set) - if (clockwise) { - tap_code(KC_PGDN); - } else { - tap_code(KC_PGUP); - } + bool encoder_update_user(uint8_t index, bool clockwise) { + uint8_t mods_state = get_mods(); + switch (index) { + case 0: // first encoder (Left Macro set) + encoder_action_navpage(clockwise); + break; - default: // other encoder (Top right) - if ( clockwise ) { - if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, Page up - unregister_mods(MOD_BIT(KC_LSFT)); - register_code(KC_PGDN); - register_mods(MOD_BIT(KC_LSFT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next word - tap_code16(LCTL(KC_RGHT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next track - tap_code(KC_MEDIA_NEXT_TRACK); + default: // other encoder (Top right) + if (mods_state & MOD_BIT(KC_LSFT) ) { // If you are holding Left shift, change layers + encoder_action_layerchange(clockwise); + } else if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding Right shift, Page up + unregister_mods(MOD_BIT(KC_RSFT)); + encoder_action_navpage(clockwise); + register_mods(MOD_BIT(KC_RSFT)); + } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word + encoder_action_navword(clockwise); + } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track + encoder_action_mediatrack(clockwise); } else { - tap_code(KC_VOLU); // Otherwise it just changes volume - } - } else { - if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { - unregister_mods(MOD_BIT(KC_LSFT)); - register_code(KC_PGUP); - register_mods(MOD_BIT(KC_LSFT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate previous word - tap_code16(LCTL(KC_LEFT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media previous track - tap_code(KC_MEDIA_PREV_TRACK); - } else { - tap_code(KC_VOLD); + encoder_action_volume(clockwise); // Otherwise it just changes volume } + break; } - break; + return true; } - return true; -} #endif #ifdef RGBLIGHT_ENABLE diff --git a/keyboards/mechwild/mercutio/keymaps/jonavin/keymap.c b/keyboards/mechwild/mercutio/keymaps/jonavin/keymap.c index 74811cbc35..22d26db3c2 100755 --- a/keyboards/mechwild/mercutio/keymaps/jonavin/keymap.c +++ b/keyboards/mechwild/mercutio/keymaps/jonavin/keymap.c @@ -106,63 +106,48 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { #ifdef ENCODER_ENABLE // Encoder Functionality - uint8_t selected_layer = 0; + void encoder_action_selectkey(bool clockwise) { + if ( clockwise ) { + if ( selectedkey_idx < MAX_KEYSELECTION-1) { + selectedkey_idx ++; + } else { + // do nothing + } + } else if ( !clockwise ) { + if ( selectedkey_idx > 0){ + selectedkey_idx --; + } else { + // do nothing + } + } + set_selectedkey(selectedkey_idx); + } bool encoder_update_user(uint8_t index, bool clockwise) { #ifdef OLED_ENABLE oled_clear(); oled_render(); #endif + uint8_t mods_state = get_mods(); switch (index) { case 0: // This is the only encoder right now, keeping for consistency switch(get_highest_layer(layer_state)){ // special handling per layer case _FN1: // on Fn layer select what the encoder does when pressed - if (!keyboard_report->mods) { - if ( clockwise ) { - if ( selectedkey_idx < MAX_KEYSELECTION-1) { - selectedkey_idx ++; - } else { - // do nothing - } - } else if ( !clockwise ) { - if ( selectedkey_idx > 0){ - selectedkey_idx --; - } else { - // do nothing - } - } - set_selectedkey(selectedkey_idx); + if (!mods_state) { + encoder_action_selectkey(clockwise); break; } else { // continue to default } default: // all other layers - if ( clockwise ) { - if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers - if(selected_layer < 3) { - selected_layer ++; - layer_move(selected_layer); - } - } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next word - tap_code16(LCTL(KC_RGHT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next track - tap_code(KC_MEDIA_NEXT_TRACK); - } else { - tap_code(KC_VOLU); // Otherwise it just changes volume - } - } else if ( !clockwise ) { - if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { - if (selected_layer > 0) { - selected_layer --; - layer_move(selected_layer); - } - } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate previous word - tap_code16(LCTL(KC_LEFT)); - } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media previous track - tap_code(KC_MEDIA_PREV_TRACK); - } else { - tap_code(KC_VOLD); - } + if (mods_state & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers + encoder_action_layerchange(clockwise); + } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word + encoder_action_navword(clockwise); + } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track + encoder_action_mediatrack(clockwise); + } else { + encoder_action_volume(clockwise); // Otherwise it just changes volume } break; } @@ -205,7 +190,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { void oled_task_user(void) { - if ( IS_HOST_LED_OFF(USB_LED_NUM_LOCK) && IS_HOST_LED_OFF(USB_LED_CAPS_LOCK) && selected_layer == 0 && get_highest_layer(layer_state) == 0 ) { + if ( IS_HOST_LED_OFF(USB_LED_NUM_LOCK) && IS_HOST_LED_OFF(USB_LED_CAPS_LOCK) && get_selected_layer() == 0 && get_highest_layer(layer_state) == 0 ) { render_name(); clear_screen = true; } else { @@ -217,7 +202,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { render_logo(); oled_set_cursor(8,2); char fn_str[12]; - switch(selected_layer){ + switch(get_selected_layer()){ case 0: oled_write_P(PSTR("BASE"), false); break; @@ -237,7 +222,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { } oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false); oled_set_cursor(8,3); - if (get_highest_layer(layer_state) == selected_layer) { + if (get_highest_layer(layer_state) == get_selected_layer()) { oled_write_P(PSTR(" "), false); } else { switch (get_highest_layer(layer_state)) { diff --git a/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c b/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c index 001abc5027..39e6ac87e4 100644 --- a/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c +++ b/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c @@ -144,67 +144,52 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { #ifdef ENCODER_ENABLE // Encoder Functionality - uint8_t selected_layer = 0; + void encoder_action_selectkey(bool clockwise) { + if ( clockwise ) { + if ( selectedkey_idx < MAX_KEYSELECTION-1) { + selectedkey_idx ++; + } else { + // do nothing + } + } else if ( !clockwise ) { + if ( selectedkey_idx > 0){ + selectedkey_idx --; + } else { + // do nothing + } + } + set_selectedkey(selectedkey_idx); + } bool encoder_update_user(uint8_t index, bool clockwise) { #ifdef OLED_ENABLE oled_clear(); oled_render(); #endif + uint8_t mods_state = get_mods(); switch (index) { case 0: // This is the only encoder right now, keeping for consistency - switch(get_highest_layer(layer_state)){ // special handling per layer - case _FN1: // on Fn layer select what the encoder does when pressed - if (!keyboard_report->mods) { - if ( clockwise ) { - if ( selectedkey_idx < MAX_KEYSELECTION-1) { - selectedkey_idx ++; - } else { - // do nothing - } - } else if ( !clockwise ) { - if ( selectedkey_idx > 0){ - selectedkey_idx --; - } else { - // do nothing - } - } - set_selectedkey(selectedkey_idx); - break; - } else { - // continue to default - } - default: // all other layers - if ( clockwise ) { - if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { // If you are holding Right Shift, encoder changes layers - if(selected_layer < (DYNAMIC_KEYMAP_LAYER_COUNT-1)) { - selected_layer ++; - layer_move(selected_layer); - } - } else if (keyboard_report->mods & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate next word - tap_code16(LCTL(KC_RGHT)); - } else if (keyboard_report->mods & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media next track - tap_code(KC_MEDIA_NEXT_TRACK); - } else { - tap_code(KC_VOLU); // Otherwise it just changes volume - } - } else if ( !clockwise ) { - if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { - if (selected_layer > 0) { - selected_layer --; - layer_move(selected_layer); - } - } else if (keyboard_report->mods & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate previous word - tap_code16(LCTL(KC_LEFT)); - } else if (keyboard_report->mods & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media previous track - tap_code(KC_MEDIA_PREV_TRACK); - } else { - tap_code(KC_VOLD); - } - } + switch(get_highest_layer(layer_state)){ // special handling per layer + case _FN1: // on Fn layer select what the encoder does when pressed + if (!mods_state) { + encoder_action_selectkey(clockwise); break; + } else { + // continue to default + } + default: // all other layers + if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, encoder changes layers + encoder_action_layerchange(clockwise); + } else if (mods_state & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate next/prev word + encoder_action_navword(clockwise); + } else if (mods_state & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media next/prev track + encoder_action_mediatrack(clockwise); + } else { + encoder_action_volume(clockwise); // Otherwise it just changes volume } break; + } + break; } return true; } @@ -232,7 +217,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { render_logo(); oled_set_cursor(8,2); - switch(selected_layer){ + switch(get_selected_layer()){ case _BASE: oled_write_P(PSTR("BASE"), false); break; @@ -257,7 +242,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { } oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false); oled_set_cursor(8,3); - if (get_highest_layer(layer_state) == selected_layer) { + if (get_highest_layer(layer_state) == get_selected_layer()) { oled_write_P(PSTR(" "), false); } else { switch (get_highest_layer(layer_state)) { -- cgit v1.2.3