From 35dbe8ba035c8eefc1051226aa8e3dd7cd63a912 Mon Sep 17 00:00:00 2001 From: Joel Elkins Date: Wed, 2 Jun 2021 15:59:52 -0500 Subject: [Keymap] merge jdelkins userspace and associated keymaps (#11276) * [Keymap] merge jdelkins userspace and associated keymaps * Add copyright & license info * Change rgblight_config.enable to rgblight_is_enabled() * Update keyboards/dz60/keymaps/jdelkins/keymap.c Co-authored-by: Drashna Jaelre * Update keyboards/dz60/keymaps/jdelkins/keymap.c Co-authored-by: Drashna Jaelre * Update keyboards/dz60/keymaps/jdelkins/keymap.c Co-authored-by: Drashna Jaelre * Remove superfluous includes * Change EXTRAFLAGS+=-flto to LTO_ENABLE=yes * Remove unnecessary jdelkins_ss symlink in users * Add copyright and license notices * Use preferred way to determine capslock / numlock state Co-authored-by: Drashna Jaelre * Add #pragma once to a header Co-authored-by: Drashna Jaelre * Include QMK_KEYBOARD_H only once, in userspace header * Remove unnecessary initialization in matrix_init_keymap * Do process_record_keymap before cases handled in process_record_user * Reorganize & simplify secrets feature enablement * Use tap_code16 Co-authored-by: Ryan * Remove superfluous break Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * include "print.h" instead of Co-authored-by: Ryan * Use tap_cod16 Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * add #pragma once to a header Co-authored-by: Ryan * include "print.h" instead of Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * Remove copyright from rules.mk Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * Use tap_code16 Co-authored-by: Ryan * Use :flash target where possible * Remove special case flash target and use PROGRAM_CMD * dz60/jdelkins_ss: use tap_code16 Co-authored-by: Drashna Jaelre Co-authored-by: Ryan --- users/jdelkins/jdelkins.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 users/jdelkins/jdelkins.c (limited to 'users/jdelkins/jdelkins.c') diff --git a/users/jdelkins/jdelkins.c b/users/jdelkins/jdelkins.c new file mode 100644 index 0000000000..7577512ec5 --- /dev/null +++ b/users/jdelkins/jdelkins.c @@ -0,0 +1,274 @@ +/* + Copyright 2020 Joel Elkins + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "jdelkins.h" +#include "version.h" + +#ifdef DO_SECRETS +# include "secrets.h" +#else +# ifndef NO_SECRETS +# pragma message("Warning: secrets.h not found") +# endif +#endif + +user_config_t user_config; + +__attribute__ ((weak)) +bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { + return true; +} + +void send_secret_string(uint8_t n) { +#ifdef DO_SECRETS + send_string(secret[n]); +#else + SEND_STRING(""); +#endif +} + +#ifdef TAP_DANCE_ENABLE + +// To activate SINGLE_HOLD, you will need to hold for 200ms first. +// This tap dance favors keys that are used frequently in typing like 'f' +int cur_dance(qk_tap_dance_state_t *state) { + if (state->count == 1) { + // If count = 1, and it has been interrupted - it doesn't matter if it + // is pressed or not: Send SINGLE_TAP + if (state->interrupted) { + // if (!state->pressed) return SINGLE_TAP; + // need "permissive hold" here. + // else return SINsGLE_HOLD; + // If the interrupting key is released before the tap-dance key, + // then it is a single HOLD However, if the tap-dance key is + // released first, then it is a single TAP But how to get access to + // the state of the interrupting key???? + return SINGLE_TAP; + } else { + if (!state->pressed) + return SINGLE_TAP; + else + return SINGLE_HOLD; + } + } + // If count = 2, and it has been interrupted - assume that user is trying to + // type the letter associated with single tap. + else if (state->count == 2) { + if (state->interrupted) + return DOUBLE_SINGLE_TAP; + else if (state->pressed) + return DOUBLE_HOLD; + else + return DOUBLE_TAP; + } else if ((state->count == 3) && ((state->interrupted) || (!state->pressed))) + return TRIPLE_TAP; + else if (state->count == 3) + return TRIPLE_HOLD; + else + return 8; // magic number. At some point this method will expand to work for more presses +} + +// This works well if you want this key to work as a "fast modifier". It favors +// being held over being tapped. +int hold_cur_dance(qk_tap_dance_state_t *state) { + if (state->count == 1) { + if (state->interrupted) { + if (!state->pressed) + return SINGLE_TAP; + else + return SINGLE_HOLD; + } else { + if (!state->pressed) + return SINGLE_TAP; + else + return SINGLE_HOLD; + } + } + // If count = 2, and it has been interrupted - assume that user is trying to + // type the letter associated with single tap. + else if (state->count == 2) { + if (state->pressed) + return DOUBLE_HOLD; + else + return DOUBLE_TAP; + } else if (state->count == 3) { + if (!state->pressed) + return TRIPLE_TAP; + else + return TRIPLE_HOLD; + } else + return 8; // magic number. At some point this method will expand to work for more presses +} + +#endif // TAP_DANCE_ENABLE + +__attribute__ ((weak)) +void keyboard_post_init_keymap(void) { +} + +void keyboard_post_init_user(void) { + user_config.raw = eeconfig_read_user(); + keyboard_post_init_keymap(); +} + +void eeconfig_init_user(void) { + user_config.raw = 0; + user_config.system_mac = false; + eeconfig_update_user(user_config.raw); +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t boot_timer; + + if (!process_record_keymap(keycode, record)) { + return false; + } + + switch (keycode) { + case FW_WRD: + do_mac_key(LCTL(KC_RIGHT), ROPT(KC_RIGHT), record); + break; + + case BK_WRD: + do_mac_key(LCTL(KC_LEFT), ROPT(KC_LEFT), record); + break; + + case KB_BOL: + do_mac_key(KC_HOME, RCMD(KC_LEFT), record); + break; + + case KB_EOL: + do_mac_key(KC_END, RCMD(KC_RIGHT), record); + break; + + case TG_SYS: + if (record->event.pressed) { + user_config.system_mac ^= 1; + eeconfig_update_user(user_config.raw); + } + break; + + case KB_COPY: + do_mac_key(LCTL(KC_INS), RCMD(KC_C), record); + break; + + case KB_PASTE: + do_mac_key(LSFT(KC_INS), RCMD(KC_V), record); + break; + + case MY_GUI: + do_mac_key(KC_LGUI, KC_LOPT, record); + break; + + case MY_ALT: + do_mac_key(KC_LALT, KC_LCMD, record); + break; + + case MY_RGUI: + do_mac_key(KC_RGUI, KC_ROPT, record); + break; + + case MY_RALT: + do_mac_key(KC_RALT, KC_RCMD, record); + break; + + case MY_CALC: + do_mac_key(KC_CALC, KC_F14, record); + break; + + case KB_MAKE: + if (!get_mods()) { + if (!record->event.pressed) + SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP SS_TAP(X_ENTER)); + return false; + } + break; + + case KB_VRSN: + if (!get_mods()) { + if (!record->event.pressed) { + if (user_config.system_mac) { + SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION " (mac mode)"); + } else { + SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION " (non-mac mode)"); + } + } + return false; + } + break; + + case KB_BOOT: + if (!get_mods()) { + if (record->event.pressed) { + boot_timer = timer_read32(); + } else { + if (timer_elapsed32(boot_timer) >= 500) { + reset_keyboard(); + } + } + return false; + } + break; + + case KB_FLSH: + if (!get_mods()) { + if (!record->event.pressed) { + SEND_STRING("make " QMK_KEYBOARD ":" QMK_KEYMAP ":flash\n"); + reset_keyboard(); + } + return false; + } + break; + +#ifdef DO_SECRETS + case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo + if (!record->event.pressed) { + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + send_secret_string(keycode - KC_SECRET_1); + } + return false; + break; +#endif + } + + return true; +} + +__attribute__ ((weak)) +void matrix_init_keymap(void) { +} + +void matrix_init_user(void) { + matrix_init_keymap(); +} + +__attribute__ ((weak)) +void matrix_scan_keymap(void) { +} + +void matrix_scan_user(void) { + matrix_scan_keymap(); +} + +__attribute__ ((weak)) +layer_state_t layer_state_set_keymap(layer_state_t state) { + return state; +} + +layer_state_t layer_state_set_user(layer_state_t state) { + return layer_state_set_keymap(state); +} -- cgit v1.2.3