123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- #include QMK_KEYBOARD_H
- #include "gourdo1.h"
- #ifdef ENCODER_ENABLE
- #ifndef DYNAMIC_KEYMAP_LAYER_COUNT
- #define DYNAMIC_KEYMAP_LAYER_COUNT 4
- #endif
- #ifndef ENCODER_DEFAULTACTIONS_INDEX
- #define ENCODER_DEFAULTACTIONS_INDEX 0
- #endif
- static uint16_t key_timer;
- void encoder_action_volume(bool clockwise) {
- if (clockwise) {
- tap_code(KC_VOLU);
- if (timer_elapsed(key_timer) < 50) {
- tap_code(KC_VOLU);
- key_timer = timer_read();
- } else {
- key_timer = timer_read();
-
- }
- }
- else {
- tap_code(KC_VOLD);
- if (timer_elapsed(key_timer) < 100) {
- tap_code(KC_VOLD);
- tap_code(KC_VOLD);
- key_timer = timer_read();
- } else {
- key_timer = timer_read();
-
- }
- }
- }
-
- 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);
- }
-
- 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
- #ifdef ALTTAB_SCROLL_ENABLE
- bool is_tab_scrolling = false;
- bool is_alt_tab_active = false;
- uint16_t alt_tab_timer = 0;
- void encoder_toggle_alttabscroll(void) {
- is_tab_scrolling = !is_tab_scrolling;
- }
- void encoder_action_alttabscroll(bool clockwise) {
- if (clockwise) {
- if (!is_alt_tab_active) {
- is_alt_tab_active = true;
- register_mods(MOD_RALT);
- }
- tap_code16(KC_TAB);
- }
- else {
- tap_code16(S(KC_TAB));
- }
- alt_tab_timer = timer_read();
- }
- void encoder_tick_alttabscroll(void) {
- if (is_alt_tab_active) {
- if (timer_elapsed(alt_tab_timer) > 600) {
- unregister_mods(MOD_RALT);
- is_alt_tab_active = false;
- }
- }
- }
- #endif
- #endif
- #if defined(ENCODER_ENABLE) && defined(ENCODER_DEFAULTACTIONS_ENABLE)
- __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;}
- uint8_t mods_state = get_mods();
- if (mods_state & MOD_BIT(KC_LSFT) ) {
- encoder_action_layerchange(clockwise);
- } else if (mods_state & MOD_BIT(KC_RSFT) ) {
- unregister_mods(MOD_BIT(KC_RSFT));
- encoder_action_navpage(clockwise);
- register_mods(MOD_BIT(KC_RSFT));
- } else if (mods_state & MOD_BIT(KC_LCTL)) {
- encoder_action_navword(clockwise);
- } else if (mods_state & MOD_BIT(KC_LALT)) {
- encoder_action_mediatrack(clockwise);
- } else {
- switch(get_highest_layer(layer_state)) {
- case _FN1:
- #ifdef IDLE_TIMEOUT_ENABLE
- timeout_update_threshold(clockwise);
- #endif
- break;
- default:
- #ifdef ALTTAB_SCROLL_ENABLE
- if (is_tab_scrolling)
- encoder_action_alttabscroll(clockwise);
- else
- encoder_action_volume(clockwise);
- #else
- encoder_action_volume(clockwise);
- #endif
- break;
- }
- }
- return false;
- }
- #endif
|