From 5334e087ef848d54266537ecdc0b87cac976517e Mon Sep 17 00:00:00 2001 From: jonavin <71780717+Jonavin@users.noreply.github.com> Date: Sat, 30 Oct 2021 14:53:58 -0400 Subject: [Keymap] Jonavin userspace encoder alt tab scrolling (#14979) Co-authored-by: Jonavin <=> --- users/jonavin/jonavin.c | 177 +++++------------------------------------------- 1 file changed, 17 insertions(+), 160 deletions(-) (limited to 'users/jonavin/jonavin.c') diff --git a/users/jonavin/jonavin.c b/users/jonavin/jonavin.c index 367601dfba..b66b444f36 100644 --- a/users/jonavin/jonavin.c +++ b/users/jonavin/jonavin.c @@ -95,171 +95,21 @@ along with this program. If not, see . } // timeout_threshold = 0 will disable timeout } +#endif // IDLE_TIMEOUT_ENABLE + +#if defined(ALTTAB_SCROLL_ENABLE) || defined(IDLE_TIMEOUT_ENABLE) // timer features __attribute__((weak)) void matrix_scan_keymap(void) {} void matrix_scan_user(void) { - timeout_tick_timer(); + #ifdef ALTTAB_SCROLL_ENABLE + encoder_tick_alttabscroll(); + #endif + #ifdef IDLE_TIMEOUT_ENABLE + timeout_tick_timer(); + #endif matrix_scan_keymap(); } -#endif // IDLE_TIMEOUT_ENABLE - - -#ifdef ENCODER_ENABLE - #ifndef DYNAMIC_KEYMAP_LAYER_COUNT - #define DYNAMIC_KEYMAP_LAYER_COUNT 4 //default in case this is not already defined elsewhere - #endif - #ifndef ENCODER_DEFAULTACTIONS_INDEX - #define ENCODER_DEFAULTACTIONS_INDEX 0 // can select encoder index if there are multiple encoders - #endif - - void encoder_action_volume(bool clockwise) { - if (clockwise) - tap_code(KC_VOLU); - else - tap_code(KC_VOLD); - } - - void encoder_action_mediatrack(bool clockwise) { - if (clockwise) - tap_code(KC_MEDIA_NEXT_TRACK); - else - tap_code(KC_MEDIA_PREV_TRACK); - } - - void encoder_action_navword(bool clockwise) { - if (clockwise) - tap_code16(LCTL(KC_RGHT)); - else - tap_code16(LCTL(KC_LEFT)); - } - - void encoder_action_navpage(bool clockwise) { - if (clockwise) - tap_code16(KC_PGUP); - else - tap_code16(KC_PGDN); - } - - // LAYER HANDLING - uint8_t selected_layer = 0; - - uint8_t get_selected_layer(void) { - return selected_layer; - } - - void encoder_action_layerchange(bool clockwise) { - if (clockwise) { - if(selected_layer < (DYNAMIC_KEYMAP_LAYER_COUNT - 1)) { - selected_layer ++; - layer_move(selected_layer); - } - } else { - if (selected_layer > 0) { - selected_layer --; - layer_move(selected_layer); - } - } - } - - #ifdef RGB_MATRIX_ENABLE - void encoder_action_rgb_speed(bool clockwise) { - if (clockwise) - rgb_matrix_increase_speed_noeeprom(); - else - rgb_matrix_decrease_speed_noeeprom(); - } - void encoder_action_rgb_hue(bool clockwise) { - if (clockwise) - rgb_matrix_increase_hue_noeeprom(); - else - rgb_matrix_decrease_hue_noeeprom(); - } - void encoder_action_rgb_saturation(bool clockwise) { - if (clockwise) - rgb_matrix_increase_sat_noeeprom(); - else - rgb_matrix_decrease_sat_noeeprom(); - } - void encoder_action_rgb_brightness(bool clockwise) { - if (clockwise) - rgb_matrix_increase_val_noeeprom(); - else - rgb_matrix_decrease_val_noeeprom(); - } - void encoder_action_rgb_mode(bool clockwise) { - if (clockwise) - rgb_matrix_step_noeeprom(); - else - rgb_matrix_step_reverse_noeeprom(); - } - #elif defined(RGBLIGHT_ENABLE) - void encoder_action_rgb_speed(bool clockwise) { - if (clockwise) - rgblight_increase_speed_noeeprom(); - else - rgblight_decrease_speed_noeeprom(); - } - void encoder_action_rgb_hue(bool clockwise) { - if (clockwise) - rgblight_increase_hue_noeeprom(); - else - rgblight_decrease_hue_noeeprom(); - } - void encoder_action_rgb_saturation(bool clockwise) { - if (clockwise) - rgblight_increase_sat_noeeprom(); - else - rgblight_decrease_sat_noeeprom(); - } - void encoder_action_rgb_brightness(bool clockwise) { - if (clockwise) - rgblight_increase_val_noeeprom(); - else - rgblight_decrease_val_noeeprom(); - } - void encoder_action_rgb_mode(bool clockwise) { - if (clockwise) - rgblight_step_noeeprom(); - else - rgblight_step_reverse_noeeprom(); - } - #endif // RGB_MATRIX_ENABLE || RGBLIGHT_ENABLE -#endif // ENCODER_ENABLE - -#if defined(ENCODER_ENABLE) && defined(ENCODER_DEFAULTACTIONS_ENABLE) // Encoder Functionality - - __attribute__((weak)) bool encoder_update_keymap(uint8_t index, bool clockwise) { return true; } - - bool encoder_update_user(uint8_t index, bool clockwise) { - if (!encoder_update_keymap(index, clockwise)) { return false; } - if (index != ENCODER_DEFAULTACTIONS_INDEX) {return true;} // exit if the index doesn't match - 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_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 false; - } -#endif // ENCODER_ENABLE - +#endif // ALTTAB_SCROLL_ENABLE or IDLE_TIMEOUT_ENABLE // PROCESS KEY CODES __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } @@ -326,6 +176,13 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; #endif // EMOTICON_ENABLE + #ifdef ALTTAB_SCROLL_ENABLE + case KC_TSTOG: + if (record->event.pressed) encoder_toggle_alttabscroll(); + else unregister_code16(keycode); + break; + #endif // ALTTAB_SCROLL_ENABLE + default: if (record->event.pressed) { #ifdef RGB_MATRIX_ENABLE -- cgit v1.2.3