diff options
| author | jonavin <71780717+Jonavin@users.noreply.github.com> | 2021-09-28 15:24:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-28 12:24:12 -0700 |
| commit | 705cd433c22aad00b12183eaa3bada50d90fd97b (patch) | |
| tree | d529e7d14aca455a8ed494f00ebe4707dac40af6 /keyboards/mechwild/murphpad | |
| parent | 724ee240751fdfedf33d75fee10d2b97d9f9e3da (diff) | |
| download | qmk_firmware-705cd433c22aad00b12183eaa3bada50d90fd97b.tar.gz qmk_firmware-705cd433c22aad00b12183eaa3bada50d90fd97b.zip | |
[Keymap] fix NKRO - switch to get_mods() and refactor encoder action code (#14278)
Co-authored-by: Jonavin <=>
Diffstat (limited to 'keyboards/mechwild/murphpad')
| -rw-r--r-- | keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c | 89 |
1 files changed, 37 insertions, 52 deletions
diff --git a/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c b/keyboards/mechwild/murphpad/keymaps/jonavin/keymap.c index 001abc502..39e6ac87e 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) { | |||
| 144 | 144 | ||
| 145 | 145 | ||
| 146 | #ifdef ENCODER_ENABLE // Encoder Functionality | 146 | #ifdef ENCODER_ENABLE // Encoder Functionality |
| 147 | uint8_t selected_layer = 0; | 147 | void encoder_action_selectkey(bool clockwise) { |
| 148 | if ( clockwise ) { | ||
| 149 | if ( selectedkey_idx < MAX_KEYSELECTION-1) { | ||
| 150 | selectedkey_idx ++; | ||
| 151 | } else { | ||
| 152 | // do nothing | ||
| 153 | } | ||
| 154 | } else if ( !clockwise ) { | ||
| 155 | if ( selectedkey_idx > 0){ | ||
| 156 | selectedkey_idx --; | ||
| 157 | } else { | ||
| 158 | // do nothing | ||
| 159 | } | ||
| 160 | } | ||
| 161 | set_selectedkey(selectedkey_idx); | ||
| 162 | } | ||
| 148 | 163 | ||
| 149 | bool encoder_update_user(uint8_t index, bool clockwise) { | 164 | bool encoder_update_user(uint8_t index, bool clockwise) { |
| 150 | #ifdef OLED_ENABLE | 165 | #ifdef OLED_ENABLE |
| 151 | oled_clear(); | 166 | oled_clear(); |
| 152 | oled_render(); | 167 | oled_render(); |
| 153 | #endif | 168 | #endif |
| 169 | uint8_t mods_state = get_mods(); | ||
| 154 | switch (index) { | 170 | switch (index) { |
| 155 | case 0: // This is the only encoder right now, keeping for consistency | 171 | case 0: // This is the only encoder right now, keeping for consistency |
| 156 | switch(get_highest_layer(layer_state)){ // special handling per layer | 172 | switch(get_highest_layer(layer_state)){ // special handling per layer |
| 157 | case _FN1: // on Fn layer select what the encoder does when pressed | 173 | case _FN1: // on Fn layer select what the encoder does when pressed |
| 158 | if (!keyboard_report->mods) { | 174 | if (!mods_state) { |
| 159 | if ( clockwise ) { | 175 | encoder_action_selectkey(clockwise); |
| 160 | if ( selectedkey_idx < MAX_KEYSELECTION-1) { | ||
| 161 | selectedkey_idx ++; | ||
| 162 | } else { | ||
| 163 | // do nothing | ||
| 164 | } | ||
| 165 | } else if ( !clockwise ) { | ||
| 166 | if ( selectedkey_idx > 0){ | ||
| 167 | selectedkey_idx --; | ||
| 168 | } else { | ||
| 169 | // do nothing | ||
| 170 | } | ||
| 171 | } | ||
| 172 | set_selectedkey(selectedkey_idx); | ||
| 173 | break; | ||
| 174 | } else { | ||
| 175 | // continue to default | ||
| 176 | } | ||
| 177 | default: // all other layers | ||
| 178 | if ( clockwise ) { | ||
| 179 | if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { // If you are holding Right Shift, encoder changes layers | ||
| 180 | if(selected_layer < (DYNAMIC_KEYMAP_LAYER_COUNT-1)) { | ||
| 181 | selected_layer ++; | ||
| 182 | layer_move(selected_layer); | ||
| 183 | } | ||
| 184 | } else if (keyboard_report->mods & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate next word | ||
| 185 | tap_code16(LCTL(KC_RGHT)); | ||
| 186 | } else if (keyboard_report->mods & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media next track | ||
| 187 | tap_code(KC_MEDIA_NEXT_TRACK); | ||
| 188 | } else { | ||
| 189 | tap_code(KC_VOLU); // Otherwise it just changes volume | ||
| 190 | } | ||
| 191 | } else if ( !clockwise ) { | ||
| 192 | if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { | ||
| 193 | if (selected_layer > 0) { | ||
| 194 | selected_layer --; | ||
| 195 | layer_move(selected_layer); | ||
| 196 | } | ||
| 197 | } else if (keyboard_report->mods & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate previous word | ||
| 198 | tap_code16(LCTL(KC_LEFT)); | ||
| 199 | } else if (keyboard_report->mods & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media previous track | ||
| 200 | tap_code(KC_MEDIA_PREV_TRACK); | ||
| 201 | } else { | ||
| 202 | tap_code(KC_VOLD); | ||
| 203 | } | ||
| 204 | } | ||
| 205 | break; | 176 | break; |
| 177 | } else { | ||
| 178 | // continue to default | ||
| 179 | } | ||
| 180 | default: // all other layers | ||
| 181 | if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, encoder changes layers | ||
| 182 | encoder_action_layerchange(clockwise); | ||
| 183 | } else if (mods_state & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate next/prev word | ||
| 184 | encoder_action_navword(clockwise); | ||
| 185 | } else if (mods_state & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media next/prev track | ||
| 186 | encoder_action_mediatrack(clockwise); | ||
| 187 | } else { | ||
| 188 | encoder_action_volume(clockwise); // Otherwise it just changes volume | ||
| 206 | } | 189 | } |
| 207 | break; | 190 | break; |
| 191 | } | ||
| 192 | break; | ||
| 208 | } | 193 | } |
| 209 | return true; | 194 | return true; |
| 210 | } | 195 | } |
| @@ -232,7 +217,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { | |||
| 232 | 217 | ||
| 233 | render_logo(); | 218 | render_logo(); |
| 234 | oled_set_cursor(8,2); | 219 | oled_set_cursor(8,2); |
| 235 | switch(selected_layer){ | 220 | switch(get_selected_layer()){ |
| 236 | case _BASE: | 221 | case _BASE: |
| 237 | oled_write_P(PSTR("BASE"), false); | 222 | oled_write_P(PSTR("BASE"), false); |
| 238 | break; | 223 | break; |
| @@ -257,7 +242,7 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { | |||
| 257 | } | 242 | } |
| 258 | oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false); | 243 | oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false); |
| 259 | oled_set_cursor(8,3); | 244 | oled_set_cursor(8,3); |
| 260 | if (get_highest_layer(layer_state) == selected_layer) { | 245 | if (get_highest_layer(layer_state) == get_selected_layer()) { |
| 261 | oled_write_P(PSTR(" "), false); | 246 | oled_write_P(PSTR(" "), false); |
| 262 | } else { | 247 | } else { |
| 263 | switch (get_highest_layer(layer_state)) { | 248 | switch (get_highest_layer(layer_state)) { |
