#include QMK_KEYBOARD_H
#include "keycodes.h"
#include "leds.h"
bool is_alt_tab_active = false;
uint16_t alt_tab_timer = 0;
bool is_screen_lock_triggered = false;
uint16_t screen_lock_timer = 0;
enum custom_keycodes {
ALT_TAB = SAFE_RANGE,
KC_00 ,
SLC_ROW,
SLC_ALL,
SLC_WRD
};
enum combo_events {
SCR_LCK
};
const uint16_t PROGMEM lock_combo[] = {KC_J, KC_K, KC_L, KC_SCLN, COMBO_END};
combo_t key_combos[COMBO_COUNT] = {COMBO(lock_combo, SCR_LCK)};
#define _QW 0
#define _FN 1
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QW] = LAYOUT_ortho_5x15(
KC_GESC, KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_DEL , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINUS, KC_EQUAL, KC_PSCR,
KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_BSPC, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC , KC_RBRC , KC_HOME,
MO(_FN), KC_A , KC_S , KC_D , KC_F , KC_G , KC_ENT , KC_H , KC_J , KC_K , KC_L , KC_SCLN , KC_QUOT , KC_NUHS , KC_END ,
KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , ALT_TAB, KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH , KC_RSFT , MO(_FN) , KC_PGUP,
KC_LCTL, KC_LGUI, KC_LALT, KC_WBAK, KC_WFWD, KC_SPC, KC_APP , KC_SPC, KC_LEFT, KC_UP , KC_DOWN, KC_RIGHT, KC_RALT , KC_RCTL , KC_PGDN
),
[_FN] = LAYOUT_ortho_5x15(
LALT(KC_F4), KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , BL_TOGG, KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , KC_NLCK,
_______ , _______, SLC_ALL , SLC_ROW , SLC_WRD , KC_BRIU, BL_STEP, _______, _______, LSFT(KC_7) , LSFT(KC_8) , LSFT(KC_9), KC_8 , _______, _______,
_______ , _______, LSFT(KC_DEL), LCTL(KC_INS), LSFT(KC_INS), KC_BRID, BL_BRTG, _______, _______, LSFT(KC_4) , LSFT(KC_5) , LSFT(KC_6), KC_7 , _______, RESET ,
_______ , _______, KC_MUTE , KC_VOLD , KC_VOLU , KC_MPLY, RGB_TOG, _______, _______, LSFT(KC_1) , LSFT(KC_2) , LSFT(KC_3), KC_ENT , _______, _______,
_______ , _______, _______ , _______ , _______ , _______, RGB_MOD, _______, _______, LSFT(KC_0) , KC_00 , KC_V , _______ , _______, _______
)
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) { case ALT_TAB:
if (record->event.pressed) {
if (!is_alt_tab_active) {
is_alt_tab_active = true;
gp100_led_on();
register_code(KC_LALT);
}
alt_tab_timer = timer_read();
register_code(KC_TAB);
} else {
unregister_code(KC_TAB);
}
break;
case KC_00:
insert_00(record);
break;
case SLC_ALL:
select_all(record);
break;
case SLC_ROW:
select_row(record);
break;
case SLC_WRD:
select_word(record);
break;
}
return true;
}
void process_combo_event(uint16_t combo_index, bool pressed) {
switch(combo_index) {
case SCR_LCK:
if (pressed) {
is_screen_lock_triggered = true;
gp103_led_on();
windows_lock();
screen_lock_timer = timer_read();
}
break;
}
}
void matrix_scan_user(void) { if (is_alt_tab_active) {
if (timer_elapsed(alt_tab_timer) > 750) {
unregister_code(KC_LALT);
gp100_led_off();
is_alt_tab_active = false;
}
}
if (is_screen_lock_triggered) {
if (timer_elapsed(screen_lock_timer) > 750) {
gp103_led_off();
is_screen_lock_triggered = false;
}
}
}
void led_set_user(uint8_t usb_led) {
if (IS_LAYER_ON(_FN)) {
capslock_led_on();
} else {
capslock_led_off();
}
}
void keyboard_post_init_user (void) {
setDefaultDisplay();
}
layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state)) {
case _FN:
setFNDisplay();
break;
default: setDefaultDisplay();
break;
}
return state;
}