2021-12-30 05:17:34 +01:00
|
|
|
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-10-17 20:46:57 +02:00
|
|
|
|
2018-12-04 22:27:41 +01:00
|
|
|
#include "drashna.h"
|
2021-01-22 17:23:03 +01:00
|
|
|
#include "version.h"
|
2018-12-04 22:27:41 +01:00
|
|
|
|
|
|
|
uint16_t copy_paste_timer;
|
2021-10-16 07:30:23 +02:00
|
|
|
bool host_driver_disabled = false;
|
2018-12-04 22:27:41 +01:00
|
|
|
// Defines actions tor my global custom keycodes. Defined in drashna.h file
|
|
|
|
// Then runs the _keymap's record handier if not processed here
|
2021-08-21 22:34:44 +02:00
|
|
|
|
2022-01-22 04:36:52 +01:00
|
|
|
/**
|
|
|
|
* @brief Keycode handler for keymaps
|
|
|
|
*
|
|
|
|
* This handles the keycodes at the keymap level, useful for keyboard specific customization
|
|
|
|
*/
|
2022-07-03 04:55:46 +02:00
|
|
|
__attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
__attribute__((weak)) bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-01-22 04:36:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Main user keycode handler
|
|
|
|
*
|
|
|
|
* This handles all of the keycodes for the user, including calling feature handlers.
|
|
|
|
*
|
|
|
|
* @param keycode Keycode from matrix
|
|
|
|
* @param record keyrecord_t data structure
|
|
|
|
* @return true Continue processing keycode and send to host
|
|
|
|
* @return false Stop process keycode and do not send to host
|
|
|
|
*/
|
2022-01-30 22:20:33 +01:00
|
|
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
2022-05-31 07:02:55 +02:00
|
|
|
#ifdef ENCODER_ENABLE // some debouncing for weird issues
|
|
|
|
if (IS_ENCODEREVENT(record->event)) {
|
|
|
|
static bool ignore_first = true;
|
|
|
|
if (ignore_first) {
|
|
|
|
ignore_first = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-23 05:22:33 +02:00
|
|
|
// If console is enabled, it will print the matrix position and status of each key pressed
|
2018-12-04 22:27:41 +01:00
|
|
|
#ifdef KEYLOGGER_ENABLE
|
2022-08-28 21:55:19 +02:00
|
|
|
uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %1d, time: %5u, int: %1d, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count);
|
2022-07-03 04:55:46 +02:00
|
|
|
#endif // KEYLOGGER_ENABLE
|
2022-03-07 07:12:17 +01:00
|
|
|
#if defined(OLED_ENABLE) && defined(CUSTOM_OLED_DRIVER)
|
2020-04-01 01:26:43 +02:00
|
|
|
process_record_user_oled(keycode, record);
|
2022-07-03 04:55:46 +02:00
|
|
|
#endif // OLED
|
2018-12-04 22:27:41 +01:00
|
|
|
|
2020-10-17 20:46:57 +02:00
|
|
|
if (!(process_record_keymap(keycode, record) && process_record_secrets(keycode, record)
|
2022-03-07 07:12:17 +01:00
|
|
|
#ifdef CUSTOM_RGB_MATRIX
|
2021-02-23 19:57:24 +01:00
|
|
|
&& process_record_user_rgb_matrix(keycode, record)
|
2020-04-01 01:26:43 +02:00
|
|
|
#endif
|
2022-03-07 07:12:17 +01:00
|
|
|
#ifdef CUSTOM_RGBLIGHT
|
2021-02-23 19:57:24 +01:00
|
|
|
&& process_record_user_rgb_light(keycode, record)
|
2021-11-29 08:41:59 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CUSTOM_UNICODE_ENABLE
|
|
|
|
&& process_record_unicode(keycode, record)
|
2021-12-15 05:53:36 +01:00
|
|
|
#endif
|
2022-03-07 07:12:17 +01:00
|
|
|
#if defined(CUSTOM_POINTING_DEVICE)
|
2021-12-15 05:53:36 +01:00
|
|
|
&& process_record_pointing(keycode, record)
|
2020-04-01 01:26:43 +02:00
|
|
|
#endif
|
2021-02-23 19:57:24 +01:00
|
|
|
&& true)) {
|
2020-10-17 20:46:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (keycode) {
|
2021-07-27 02:59:49 +02:00
|
|
|
case FIRST_DEFAULT_LAYER_KEYCODE ... LAST_DEFAULT_LAYER_KEYCODE:
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
|
|
|
uint8_t mods = mod_config(get_mods() | get_oneshot_mods());
|
|
|
|
if (!mods) {
|
2021-07-27 02:59:49 +02:00
|
|
|
set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE);
|
|
|
|
#if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 3)
|
2020-10-17 20:46:57 +02:00
|
|
|
} else if (mods & MOD_MASK_SHIFT) {
|
2021-07-27 02:59:49 +02:00
|
|
|
set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 4);
|
|
|
|
# if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 7)
|
|
|
|
|
2020-10-17 20:46:57 +02:00
|
|
|
} else if (mods & MOD_MASK_CTRL) {
|
2021-07-27 02:59:49 +02:00
|
|
|
set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 8);
|
|
|
|
# endif
|
|
|
|
#endif
|
2019-09-07 17:57:30 +02:00
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-12-04 22:27:41 +01:00
|
|
|
|
2022-07-03 04:55:46 +02:00
|
|
|
case VRSN: // Prints firmware version
|
2021-07-27 02:59:49 +02:00
|
|
|
if (record->event.pressed) {
|
|
|
|
send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), TAP_CODE_DELAY);
|
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
break;
|
2018-12-04 22:27:41 +01:00
|
|
|
|
2022-07-03 04:55:46 +02:00
|
|
|
case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them
|
2018-12-04 22:27:41 +01:00
|
|
|
#ifdef TAP_DANCE_ENABLE
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
2021-07-27 02:59:49 +02:00
|
|
|
for (uint8_t index = 0; index < 4; index++) {
|
|
|
|
diablo_timer[index].key_interval = 0;
|
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
2022-07-03 04:55:46 +02:00
|
|
|
#endif // TAP_DANCE_ENABLE
|
2020-10-17 20:46:57 +02:00
|
|
|
break;
|
2018-12-04 22:27:41 +01:00
|
|
|
|
2022-07-03 04:55:46 +02:00
|
|
|
case KC_CCCV: // One key copy/paste
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
|
|
|
copy_paste_timer = timer_read();
|
|
|
|
} else {
|
2022-07-03 04:55:46 +02:00
|
|
|
if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy
|
2020-10-17 20:46:57 +02:00
|
|
|
tap_code16(LCTL(KC_C));
|
2022-07-03 04:55:46 +02:00
|
|
|
} else { // Tap, paste
|
2020-10-17 20:46:57 +02:00
|
|
|
tap_code16(LCTL(KC_V));
|
2019-07-23 05:22:33 +02:00
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-07-03 04:55:46 +02:00
|
|
|
case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal
|
2022-03-07 07:12:17 +01:00
|
|
|
#if defined(CUSTOM_RGBLIGHT) || defined(CUSTOM_RGB_MATRIX)
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
|
|
|
userspace_config.rgb_layer_change ^= 1;
|
|
|
|
dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
|
|
|
|
eeconfig_update_user(userspace_config.raw);
|
|
|
|
if (userspace_config.rgb_layer_change) {
|
2022-05-31 07:02:55 +02:00
|
|
|
# if defined(CUSTOM_RGB_MATRIX)
|
|
|
|
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW | LED_FLAG_KEYLIGHT | LED_FLAG_INDICATOR);
|
|
|
|
# if defined(CUSTOM_RGBLIGHT)
|
2020-10-17 20:46:57 +02:00
|
|
|
rgblight_enable_noeeprom();
|
2022-05-31 07:02:55 +02:00
|
|
|
# endif
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
2022-05-31 07:02:55 +02:00
|
|
|
layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
|
|
|
|
# if defined(CUSTOM_RGB_MATRIX)
|
2020-10-17 20:46:57 +02:00
|
|
|
} else {
|
2022-05-31 07:02:55 +02:00
|
|
|
rgb_matrix_set_flags(LED_FLAG_ALL);
|
|
|
|
# if defined(CUSTOM_RGBLIGHT)
|
2020-10-17 20:46:57 +02:00
|
|
|
rgblight_disable_noeeprom();
|
2022-05-31 07:02:55 +02:00
|
|
|
# endif
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
2022-07-03 04:55:46 +02:00
|
|
|
#endif // CUSTOM_RGBLIGHT
|
2020-10-17 20:46:57 +02:00
|
|
|
break;
|
2020-04-01 01:26:43 +02:00
|
|
|
|
2022-03-07 07:12:17 +01:00
|
|
|
#if defined(CUSTOM_RGBLIGHT) || defined(CUSTOM_RGB_MATRIX)
|
2020-10-17 20:46:57 +02:00
|
|
|
case RGB_TOG:
|
|
|
|
// Split keyboards need to trigger on key-up for edge-case issue
|
2020-04-01 01:26:43 +02:00
|
|
|
# ifndef SPLIT_KEYBOARD
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
2020-04-01 01:26:43 +02:00
|
|
|
# else
|
2020-10-17 20:46:57 +02:00
|
|
|
if (!record->event.pressed) {
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
2022-03-07 07:12:17 +01:00
|
|
|
# if defined(CUSTOM_RGBLIGHT) && !defined(RGBLIGHT_DISABLE_KEYCODES)
|
2020-10-17 20:46:57 +02:00
|
|
|
rgblight_toggle();
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
2022-03-07 07:12:17 +01:00
|
|
|
# if defined(CUSTOM_RGB_MATRIX) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
|
2020-10-17 20:46:57 +02:00
|
|
|
rgb_matrix_toggle();
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
break;
|
2022-07-03 04:55:46 +02:00
|
|
|
case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
|
2020-10-17 20:46:57 +02:00
|
|
|
if (record->event.pressed) {
|
|
|
|
bool is_eeprom_updated;
|
2022-03-07 07:12:17 +01:00
|
|
|
# if defined(CUSTOM_RGBLIGHT) && !defined(RGBLIGHT_DISABLE_KEYCODES)
|
2020-10-17 20:46:57 +02:00
|
|
|
// This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
|
|
|
|
if (userspace_config.rgb_layer_change) {
|
|
|
|
userspace_config.rgb_layer_change = false;
|
|
|
|
dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
|
|
|
|
is_eeprom_updated = true;
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
# endif
|
2022-03-07 07:12:17 +01:00
|
|
|
# if defined(CUSTOM_RGB_MATRIX) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2020-10-17 20:46:57 +02:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim) {
|
|
|
|
userspace_config.rgb_matrix_idle_anim = false;
|
|
|
|
dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
|
|
|
|
is_eeprom_updated = true;
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
|
|
|
# endif
|
2021-07-27 02:59:49 +02:00
|
|
|
if (is_eeprom_updated) {
|
|
|
|
eeconfig_update_user(userspace_config.raw);
|
|
|
|
}
|
2020-10-17 20:46:57 +02:00
|
|
|
}
|
2021-10-16 07:30:23 +02:00
|
|
|
break;
|
2021-11-17 21:45:50 +01:00
|
|
|
#endif
|
2021-10-16 07:30:23 +02:00
|
|
|
case KEYLOCK: {
|
|
|
|
static host_driver_t *host_driver = 0;
|
|
|
|
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (host_get_driver()) {
|
|
|
|
host_driver = host_get_driver();
|
|
|
|
clear_keyboard();
|
|
|
|
host_set_driver(0);
|
|
|
|
host_driver_disabled = true;
|
|
|
|
} else {
|
|
|
|
host_set_driver(host_driver);
|
|
|
|
host_driver_disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-12-15 05:53:36 +01:00
|
|
|
}
|
2022-07-03 04:55:46 +02:00
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
return true;
|
2018-12-04 22:27:41 +01:00
|
|
|
}
|
2021-08-21 22:34:44 +02:00
|
|
|
|
|
|
|
__attribute__((weak)) void post_process_record_keymap(uint16_t keycode, keyrecord_t *record) {}
|
2022-07-03 04:55:46 +02:00
|
|
|
void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
post_process_record_keymap(keycode, record);
|
|
|
|
}
|