From 3fa592a4024a24a636fa0c562e6761667a94f565 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 14 Dec 2021 20:53:36 -0800 Subject: [Keymap] Unicode and Pointing Device and Autocorect for drashna keymaps (#15415) --- .../keyrecords/autocorrection/autocorrection.c | 143 ++++++++++ .../keyrecords/autocorrection/autocorrection.h | 10 + .../autocorrection/make_autocorrection_data.py | 273 ++++++++++++++++++++ users/drashna/keyrecords/caps_word.c | 69 +++++ users/drashna/keyrecords/caps_word.h | 8 + users/drashna/keyrecords/process_records.c | 220 ++++++++++++++++ users/drashna/keyrecords/process_records.h | 142 ++++++++++ users/drashna/keyrecords/tap_dances.c | 72 ++++++ users/drashna/keyrecords/tap_dances.h | 44 ++++ users/drashna/keyrecords/unicode.c | 287 +++++++++++++++++++++ users/drashna/keyrecords/wrappers.h | 278 ++++++++++++++++++++ 11 files changed, 1546 insertions(+) create mode 100644 users/drashna/keyrecords/autocorrection/autocorrection.c create mode 100644 users/drashna/keyrecords/autocorrection/autocorrection.h create mode 100755 users/drashna/keyrecords/autocorrection/make_autocorrection_data.py create mode 100644 users/drashna/keyrecords/caps_word.c create mode 100644 users/drashna/keyrecords/caps_word.h create mode 100644 users/drashna/keyrecords/process_records.c create mode 100644 users/drashna/keyrecords/process_records.h create mode 100644 users/drashna/keyrecords/tap_dances.c create mode 100644 users/drashna/keyrecords/tap_dances.h create mode 100644 users/drashna/keyrecords/unicode.c create mode 100644 users/drashna/keyrecords/wrappers.h (limited to 'users/drashna/keyrecords') diff --git a/users/drashna/keyrecords/autocorrection/autocorrection.c b/users/drashna/keyrecords/autocorrection/autocorrection.c new file mode 100644 index 0000000000..7c8c28c674 --- /dev/null +++ b/users/drashna/keyrecords/autocorrection/autocorrection.c @@ -0,0 +1,143 @@ +// Copyright 2021 Google LLC +// Copyright 2022 @filterpaper +// SPDX-License-Identifier: Apache-2.0 +// Original source: https://getreuer.info/posts/keyboards/autocorrection + +#include "autocorrection.h" +#include + +#if __has_include("autocorrection_data.h") +# include "autocorrection_data.h" +# if AUTOCORRECTION_MIN_LENGTH < 4 +# error Minimum Length is too short and may cause overflows +# endif + +bool process_autocorrection(uint16_t keycode, keyrecord_t* record) { + static uint8_t typo_buffer[AUTOCORRECTION_MAX_LENGTH] = {KC_SPC}; + static uint8_t typo_buffer_size = 1; + + if (keycode == AUTO_CTN) { + if (record->event.pressed) { + typo_buffer_size = 0; + userspace_config.autocorrection ^= 1; + eeconfig_update_user(userspace_config.raw); + } + return false; + } + + if (!userspace_config.autocorrection) { + typo_buffer_size = 0; + return true; + } + + switch (keycode) { + case KC_LSFT: + case KC_RSFT: + return true; +# ifndef NO_ACTION_TAPPING + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + if (((keycode >> 8) & 0xF) == MOD_LSFT) { + return true; + } +# ifndef NO_ACTION_LAYER + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: +# endif + if (record->event.pressed || !record->tap.count) { + return true; + } + keycode &= 0xFF; + break; +# endif +# ifndef NO_ACTION_ONESHOT + case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: + if ((keycode & 0xF) == MOD_LSFT) { + return true; + } +# endif + default: + if (!record->event.pressed) { + return true; + } + } + + // Subtract buffer for Backspace key, reset for other non-alpha. + if (!(KC_A <= keycode && keycode <= KC_Z)) { + if (keycode == KC_BSPC) { + // Remove last character from the buffer. + if (typo_buffer_size > 0) { + --typo_buffer_size; + } + return true; + } else if (KC_1 <= keycode && keycode <= KC_SLSH && keycode != KC_ESC) { + // Set a word boundary if space, period, digit, etc. is pressed. + // Behave more conservatively for the enter key. Reset, so that enter + // can't be used on a word ending. + if (keycode == KC_ENT) { + typo_buffer_size = 0; + } + keycode = KC_SPC; + } else { + // Clear state if some other non-alpha key is pressed. + typo_buffer_size = 0; + return true; + } + } + + // Rotate oldest character if buffer is full. + if (typo_buffer_size >= AUTOCORRECTION_MAX_LENGTH) { + memmove(typo_buffer, typo_buffer + 1, AUTOCORRECTION_MAX_LENGTH - 1); + typo_buffer_size = AUTOCORRECTION_MAX_LENGTH - 1; + } + + // Append `keycode` to buffer. + typo_buffer[typo_buffer_size++] = keycode; + // Return if buffer is smaller than the shortest word. + if (typo_buffer_size < AUTOCORRECTION_MIN_LENGTH) { + return true; + } + + // Check for typo in buffer using a trie stored in `autocorrection_data`. + uint16_t state = 0; + uint8_t code = pgm_read_byte(autocorrection_data + state); + for (uint8_t i = typo_buffer_size - 1; i >= 0; --i) { + uint8_t const key_i = typo_buffer[i]; + + if (code & 64) { // Check for match in node with multiple children. + code &= 63; + for (; code != key_i; code = pgm_read_byte(autocorrection_data + (state += 3))) { + if (!code) return true; + } + // Follow link to child node. + state = (pgm_read_byte(autocorrection_data + state + 1) | pgm_read_byte(autocorrection_data + state + 2) << 8); + // Check for match in node with single child. + } else if (code != key_i) { + return true; + } else if (!(code = pgm_read_byte(autocorrection_data + (++state)))) { + ++state; + } + + code = pgm_read_byte(autocorrection_data + state); + + if (code & 128) { // A typo was found! Apply autocorrection. + const uint8_t backspaces = code & 63; + for (uint8_t i = 0; i < backspaces; ++i) { + tap_code(KC_BSPC); + } + send_string_P((char const*)(autocorrection_data + state + 1)); + + if (keycode == KC_SPC) { + typo_buffer[0] = KC_SPC; + typo_buffer_size = 1; + return true; + } else { + typo_buffer_size = 0; + return false; + } + } + } + return true; +} +#else +# pragma message "Warning!!! Autocorrect is not corretly setup!" +bool process_autocorrection(uint16_t keycode, keyrecord_t* record) { return true; } +#endif diff --git a/users/drashna/keyrecords/autocorrection/autocorrection.h b/users/drashna/keyrecords/autocorrection/autocorrection.h new file mode 100644 index 0000000000..57685eb4b5 --- /dev/null +++ b/users/drashna/keyrecords/autocorrection/autocorrection.h @@ -0,0 +1,10 @@ +// Copyright 2021 Google LLC +// Copyright 2022 @filterpaper +// SPDX-License-Identifier: Apache-2.0 +// Original source: https://getreuer.info/posts/keyboards/autocorrection + +#pragma once + +#include "drashna.h" + +bool process_autocorrection(uint16_t keycode, keyrecord_t* record); diff --git a/users/drashna/keyrecords/autocorrection/make_autocorrection_data.py b/users/drashna/keyrecords/autocorrection/make_autocorrection_data.py new file mode 100755 index 0000000000..27383b8955 --- /dev/null +++ b/users/drashna/keyrecords/autocorrection/make_autocorrection_data.py @@ -0,0 +1,273 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Python program to make autocorrection_data.h. + +This program reads "autocorrection_dict.txt" and generates a C source file +"autocorrection_data.h" with a serialized trie embedded as an array. Run this +program without arguments like + +$ python3 make_autocorrection_data.py + +Or to read from a different typo dict file, pass it as the first argument like + +$ python3 make_autocorrection_data.py dict.txt + +Each line of the dict file defines one typo and its correction with the syntax +"typo -> correction". Blank lines or lines starting with '#' are ignored. +Example: + + :thier -> their + fitler -> filter + lenght -> length + ouput -> output + widht -> width + +See autocorrection_dict_extra.txt for a larger example. + +For full documentation, see +https://getreuer.info/posts/keyboards/autocorrection +""" + +import sys +import textwrap +from typing import Any, Dict, List, Tuple + +try: + from english_words import english_words_lower_alpha_set as CORRECT_WORDS +except ImportError: + print('Autocorrection will falsely trigger when a typo is a substring of a ' + 'correctly spelled word. To check for this, install the english_words ' + 'package and rerun this script:\n\n pip install english_words\n') + # Use a minimal word list as a fallback. + CORRECT_WORDS = ('information', 'available', 'international', 'language', + 'loosest', 'reference', 'wealthier', 'entertainment', + 'association', 'provides', 'technology', 'statehood') + +KC_A = 4 +KC_SPC = 0x2c + +def parse_file(file_name: str) -> List[Tuple[str, str]]: + """Parses autocorrections dictionary file. + + Each line of the file defines one typo and its correction with the syntax + "typo -> correction". Blank lines or lines starting with '#' are ignored. The + function validates that typos only have characters a-z and that typos are not + substrings of other typos, otherwise the longer typo would never trigger. + + Args: + file_name: String, path of the autocorrections dictionary. + Returns: + List of (typo, correction) tuples. + """ + + autocorrections = [] + typos = set() + line_number = 0 + for line in open(file_name, 'rt'): + line_number += 1 + line = line.strip() + if line and line[0] != '#': + # Parse syntax "typo -> correction", using strip to ignore indenting. + tokens = [token.strip() for token in line.split('->', 1)] + if len(tokens) != 2 or not tokens[0]: + print(f'Error:{line_number}: Invalid syntax: "{line}"') + sys.exit(1) + + typo, correction = tokens + typo = typo.lower() # Force typos to lowercase. + typo = typo.replace(' ', ':') + + if typo in typos: + print(f'Warning:{line_number}: Ignoring duplicate typo: "{typo}"') + continue + + # Check that `typo` is valid. + if not(all([ord('a') <= ord(c) <= ord('z') or c == ':' for c in typo])): + print(f'Error:{line_number}: Typo "{typo}" has ' + 'characters other than a-z and :.') + sys.exit(1) + for other_typo in typos: + if typo in other_typo or other_typo in typo: + print(f'Error:{line_number}: Typos may not be substrings of one ' + f'another, otherwise the longer typo would never trigger: ' + f'"{typo}" vs. "{other_typo}".') + sys.exit(1) + if len(typo) < 5: + print(f'Warning:{line_number}: It is suggested that typos are at ' + f'least 5 characters long to avoid false triggers: "{typo}"') + + if typo.startswith(':') and typo.endswith(':'): + if typo[1:-1] in CORRECT_WORDS: + print(f'Warning:{line_number}: Typo "{typo}" is a correctly spelled ' + 'dictionary word.') + elif typo.startswith(':') and not typo.endswith(':'): + for word in CORRECT_WORDS: + if word.startswith(typo[1:]): + print(f'Warning:{line_number}: Typo "{typo}" would falsely trigger ' + f'on correctly spelled word "{word}".') + elif not typo.startswith(':') and typo.endswith(':'): + for word in CORRECT_WORDS: + if word.endswith(typo[:-1]): + print(f'Warning:{line_number}: Typo "{typo}" would falsely trigger ' + f'on correctly spelled word "{word}".') + elif not typo.startswith(':') and not typo.endswith(':'): + for word in CORRECT_WORDS: + if typo in word: + print(f'Warning:{line_number}: Typo "{typo}" would falsely trigger ' + f'on correctly spelled word "{word}".') + + autocorrections.append((typo, correction)) + typos.add(typo) + + return autocorrections + + +def make_trie(autocorrections: List[Tuple[str, str]]) -> Dict[str, Any]: + """Makes a trie from the the typos, writing in reverse. + + Args: + autocorrections: List of (typo, correction) tuples. + Returns: + Dict of dict, representing the trie. + """ + trie = {} + for typo, correction in autocorrections: + node = trie + for letter in typo[::-1]: + node = node.setdefault(letter, {}) + node['LEAF'] = (typo, correction) + + return trie + + +def serialize_trie(autocorrections: List[Tuple[str, str]], + trie: Dict[str, Any]) -> List[int]: + """Serializes trie and correction data in a form readable by the C code. + + Args: + autocorrections: List of (typo, correction) tuples. + trie: Dict of dicts. + Returns: + List of ints in the range 0-255. + """ + table = [] + + # Traverse trie in depth first order. + def traverse(trie_node): + if 'LEAF' in trie_node: # Handle a leaf trie node. + typo, correction = trie_node['LEAF'] + word_boundary_ending = typo[-1] == ':' + typo = typo.strip(':') + i = 0 # Make the autocorrection data for this entry and serialize it. + while i < min(len(typo), len(correction)) and typo[i] == correction[i]: + i += 1 + backspaces = len(typo) - i - 1 + word_boundary_ending + assert 0 <= backspaces <= 63 + correction = correction[i:] + data = [backspaces + 128] + list(bytes(correction, 'ascii')) + [0] + + entry = {'data': data, 'links': [], 'byte_offset': 0} + table.append(entry) + elif len(trie_node) == 1: # Handle trie node with a single child. + c, trie_node = next(iter(trie_node.items())) + entry = {'chars': c, 'byte_offset': 0} + + # It's common for a trie to have long chains of single-child nodes. We + # find the whole chain so that we can serialize it more efficiently. + while len(trie_node) == 1 and 'LEAF' not in trie_node: + c, trie_node = next(iter(trie_node.items())) + entry['chars'] += c + + table.append(entry) + entry['links'] = [traverse(trie_node)] + else: # Handle trie node with multiple children. + entry = {'chars': ''.join(sorted(trie_node.keys())), 'byte_offset': 0} + table.append(entry) + entry['links'] = [traverse(trie_node[c]) for c in entry['chars']] + return entry + + traverse(trie) + + def serialize(e): + def kc_code(c): + if ord('a') <= ord(c) <= ord('z'): + return ord(c) - ord('a') + KC_A + elif c == ':': + return KC_SPC + else: + raise ValueError(f'Invalid character: {c}') + + encode_link = lambda link: [link['byte_offset'] & 255, + link['byte_offset'] >> 8] + + if not e['links']: # Handle a leaf table entry. + return e['data'] + elif len(e['links']) == 1: # Handle a chain table entry. + return list(map(kc_code, e['chars'])) + [0] #+ encode_link(e['links'][0])) + else: # Handle a branch table entry. + data = [] + for c, link in zip(e['chars'], e['links']): + data += [kc_code(c) | (0 if data else 64)] + encode_link(link) + return data + [0] + + byte_offset = 0 + for e in table: # To encode links, first compute byte offset of each entry. + e['byte_offset'] = byte_offset + byte_offset += len(serialize(e)) + assert 0 <= byte_offset <= 0xffff + + return [b for e in table for b in serialize(e)] # Serialize final table. + + +def write_generated_code(autocorrections: List[Tuple[str, str]], + data: List[int], + file_name: str) -> None: + """Writes autocorrection data as generated C code to `file_name`. + + Args: + autocorrections: List of (typo, correction) tuples. + data: List of ints in 0-255, the serialized trie. + file_name: String, path of the output C file. + """ + assert all(0 <= b <= 255 for b in data) + typo_len = lambda e: len(e[0]) + min_typo = min(autocorrections, key=typo_len)[0] + max_typo = max(autocorrections, key=typo_len)[0] + generated_code = ''.join([ + '// Generated code.\n\n', + f'// Autocorrection dictionary ({len(autocorrections)} entries):\n', + ''.join(sorted(f'// {typo:<{len(max_typo)}} -> {correction}\n' + for typo, correction in autocorrections)), + f'\n#define AUTOCORRECTION_MIN_LENGTH {len(min_typo)} // "{min_typo}"\n', + f'#define AUTOCORRECTION_MAX_LENGTH {len(max_typo)} // "{max_typo}"\n\n', + textwrap.fill('static const uint8_t autocorrection_data[%d] PROGMEM = {%s};' % ( + len(data), ', '.join(map(str, data))), width=80, subsequent_indent=' '), + '\n\n']) + + with open(file_name, 'wt') as f: + f.write(generated_code) + + +def main(argv): + dict_file = argv[1] if len(argv) > 1 else 'autocorrection_dict.txt' + autocorrections = parse_file(dict_file) + trie = make_trie(autocorrections) + data = serialize_trie(autocorrections, trie) + print(f'Processed %d autocorrection entries to table with %d bytes.' + % (len(autocorrections), len(data))) + write_generated_code(autocorrections, data, 'autocorrection_data.h') + +if __name__ == '__main__': + main(sys.argv) diff --git a/users/drashna/keyrecords/caps_word.c b/users/drashna/keyrecords/caps_word.c new file mode 100644 index 0000000000..731568328a --- /dev/null +++ b/users/drashna/keyrecords/caps_word.c @@ -0,0 +1,69 @@ +// Copyright 2021 Google LLC. +// SPDX-License-Identifier: Apache-2.0 + +#include "caps_word.h" + +bool caps_word_enabled = false; +bool caps_word_shifted = false; + +bool process_caps_word(uint16_t keycode, keyrecord_t* record) { + if (!caps_word_enabled) { + // Pressing both shift keys at the same time enables caps word. + if (((get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT) == MOD_MASK_SHIFT) { + clear_mods(); + clear_oneshot_mods(); + caps_word_shifted = false; + caps_word_enabled = true; + return false; + } + return true; + } + + if (!record->event.pressed) { + return true; + } + + if (!((get_mods() | get_oneshot_mods()) & ~MOD_MASK_SHIFT)) { + switch (keycode) { + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + // Earlier return if this has not been considered tapped yet. + if (record->tap.count == 0) { + return true; + } + // Get the base tapping keycode of a mod- or layer-tap key. + keycode &= 0xff; + } + + switch (keycode) { + // Letter keys should be shifted. + case KC_A ... KC_Z: + if (!caps_word_shifted) { + register_code(KC_LSFT); + } + caps_word_shifted = true; + return true; + + // Keycodes that continue caps word but shouldn't get shifted. + case KC_1 ... KC_0: + case KC_BSPC: + case KC_MINS: + case KC_UNDS: + if (caps_word_shifted) { + unregister_code(KC_LSFT); + } + caps_word_shifted = false; + return true; + + // Any other keycode disables caps word. + } + } + + // Disable caps word. + caps_word_enabled = false; + if (caps_word_shifted) { + unregister_code(KC_LSFT); + } + caps_word_shifted = false; + return true; +} diff --git a/users/drashna/keyrecords/caps_word.h b/users/drashna/keyrecords/caps_word.h new file mode 100644 index 0000000000..79e410ddda --- /dev/null +++ b/users/drashna/keyrecords/caps_word.h @@ -0,0 +1,8 @@ +// Copyright 2021 Google LLC. +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "drashna.h" + +bool process_caps_word(uint16_t keycode, keyrecord_t* record); diff --git a/users/drashna/keyrecords/process_records.c b/users/drashna/keyrecords/process_records.c new file mode 100644 index 0000000000..c7d4a925b0 --- /dev/null +++ b/users/drashna/keyrecords/process_records.c @@ -0,0 +1,220 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 "drashna.h" +#include "version.h" +#ifdef CAPS_WORD_ENABLE +# include "caps_word.h" +#endif +#ifdef AUTOCORRECTION_ENABLE +# include "autocorrection/autocorrection.h" +#endif + +uint16_t copy_paste_timer; +bool host_driver_disabled = false; +// Defines actions tor my global custom keycodes. Defined in drashna.h file +// Then runs the _keymap's record handier if not processed here + +__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; } +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + // If console is enabled, it will print the matrix position and status of each key pressed +#ifdef KEYLOGGER_ENABLE + uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %b, time: %5u, int: %b, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count); +#endif // KEYLOGGER_ENABLE +#ifdef OLED_ENABLE + process_record_user_oled(keycode, record); +#endif // OLED + + if (!(process_record_keymap(keycode, record) && process_record_secrets(keycode, record) +#ifdef RGB_MATRIX_ENABLE + && process_record_user_rgb_matrix(keycode, record) +#endif +#ifdef RGBLIGHT_ENABLE + && process_record_user_rgb_light(keycode, record) +#endif +#ifdef CUSTOM_UNICODE_ENABLE + && process_record_unicode(keycode, record) +#endif +#if defined(POINTING_DEVICE_ENABLE) + && process_record_pointing(keycode, record) +#endif +#ifdef CAPS_WORD_ENABLE + && process_caps_word(keycode, record) +#endif +#ifdef AUTOCORRECTION_ENABLE + && process_autocorrection(keycode, record) +#endif + && true)) { + return false; + } + + switch (keycode) { + case FIRST_DEFAULT_LAYER_KEYCODE ... LAST_DEFAULT_LAYER_KEYCODE: + if (record->event.pressed) { + uint8_t mods = mod_config(get_mods() | get_oneshot_mods()); + if (!mods) { + set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE); +#if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 3) + } else if (mods & MOD_MASK_SHIFT) { + set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 4); +# if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 7) + + } else if (mods & MOD_MASK_CTRL) { + set_single_persistent_default_layer(keycode - FIRST_DEFAULT_LAYER_KEYCODE + 8); +# endif +#endif + } + } + break; + + case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader + if (!record->event.pressed) { +#ifndef MAKE_BOOTLOADER + uint8_t temp_mod = mod_config(get_mods()); + uint8_t temp_osm = mod_config(get_oneshot_mods()); + clear_mods(); + clear_oneshot_mods(); +#endif + send_string_with_delay_P(PSTR("qmk"), TAP_CODE_DELAY); +#ifndef MAKE_BOOTLOADER + if ((temp_mod | temp_osm) & MOD_MASK_SHIFT) +#endif + { + send_string_with_delay_P(PSTR(" flash "), TAP_CODE_DELAY); +#ifndef MAKE_BOOTLOADER + } else { + send_string_with_delay_P(PSTR(" compile "), TAP_CODE_DELAY); +#endif + } + send_string_with_delay_P(PSTR("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP), TAP_CODE_DELAY); +#ifdef CONVERT_TO_PROTON_C + send_string_with_delay_P(PSTR(" -e CTPC=yes"), TAP_CODE_DELAY); +#endif + send_string_with_delay_P(PSTR(SS_TAP(X_ENTER)), TAP_CODE_DELAY); + } + break; + + case VRSN: // Prints firmware version + if (record->event.pressed) { + send_string_with_delay_P(PSTR(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE), TAP_CODE_DELAY); + } + break; + + case KC_DIABLO_CLEAR: // reset all Diablo timers, disabling them +#ifdef TAP_DANCE_ENABLE + if (record->event.pressed) { + for (uint8_t index = 0; index < 4; index++) { + diablo_timer[index].key_interval = 0; + } + } +#endif // TAP_DANCE_ENABLE + break; + + case KC_CCCV: // One key copy/paste + if (record->event.pressed) { + copy_paste_timer = timer_read(); + } else { + if (timer_elapsed(copy_paste_timer) > TAPPING_TERM) { // Hold, copy + tap_code16(LCTL(KC_C)); + } else { // Tap, paste + tap_code16(LCTL(KC_V)); + } + } + break; + case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal +#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) + 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) { +# if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE) + rgblight_enable_noeeprom(); +# endif + layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) +# if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE) + } else { + rgblight_disable_noeeprom(); +# endif + } + } +#endif // RGBLIGHT_ENABLE + break; + +#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) + case RGB_TOG: + // Split keyboards need to trigger on key-up for edge-case issue +# ifndef SPLIT_KEYBOARD + if (record->event.pressed) { +# else + if (!record->event.pressed) { +# endif +# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) + rgblight_toggle(); +# endif +# if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) + rgb_matrix_toggle(); +# endif + } + return false; + break; + case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions + if (record->event.pressed) { + bool is_eeprom_updated; +# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) + // 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; + } +# endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + 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; + } +# endif + if (is_eeprom_updated) { + eeconfig_update_user(userspace_config.raw); + } + } + break; +#endif + 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; + } + } + return true; +} + +__attribute__((weak)) void post_process_record_keymap(uint16_t keycode, keyrecord_t *record) {} +void post_process_record_user(uint16_t keycode, keyrecord_t *record) { post_process_record_keymap(keycode, record); } diff --git a/users/drashna/keyrecords/process_records.h b/users/drashna/keyrecords/process_records.h new file mode 100644 index 0000000000..df506b3647 --- /dev/null +++ b/users/drashna/keyrecords/process_records.h @@ -0,0 +1,142 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#pragma once +#include "drashna.h" + +#if defined(KEYBOARD_handwired_tractyl_manuform) +# define PLACEHOLDER_SAFE_RANGE KEYMAP_SAFE_RANGE +#else +# define PLACEHOLDER_SAFE_RANGE SAFE_RANGE +#endif + +enum userspace_custom_keycodes { + VRSN = PLACEHOLDER_SAFE_RANGE, // Prints QMK Firmware and board info + KC_QWERTY, // Sets default layer to QWERTY + FIRST_DEFAULT_LAYER_KEYCODE = KC_QWERTY, // Sets default layer to QWERTY + KC_COLEMAK_DH, // Sets default layer to COLEMAK + KC_COLEMAK, // Sets default layer to COLEMAK + KC_DVORAK, // Sets default layer to DVORAK + LAST_DEFAULT_LAYER_KEYCODE = KC_DVORAK, // Sets default layer to WORKMAN + KC_DIABLO_CLEAR, // Clears all Diablo Timers + KC_MAKE, // Run keyboard's customized make command + KC_RGB_T, // Toggles RGB Layer Indication mode + RGB_IDL, // RGB Idling animations + KC_SECRET_1, // test1 + KC_SECRET_2, // test2 + KC_SECRET_3, // test3 + KC_SECRET_4, // test4 + KC_SECRET_5, // test5 + KC_CCCV, // Hold to copy, tap to paste + KC_NUKE, // NUCLEAR LAUNCH DETECTED!!! + UC_FLIP, // (ಠ痊ಠ)┻━┻ + UC_TABL, // ┬─┬ノ( º _ ºノ) + UC_SHRG, // ¯\_(ツ)_/¯ + UC_DISA, // ಠ_ಠ + UC_IRNY, + UC_CLUE, + KEYLOCK, // Locks keyboard by unmounting driver + KC_NOMODE, + KC_WIDE, + KC_SCRIPT, + KC_BLOCKS, + KC_REGIONAL, + KC_AUSSIE, + KC_ZALGO, + KC_ACCEL, + AUTO_CTN, // Toggle Autocorrect status + NEW_SAFE_RANGE // use "NEWPLACEHOLDER for keymap specific codes +}; + +bool process_record_secrets(uint16_t keycode, keyrecord_t *record); +bool process_record_keymap(uint16_t keycode, keyrecord_t *record); +void post_process_record_keymap(uint16_t keycode, keyrecord_t *record); +#ifdef CUSTOM_UNICODE_ENABLE +bool process_record_unicode(uint16_t keycode, keyrecord_t *record); +void matrix_init_unicode(void); +#endif + +#define LOWER MO(_LOWER) +#define RAISE MO(_RAISE) +#define ADJUST MO(_ADJUST) +#define TG_MODS OS_TOGG +#define TG_GAME TG(_GAMEPAD) +#define TG_DBLO TG(_DIABLO) +#define OS_LWR OSL(_LOWER) +#define OS_RSE OSL(_RAISE) + +#define KC_SEC1 KC_SECRET_1 +#define KC_SEC2 KC_SECRET_2 +#define KC_SEC3 KC_SECRET_3 +#define KC_SEC4 KC_SECRET_4 +#define KC_SEC5 KC_SECRET_5 + +#define QWERTY KC_QWERTY +#define DVORAK KC_DVORAK +#define COLEMAK KC_COLEMAK +#define COLEMAKDH KC_COLEMAK_DH + +#define DEFLYR1 FIRST_DEFAULT_LAYER_KEYCODE +#define DEFLYR2 (FIRST_DEFAULT_LAYER_KEYCODE + 1) +#define DEFLYR3 (FIRST_DEFAULT_LAYER_KEYCODE + 2) +#define DEFLYR4 (FIRST_DEFAULT_LAYER_KEYCODE + 3) +#if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 3) +# define DEFLYR5 (FIRST_DEFAULT_LAYER_KEYCODE + 4) +# define DEFLYR6 (FIRST_DEFAULT_LAYER_KEYCODE + 5) +# define DEFLYR7 (FIRST_DEFAULT_LAYER_KEYCODE + 6) +# define DEFLYR8 (FIRST_DEFAULT_LAYER_KEYCODE + 7) +# if LAST_DEFAULT_LAYER_KEYCODE > (FIRST_DEFAULT_LAYER_KEYCODE + 7) +# define DEFLYR9 (FIRST_DEFAULT_LAYER_KEYCODE + 8) +# define DEFLYR10 (FIRST_DEFAULT_LAYER_KEYCODE + 9) +# define DEFLYR11 (FIRST_DEFAULT_LAYER_KEYCODE + 10) +# define DEFLYR12 (FIRST_DEFAULT_LAYER_KEYCODE + 11) +# endif +#endif + +#define KC_RESET RESET +#define KC_RST KC_RESET + +#ifdef SWAP_HANDS_ENABLE +# define KC_C1R3 SH_T(KC_TAB) +#elif defined(DRASHNA_LP) +# define KC_C1R3 TG(_GAMEPAD) +#else // SWAP_HANDS_ENABLE +# define KC_C1R3 KC_TAB +#endif // SWAP_HANDS_ENABLE + +#define BK_LWER LT(_LOWER, KC_BSPC) +#define SP_LWER LT(_LOWER, KC_SPC) +#define DL_RAIS LT(_RAISE, KC_DEL) +#define ET_RAIS LT(_RAISE, KC_ENTER) + +/* OSM keycodes, to keep things clean and easy to change */ +#define KC_MLSF OSM(MOD_LSFT) +#define KC_MRSF OSM(MOD_RSFT) + +#define OS_LGUI OSM(MOD_LGUI) +#define OS_RGUI OSM(MOD_RGUI) +#define OS_LSFT OSM(MOD_LSFT) +#define OS_RSFT OSM(MOD_RSFT) +#define OS_LCTL OSM(MOD_LCTL) +#define OS_RCTL OSM(MOD_RCTL) +#define OS_LALT OSM(MOD_LALT) +#define OS_RALT OSM(MOD_RALT) +#define OS_MEH OSM(MOD_MEH) +#define OS_HYPR OSM(MOD_HYPR) + +#define ALT_APP ALT_T(KC_APP) + +#define MG_NKRO MAGIC_TOGGLE_NKRO diff --git a/users/drashna/keyrecords/tap_dances.c b/users/drashna/keyrecords/tap_dances.c new file mode 100644 index 0000000000..01873489d8 --- /dev/null +++ b/users/drashna/keyrecords/tap_dances.c @@ -0,0 +1,72 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 "tap_dances.h" + +#define NUM_OF_DIABLO_KEYS 4 +// define diablo macro timer variables +diablo_timer_t diablo_timer[NUM_OF_DIABLO_KEYS]; + +// Set the default intervals. Always start with 0 so that it will disable on first hit. +// Otherwise, you will need to hit a bunch of times, or hit the "clear" command +uint8_t diablo_times[] = {0, 1, 3, 5, 10, 30}; + +// Cycle through the times for the macro, starting at 0, for disabled. +void diablo_tapdance_master(qk_tap_dance_state_t *state, void *user_data) { + diable_keys_t *diablo_keys = (diable_keys_t *)user_data; + // Sets the keycode based on the index + diablo_timer[diablo_keys->index].keycode = diablo_keys->keycode; + + // if the tapdance is hit more than the number of elemints in the array, reset + if (state->count >= (sizeof(diablo_times) / sizeof(uint8_t))) { + diablo_timer[diablo_keys->index].key_interval = 0; + reset_tap_dance(state); + } else { // else set the interval (tapdance count starts at 1, array starts at 0, so offset by one) + diablo_timer[diablo_keys->index].key_interval = diablo_times[state->count - 1]; + } +} + +// clang-format off +// One function to rule them all!! Where the Magic Sauce lies +#define ACTION_TAP_DANCE_DIABLO(index, keycode) { \ + .fn = { NULL, (void *)diablo_tapdance_master, NULL }, \ + .user_data = (void *)&((diable_keys_t) { index, keycode }), \ + } +// clang-format on + +// Tap Dance Definitions, sets the index and the keycode. +qk_tap_dance_action_t tap_dance_actions[] = { + // tap once to disable, and more to enable timed micros + [TD_D3_1] = ACTION_TAP_DANCE_DIABLO(0, KC_1), + [TD_D3_2] = ACTION_TAP_DANCE_DIABLO(1, KC_2), + [TD_D3_3] = ACTION_TAP_DANCE_DIABLO(2, KC_3), + [TD_D3_4] = ACTION_TAP_DANCE_DIABLO(3, KC_4), +}; + +// Checks each of the 4 timers/keys to see if enough time has elapsed +void run_diablo_macro_check(void) { + for (uint8_t index = 0; index < NUM_OF_DIABLO_KEYS; index++) { + // if key_interval is 0, it's disabled, so only run if it's set. If it's set, check the timer. + if (diablo_timer[index].key_interval && timer_elapsed(diablo_timer[index].timer) > (diablo_timer[index].key_interval * 1000)) { + // reset the timer, since enough time has passed + diablo_timer[index].timer = timer_read(); + // send keycode ONLY if we're on the diablo layer. + if (IS_LAYER_ON(_DIABLO)) { + tap_code(diablo_timer[index].keycode); + } + } + } +} diff --git a/users/drashna/keyrecords/tap_dances.h b/users/drashna/keyrecords/tap_dances.h new file mode 100644 index 0000000000..81e462ce29 --- /dev/null +++ b/users/drashna/keyrecords/tap_dances.h @@ -0,0 +1,44 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#pragma once +#include "drashna.h" + +// define diablo macro timer variables +extern uint8_t diablo_times[]; +typedef struct { + uint16_t timer; + uint8_t key_interval; + uint8_t keycode; +} diablo_timer_t; + +typedef struct { + uint8_t index; + uint8_t keycode; +} diable_keys_t; + +extern diablo_timer_t diablo_timer[]; + +void run_diablo_macro_check(void); + +#ifdef TAP_DANCE_ENABLE +enum { + TD_D3_1 = 0, + TD_D3_2, + TD_D3_3, + TD_D3_4, +}; +#endif // TAP_DANCE_ENABLE diff --git a/users/drashna/keyrecords/unicode.c b/users/drashna/keyrecords/unicode.c new file mode 100644 index 0000000000..88df2c9df9 --- /dev/null +++ b/users/drashna/keyrecords/unicode.c @@ -0,0 +1,287 @@ +/* Copyright 2020 @ridingqwerty + * Copyright 2020 @tzarc + * Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 "drashna.h" +#include "process_unicode_common.h" + +uint16_t typing_mode; + +void tap_code16_nomods(uint8_t kc) { + uint8_t temp_mod = get_mods(); + clear_mods(); + clear_oneshot_mods(); + tap_code16(kc); + set_mods(temp_mod); +} + +void tap_unicode_glyph_nomods(uint32_t glyph) { + uint8_t temp_mod = get_mods(); + clear_mods(); + clear_oneshot_mods(); + register_unicode(glyph); + set_mods(temp_mod); +} + +typedef uint32_t (*translator_function_t)(bool is_shifted, uint32_t keycode); + +#define DEFINE_UNICODE_RANGE_TRANSLATOR(translator_name, lower_alpha, upper_alpha, zero_glyph, number_one, space_glyph) \ + static inline uint32_t translator_name(bool is_shifted, uint32_t keycode) { \ + switch (keycode) { \ + case KC_A ... KC_Z: \ + return (is_shifted ? upper_alpha : lower_alpha) + keycode - KC_A; \ + case KC_0: \ + return zero_glyph; \ + case KC_1 ... KC_9: \ + return (number_one + keycode - KC_1); \ + case KC_SPACE: \ + return space_glyph; \ + } \ + return keycode; \ + } + +#define DEFINE_UNICODE_LUT_TRANSLATOR(translator_name, ...) \ + static inline uint32_t translator_name(bool is_shifted, uint32_t keycode) { \ + static const uint32_t translation[] = {__VA_ARGS__}; \ + uint32_t ret = keycode; \ + if ((keycode - KC_A) < (sizeof(translation) / sizeof(uint32_t))) { \ + ret = translation[keycode - KC_A]; \ + } \ + return ret; \ + } + +bool process_record_glyph_replacement(uint16_t keycode, keyrecord_t *record, translator_function_t translator) { + uint8_t temp_mod = get_mods(); + uint8_t temp_osm = get_oneshot_mods(); + bool is_shifted = (temp_mod | temp_osm) & MOD_MASK_SHIFT; + if (((temp_mod | temp_osm) & (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI)) == 0) { + if (KC_A <= keycode && keycode <= KC_Z) { + if (record->event.pressed) { + tap_unicode_glyph_nomods(translator(is_shifted, keycode)); + } + return false; + } else if (KC_1 <= keycode && keycode <= KC_0) { + if (is_shifted) { // skip shifted numbers, so that we can still use symbols etc. + return process_record_keymap(keycode, record); + } + if (record->event.pressed) { + register_unicode(translator(is_shifted, keycode)); + } + return false; + } else if (keycode == KC_SPACE) { + if (record->event.pressed) { + register_unicode(translator(is_shifted, keycode)); + } + return false; + } + } + return true; +} + +DEFINE_UNICODE_RANGE_TRANSLATOR(unicode_range_translator_wide, 0xFF41, 0xFF21, 0xFF10, 0xFF11, 0x2003); +DEFINE_UNICODE_RANGE_TRANSLATOR(unicode_range_translator_script, 0x1D4EA, 0x1D4D0, 0x1D7CE, 0x1D7C1, 0x2002); +DEFINE_UNICODE_RANGE_TRANSLATOR(unicode_range_translator_boxes, 0x1F170, 0x1F170, '0', '1', 0x2002); +DEFINE_UNICODE_RANGE_TRANSLATOR(unicode_range_translator_regional, 0x1F1E6, 0x1F1E6, '0', '1', 0x2003); + +DEFINE_UNICODE_LUT_TRANSLATOR(unicode_lut_translator_aussie, + 0x0250, // a + 'q', // b + 0x0254, // c + 'p', // d + 0x01DD, // e + 0x025F, // f + 0x0183, // g + 0x0265, // h + 0x1D09, // i + 0x027E, // j + 0x029E, // k + 'l', // l + 0x026F, // m + 'u', // n + 'o', // o + 'd', // p + 'b', // q + 0x0279, // r + 's', // s + 0x0287, // t + 'n', // u + 0x028C, // v + 0x028D, // w + 0x2717, // x + 0x028E, // y + 'z', // z + 0x0269, // 1 + 0x3139, // 2 + 0x0190, // 3 + 0x3123, // 4 + 0x03DB, // 5 + '9', // 6 + 0x3125, // 7 + '8', // 8 + '6', // 9 + '0' // 0 +); + +bool process_record_aussie(uint16_t keycode, keyrecord_t *record) { + bool is_shifted = (get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT; + if ((KC_A <= keycode) && (keycode <= KC_0)) { + if (record->event.pressed) { + if (!process_record_glyph_replacement(keycode, record, unicode_lut_translator_aussie)) { + tap_code16_nomods(KC_LEFT); + return false; + } + } + } else if (record->event.pressed && keycode == KC_SPACE) { + tap_code16_nomods(KC_SPACE); + tap_code16_nomods(KC_LEFT); + return false; + } else if (record->event.pressed && keycode == KC_ENTER) { + tap_code16_nomods(KC_END); + tap_code16_nomods(KC_ENTER); + return false; + } else if (record->event.pressed && keycode == KC_HOME) { + tap_code16_nomods(KC_END); + return false; + } else if (record->event.pressed && keycode == KC_END) { + tap_code16_nomods(KC_HOME); + return false; + } else if (record->event.pressed && keycode == KC_BSPC) { + tap_code16_nomods(KC_DELT); + return false; + } else if (record->event.pressed && keycode == KC_DELT) { + tap_code16_nomods(KC_BSPC); + return false; + } else if (record->event.pressed && keycode == KC_QUOT) { + tap_unicode_glyph_nomods(is_shifted ? 0x201E : 0x201A); + tap_code16_nomods(KC_LEFT); + return false; + } else if (record->event.pressed && keycode == KC_COMMA) { + tap_unicode_glyph_nomods(is_shifted ? '<' : 0x2018); + tap_code16_nomods(KC_LEFT); + return false; + } else if (record->event.pressed && keycode == KC_DOT) { + tap_unicode_glyph_nomods(is_shifted ? '>' : 0x02D9); + tap_code16_nomods(KC_LEFT); + return false; + } else if (record->event.pressed && keycode == KC_SLASH) { + tap_unicode_glyph_nomods(is_shifted ? 0x00BF : '/'); + tap_code16_nomods(KC_LEFT); + return false; + } + return true; +} + +bool process_record_zalgo(uint16_t keycode, keyrecord_t *record) { + if ((KC_A <= keycode) && (keycode <= KC_0)) { + if (record->event.pressed) { + tap_code16_nomods(keycode); + + int number = (rand() % (8 + 1 - 2)) + 2; + for (int index = 0; index < number; index++) { + uint16_t hex = (rand() % (0x036F + 1 - 0x0300)) + 0x0300; + register_unicode(hex); + } + + return false; + } + } + return true; +} + +bool process_record_unicode(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case UC_FLIP: // (ノಠ痊ಠ)ノ彡┻━┻ + if (record->event.pressed) { + send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻"); + } + break; + + case UC_TABL: // ┬─┬ノ( º _ ºノ) + if (record->event.pressed) { + send_unicode_string("┬─┬ノ( º _ ºノ)"); + } + break; + + case UC_SHRG: // ¯\_(ツ)_/¯ + if (record->event.pressed) { + send_unicode_string("¯\\_(ツ)_/¯"); + } + break; + + case UC_DISA: // ಠ_ಠ + if (record->event.pressed) { + send_unicode_string("ಠ_ಠ"); + } + break; + + case UC_IRNY: // ⸮ + if (record->event.pressed) { + register_unicode(0x2E2E); + } + break; + case UC_CLUE: // ‽ + if (record->event.pressed) { + register_unicode(0x203D); + } + break; + case KC_NOMODE ... KC_ZALGO: + if (record->event.pressed) { + if (typing_mode != keycode) { + typing_mode = keycode; + } else { + typing_mode = 0; + } + } + break; + + break; + } + if (((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) && record->tap.count) { + keycode &= 0xFF; + } + + if (typing_mode == KC_WIDE) { + if (((KC_A <= keycode) && (keycode <= KC_0)) || keycode == KC_SPACE) { + return process_record_glyph_replacement(keycode, record, unicode_range_translator_wide); + } + } else if (typing_mode == KC_SCRIPT) { + if (((KC_A <= keycode) && (keycode <= KC_0)) || keycode == KC_SPACE) { + return process_record_glyph_replacement(keycode, record, unicode_range_translator_script); + } + } else if (typing_mode == KC_BLOCKS) { + if (((KC_A <= keycode) && (keycode <= KC_0)) || keycode == KC_SPACE) { + return process_record_glyph_replacement(keycode, record, unicode_range_translator_boxes); + } + } else if (typing_mode == KC_REGIONAL) { + if (((KC_A <= keycode) && (keycode <= KC_0)) || keycode == KC_SPACE) { + if (!process_record_glyph_replacement(keycode, record, unicode_range_translator_regional)) { + wait_us(500); + tap_unicode_glyph_nomods(0x200C); + return false; + } + } + } else if (typing_mode == KC_AUSSIE) { + return process_record_aussie(keycode, record); + } else if (typing_mode == KC_ZALGO) { + return process_record_zalgo(keycode, record); + } + return process_unicode_common(keycode, record); +} + +void matrix_init_unicode(void) { + unicode_input_mode_init(); +} diff --git a/users/drashna/keyrecords/wrappers.h b/users/drashna/keyrecords/wrappers.h new file mode 100644 index 0000000000..c1ae815579 --- /dev/null +++ b/users/drashna/keyrecords/wrappers.h @@ -0,0 +1,278 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#pragma once +#include "drashna.h" +/* +Since our quirky block definitions are basically a list of comma separated +arguments, we need a wrapper in order for these definitions to be +expanded before being used as arguments to the LAYOUT_xxx macro. +*/ + +/* +Blocks for each of the four major keyboard layouts +Organized so we can quickly adapt and modify all of them +at once, rather than for each keyboard, one at a time. +And this allows for much cleaner blocks in the keymaps. +For instance Tap/Hold for Control on all of the layouts + +NOTE: These are all the same length. If you do a search/replace + then you need to add/remove underscores to keep the + lengths consistent. +*/ +// clang-format off +#define _________________QWERTY_L1_________________ KC_Q, KC_W, KC_E, KC_R, KC_T +#define _________________QWERTY_L2_________________ KC_A, KC_S, KC_D, KC_F, KC_G +#define _________________QWERTY_L3_________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _________________QWERTY_R1_________________ KC_Y, KC_U, KC_I, KC_O, KC_P +#define _________________QWERTY_R2_________________ KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT +#define _________________QWERTY_R3_________________ KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________COLEMAK_L1________________ KC_Q, KC_W, KC_F, KC_P, KC_G +#define _________________COLEMAK_L2________________ KC_A, KC_R, KC_S, KC_T, KC_D +#define _________________COLEMAK_L3________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _________________COLEMAK_R1________________ KC_J, KC_L, KC_U, KC_Y, KC_SCLN +#define _________________COLEMAK_R2________________ KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT +#define _________________COLEMAK_R3________________ KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH + +#define ______________COLEMAK_MOD_DH_L1____________ KC_Q, KC_W, KC_F, KC_P, KC_B +#define ______________COLEMAK_MOD_DH_L2____________ KC_A, KC_R, KC_S, KC_T, KC_G +#define ______________COLEMAK_MOD_DH_L3____________ KC_Z, KC_X, KC_C, KC_D, KC_V + +#define ______________COLEMAK_MOD_DH_R1____________ KC_J, KC_L, KC_U, KC_Y, KC_SCLN +#define ______________COLEMAK_MOD_DH_R2____________ KC_M, KC_N, KC_E, KC_I, KC_O, KC_QUOT +#define ______________COLEMAK_MOD_DH_R3____________ KC_K, KC_H, KC_COMM, KC_DOT, KC_SLASH + + +#define _________________DVORAK_L1_________________ KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y +#define _________________DVORAK_L2_________________ KC_A, KC_O, KC_E, KC_U, KC_I +#define _________________DVORAK_L3_________________ KC_SCLN, KC_Q, KC_J, KC_K, KC_X + +#define _________________DVORAK_R1_________________ KC_F, KC_G, KC_C, KC_R, KC_L +#define _________________DVORAK_R2_________________ KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH +#define _________________DVORAK_R3_________________ KC_B, KC_M, KC_W, KC_V, KC_Z + + +#define ________________DVORAK_AU_L1_______________ KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y +#define ________________DVORAK_AU_L2_______________ KC_O, KC_A, KC_E, KC_I, KC_U +#define ________________DVORAK_AU_L3_______________ KC_SCLN, KC_Q, KC_J, KC_K, KC_X + +#define ________________DVORAK_AU_R1_______________ KC_F, KC_G, KC_C, KC_R, KC_L +#define ________________DVORAK_AU_R2_______________ KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH +#define ________________DVORAK_AU_R3_______________ KC_B, KC_M, KC_W, KC_V, KC_Z + +#define _________________WORKMAN_L1________________ KC_Q, KC_D, KC_R, KC_W, KC_B +#define _________________WORKMAN_L2________________ KC_A, KC_S, KC_H, KC_T, KC_G +#define _________________WORKMAN_L3________________ KC_Z, KC_X, KC_M, KC_C, KC_V + +#define _________________WORKMAN_R1________________ KC_J, KC_F, KC_U, KC_P, KC_SCLN +#define _________________WORKMAN_R2________________ KC_Y, KC_N, KC_E, KC_O, KC_I, KC_QUOT +#define _________________WORKMAN_R3________________ KC_K, KC_L, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________NORMAN_L1_________________ KC_Q, KC_W, KC_D, KC_F, KC_K +#define _________________NORMAN_L2_________________ KC_A, KC_S, KC_E, KC_T, KC_G +#define _________________NORMAN_L3_________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _________________NORMAN_R1_________________ KC_J, KC_U, KC_R, KC_L, KC_SCLN +#define _________________NORMAN_R2_________________ KC_Y, KC_N, KC_I, KC_O, KC_U, KC_QUOT +#define _________________NORMAN_R3_________________ KC_P, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________MALTRON_L1________________ KC_Q, KC_P, KC_Y, KC_C, KC_B +#define _________________MALTRON_L2________________ KC_A, KC_N, KC_I, KC_S, KC_F +#define _________________MALTRON_L3________________ KC_SCLN, KC_SLSH, KC_J, KC_G, KC_COMM + +#define _________________MALTRON_R1________________ KC_V, KC_M, KC_U, KC_Z, KC_L +#define _________________MALTRON_R2________________ KC_D, KC_T, KC_D, KC_O, KC_R, KC_QUOT +#define _________________MALTRON_R3________________ KC_DOT, KC_W, KC_K, KC_MINS, KC_X + + +#define _________________EUCALYN_L1________________ KC_Q, KC_W, KC_COMM, KC_DOT, KC_SCLN +#define _________________EUCALYN_L2________________ KC_A, KC_O, KC_E, KC_I, KC_U +#define _________________EUCALYN_L3________________ KC_Z, KC_X, KC_C, KC_V, KC_F + +#define _________________EUCALYN_R1________________ KC_M, KC_R, KC_D, KC_Y, KC_P +#define _________________EUCALYN_R2________________ KC_G, KC_T, KC_K, KC_S, KC_N, KC_QUOT +#define _________________EUCALYN_R3________________ KC_B, KC_H, KC_J, KC_L, KC_SLSH + +// Qwerty-like +#define _____________CARPLAX_QFMLWY_L1_____________ KC_Q, KC_F, KC_M, KC_L, KC_W +#define _____________CARPLAX_QFMLWY_L2_____________ KC_D, KC_S, KC_T, KC_N, KC_R +#define _____________CARPLAX_QFMLWY_L3_____________ KC_Z, KC_V, KC_G, KC_C, KC_X + +#define _____________CARPLAX_QFMLWY_R1_____________ KC_Y, KC_U, KC_O, KC_B, KC_J +#define _____________CARPLAX_QFMLWY_R2_____________ KC_I, KC_A, KC_E, KC_H, KC_SCLN, KC_QUOT +#define _____________CARPLAX_QFMLWY_R3_____________ KC_P, KC_K, KC_COMM, KC_DOT, KC_SLSH + +// Colemak like +#define _____________CARPLAX_QGMLWB_L1_____________ KC_Q, KC_G, KC_M, KC_L, KC_W +#define _____________CARPLAX_QGMLWB_L2_____________ KC_D, KC_S, KC_T, KC_N, KC_R +#define _____________CARPLAX_QGMLWB_L3_____________ KC_Z, KC_X, KC_C, KC_F, KC_J + +#define _____________CARPLAX_QGMLWB_R1_____________ KC_B, KC_Y, KC_U, KC_V, KC_SCLN +#define _____________CARPLAX_QGMLWB_R2_____________ KC_I, KC_A, KC_E, KC_O, KC_H, KC_QUOT +#define _____________CARPLAX_QGMLWB_R3_____________ KC_K, KC_P, KC_COMM, KC_DOT, KC_SLSH + +// colemak like, zxcv fixed +#define _____________CARPLAX_QGMLWY_L1_____________ KC_Q, KC_G, KC_M, KC_L, KC_W +#define _____________CARPLAX_QGMLWY_L2_____________ KC_D, KC_S, KC_T, KC_N, KC_R +#define _____________CARPLAX_QGMLWY_L3_____________ KC_Z, KC_X, KC_C, KC_V, KC_J + +#define _____________CARPLAX_QGMLWY_R1_____________ KC_Y, KC_F, KC_U, KC_B, KC_SCLN +#define _____________CARPLAX_QGMLWY_R2_____________ KC_I, KC_A, KC_E, KC_O, KC_H, KC_QUOT +#define _____________CARPLAX_QGMLWY_R3_____________ KC_K, KC_P, KC_COMM, KC_DOT, KC_SLSH + +// teeheehee +#define _____________CARPLAX_TNWCLR_L1_____________ KC_T, KC_N, KC_W, KC_C, KC_L +#define _____________CARPLAX_TNWCLR_L2_____________ KC_S, KC_K, KC_J, KC_X, KC_G +#define _____________CARPLAX_TNWCLR_L3_____________ KC_E, KC_O, KC_D, KC_I, KC_A + +#define _____________CARPLAX_TNWCLR_R1_____________ KC_R, KC_B, KC_F, KC_M, KC_H +#define _____________CARPLAX_TNWCLR_R2_____________ KC_P, KC_Q, KC_Z, KC_V, KC_SCLN, KC_QUOT +#define _____________CARPLAX_TNWCLR_R3_____________ KC_U, KC_Y, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________WHITE_R1__________________ KC_V, KC_Y, KC_D, KC_COMM, KC_QUOT +#define _________________WHITE_R2__________________ KC_A, KC_T, KC_H, KC_E, KC_B +#define _________________WHITE_R3__________________ KC_P, KC_K, KC_G, KC_W, KC_Q + +#define _________________WHITE_L1__________________ KC_INT1, KC_J, KC_M, KC_L, KC_U +#define _________________WHITE_L2__________________ KC_MINS, KC_C, KC_S, KC_N, KC_O, KC_I +#define _________________WHITE_L3__________________ KC_X, KC_R, KC_F, KC_DOT, KC_Z + + +#define _________________HALMAK_L1_________________ KC_W, KC_L, KC_R, KC_B, KC_Z +#define _________________HALMAK_L2_________________ KC_S, KC_H, KC_N, KC_T, KC_COMM +#define _________________HALMAK_L3_________________ KC_F, KC_M, KC_V, KC_V, KC_SLASH + +#define _________________HALMAK_R1_________________ KC_SCLN, KC_Q, KC_U, KC_D, KC_J +#define _________________HALMAK_R2_________________ KC_DOT, KC_A, KC_E, KC_O, KC_I, KC_QUOTE +#define _________________HALMAK_R3_________________ KC_G, KC_P, KC_X, KC_K, KC_Y + + +#define __________________ISRT_L1__________________ KC_W, KC_C, KC_L, KC_M, KC_K +#define __________________ISRT_L2__________________ KC_I, KC_S, KC_R, KC_T, KC_G +#define __________________ISRT_L3__________________ KC_Q, KC_V, KC_W, KC_D, KC_J + +#define __________________ISRT_R1__________________ KC_Z, KC_F, KC_U, KC_COMM, KC_QUOTE +#define __________________ISRT_R2__________________ KC_P, KC_N, KC_E, KC_A, KC_O, KC_SCLN +#define __________________ISRT_R3__________________ KC_B, KC_H, KC_SLSH, KC_DOT, KC_X + + +#define __________________SOUL_L1__________________ KC_Q, KC_W, KC_L, KC_D, KC_P +#define __________________SOUL_L2__________________ KC_A, KC_S, KC_R, KC_T, KC_G +#define __________________SOUL_L3__________________ KC_Z, KC_X, KC_C, KC_V, KC_J + +#define __________________SOUL_R1__________________ KC_K, KC_M, KC_U, KC_Y, KC_SCLN +#define __________________SOUL_R2__________________ KC_F, KC_N, KC_E, KC_I, KC_O, KC_QUOTE +#define __________________SOUL_R3__________________ KC_B, KC_H, KC_COMM, KC_DOT, KC_SLSH + + +#define __________________NIRO_L1__________________ KC_Q, KC_W, KC_U, KC_D, KC_P +#define __________________NIRO_L2__________________ KC_A, KC_S, KC_E, KC_T, KC_G +#define __________________NIRO_L3__________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define __________________NIRO_R1__________________ KC_J, KC_F, KC_Y, KC_L, KC_SCLN +#define __________________NIRO_R2__________________ KC_H, KC_N, KC_I, KC_R, KC_O, KC_QUOTE +#define __________________NIRO_R3__________________ KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________ASSET_L1__________________ KC_Q, KC_W, KC_J, KC_F, KC_G +#define _________________ASSET_L2__________________ KC_A, KC_S, KC_E, KC_T, KC_D +#define _________________ASSET_L3__________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _________________ASSET_R1__________________ KC_Y, KC_P, KC_U, KC_L, KC_SCLN +#define _________________ASSET_R2__________________ KC_H, KC_N, KC_I, KC_O, KC_R, KC_QUOTE +#define _________________ASSET_R3__________________ KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define _________________MTGAP_L1__________________ KC_Y, KC_P, KC_O, KC_U, KC_J +#define _________________MTGAP_L2__________________ KC_I, KC_N, KC_E, KC_A, KC_COMM +#define _________________MTGAP_L3__________________ KC_Q, KC_Z, KC_SLSH, KC_DOT, KC_SCLN + +#define _________________MTGAP_R1__________________ KC_K, KC_D, KC_L, KC_C, KC_W +#define _________________MTGAP_R2__________________ KC_M, KC_H, KC_T, KC_S, KC_R, KC_QUOTE +#define _________________MTGAP_R3__________________ KC_B, KC_F, KC_G, KC_V, KC_X + + +#define _________________MINIMAK_L1________________ KC_Q, KC_W, KC_D, KC_R, KC_K +#define _________________MINIMAK_L2________________ KC_A, KC_S, KC_T, KC_F, KC_G +#define _________________MINIMAK_L3________________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _________________MINIMAK_R1________________ KC_Y, KC_U, KC_I, KC_O, KC_P +#define _________________MINIMAK_R2________________ KC_H, KC_J, KC_E, KC_L, KC_SCLN, KC_QUOT +#define _________________MINIMAK_R3________________ KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define ________________MINIMAK_8_L1_______________ KC_Q, KC_W, KC_D, KC_R, KC_K +#define ________________MINIMAK_8_L2_______________ KC_A, KC_S, KC_T, KC_F, KC_G +#define ________________MINIMAK_8_L3_______________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define ________________MINIMAK_8_R1_______________ KC_Y, KC_U, KC_I, KC_L, KC_P +#define ________________MINIMAK_8_R2_______________ KC_H, KC_N, KC_E, KC_O, KC_SCLN, KC_QUOT +#define ________________MINIMAK_8_R3_______________ KC_J, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define _______________MINIMAK_12_L1_______________ KC_Q, KC_W, KC_D, KC_F, KC_K +#define _______________MINIMAK_12_L2_______________ KC_A, KC_S, KC_T, KC_R, KC_G +#define _______________MINIMAK_12_L3_______________ KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _______________MINIMAK_12_R1_______________ KC_Y, KC_U, KC_I, KC_L, KC_SCLN +#define _______________MINIMAK_12_R2_______________ KC_H, KC_N, KC_E, KC_O, KC_P, KC_QUOT +#define _______________MINIMAK_12_R3_______________ KC_J, KC_M, KC_COMM, KC_DOT, KC_SLSH + + +#define ________________NUMBER_LEFT________________ KC_1, KC_2, KC_3, KC_4, KC_5 +#define ________________NUMBER_RIGHT_______________ KC_6, KC_7, KC_8, KC_9, KC_0 +#define _________________FUNC_LEFT_________________ KC_F1, KC_F2, KC_F3, KC_F4, KC_F5 +#define _________________FUNC_RIGHT________________ KC_F6, KC_F7, KC_F8, KC_F9, KC_F10 + +#define ___________________BLANK___________________ _______, _______, _______, _______, _______ + + +#define _________________LOWER_L1__________________ KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC +#define _________________LOWER_L2__________________ _________________FUNC_LEFT_________________ +#define _________________LOWER_L3__________________ _________________FUNC_RIGHT________________ + +#define _________________LOWER_R1__________________ KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN +#define _________________LOWER_R2__________________ _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR +#define _________________LOWER_R3__________________ _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END + + + +#define _________________RAISE_L1__________________ ________________NUMBER_LEFT________________ +#define _________________RAISE_L2__________________ ___________________BLANK___________________ +#define _________________RAISE_L3__________________ ___________________BLANK___________________ + +#define _________________RAISE_R1__________________ ________________NUMBER_RIGHT_______________ +#define _________________RAISE_R2__________________ _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC +#define _________________RAISE_R3__________________ _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT + + + +#define _________________ADJUST_L1_________________ RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG +#define _________________ADJUST_L2_________________ MU_TOG , CK_TOGG, AU_ON, AU_OFF, CG_NORM +#define _________________ADJUST_L3_________________ RGB_RMOD,RGB_HUD,RGB_SAD, RGB_VAD, KC_RGB_T + +#define _________________ADJUST_R1_________________ KC_SEC1, KC_SEC2, KC_SEC3, KC_SEC4, KC_SEC5 +#define _________________ADJUST_R2_________________ CG_SWAP, DEFLYR1, DEFLYR2, DEFLYR3, DEFLYR4 +#define _________________ADJUST_R3_________________ MG_NKRO, KC_MUTE, KC_VOLD, KC_VOLU, KC_MNXT + +// clang-format on -- cgit v1.2.3