[Keymap] develop updates for Drashna Keymaps (#18472)
This commit is contained in:
@ -23,6 +23,6 @@ MOUSEKEY_ENABLE = yes
|
||||
NKRO_ENABLE = yes
|
||||
CONSOLE_ENABLE = yes
|
||||
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
|
||||
DEBOUNCE_TYPE = asym_eager_defer_pk
|
||||
|
@ -24,7 +24,7 @@ SERIAL_DRIVER = usart
|
||||
AUDIO_DRIVER = pwm_hardware
|
||||
BACKLIGHT_DRIVER = pwm
|
||||
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
SWAP_HANDS_ENABLE = yes
|
||||
TAP_DANCE_ENABLE = yes
|
||||
|
@ -1,5 +1,5 @@
|
||||
SWAP_HANDS_ENABLE = no
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
CONSOLE_ENABLE = yes
|
||||
KEYLOGGER_ENABLE = no
|
||||
|
@ -8,7 +8,7 @@ OLED_ENABLE = yes
|
||||
WPM_ENABLE = yes
|
||||
ENCODER_ENABLE = yes
|
||||
ENCODER_MAP_ENABLE = yes
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
DEFERRED_EXEC_ENABLE = yes
|
||||
|
||||
@ -20,7 +20,7 @@ ifeq ($(strip $(KEYBOARD)), handwired/tractyl_manuform/5x6_right/elite_c)
|
||||
OLED_ENABLE = no
|
||||
WPM_ENABLE = no
|
||||
ENCODER_ENABLE = no
|
||||
AUTOCORRECTION_ENABLE = no
|
||||
AUTOCORRECT_ENABLE = no
|
||||
LTO_SUPPORTED = yes
|
||||
SWAP_HANDS_ENABLE = no
|
||||
CUSTOM_UNICODE_ENABLE = no
|
||||
@ -29,7 +29,7 @@ ifeq ($(strip $(KEYBOARD)), handwired/tractyl_manuform/5x6_right/elite_c)
|
||||
BOOTLOADER_SIZE = 512
|
||||
endif
|
||||
ifeq ($(strip $(KEYBOARD)), handwired/tractyl_manuform/5x6_right/teensy2pp)
|
||||
AUTOCORRECTION_ENABLE = no
|
||||
AUTOCORRECT_ENABLE = no
|
||||
CAPS_WORD_ENABLE = yes
|
||||
endif
|
||||
ifeq ($(strip $(KEYBOARD)), handwired/tractyl_manuform/5x6_right/f411)
|
||||
|
@ -2,5 +2,5 @@ TAP_DANCE_ENABLE = yes
|
||||
BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite
|
||||
UNICODE_ENABLE = yes
|
||||
UNICODEMAP_ENABLE = no
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
|
@ -18,7 +18,7 @@ ifeq ($(strip $(KEYBOARD)), splitkb/kyria/rev1/proton_c)
|
||||
SWAP_HANDS_ENABLE = yes
|
||||
LTO_ENABLE = no
|
||||
ENCODER_MAP_ENABLE = yes
|
||||
AUTOCORRECTION_ENABLE = yes
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
CAPS_WORD_ENABLE = yes
|
||||
OLED_DRIVER = custom
|
||||
else
|
||||
|
@ -6,5 +6,5 @@ NKRO_ENABLE = yes
|
||||
RGBLIGHT_STARTUP_ANIMATION = yes
|
||||
ENCODER_MAP_ENABLE = yes
|
||||
|
||||
AUTOCORRECTION_ENABLE = no
|
||||
AUTOCORRECT_ENABLE = no
|
||||
CUSTOM_UNICODE_ENABLE = no
|
||||
|
@ -49,7 +49,7 @@ void keyboard_post_init_user(void) {
|
||||
keyboard_post_init_transport_sync();
|
||||
#endif
|
||||
#ifdef I2C_SCANNER_ENABLE
|
||||
matrix_scan_i2c();
|
||||
keyboard_post_init_i2c();
|
||||
#endif
|
||||
|
||||
keyboard_post_init_keymap();
|
||||
|
@ -129,3 +129,15 @@ void keyboard_post_init_i2c(void) {
|
||||
scan_timer = timer_read();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AUTOCORRECT_ENABLE) && defined(AUDIO_ENABLE)
|
||||
# ifdef USER_SONG_LIST
|
||||
float autocorrect_song[][2] = SONG(MARIO_GAMEOVER);
|
||||
# else
|
||||
float autocorrect_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
|
||||
# endif
|
||||
bool apply_autocorrect(uint8_t backspaces, const char *str) {
|
||||
PLAY_SONG(autocorrect_song);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +0,0 @@
|
||||
// Copyright 2021 Google LLC
|
||||
// Copyright 2021 @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);
|
||||
bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
|
||||
bool apply_autocorrect(uint8_t backspaces, const char *str);
|
||||
|
||||
bool autocorrect_is_enabled(void);
|
||||
void autocorrect_enable(void);
|
||||
void autocorrect_disable(void);
|
||||
void autocorrect_toggle(void);
|
@ -1 +0,0 @@
|
||||
#include "autocorrect_data.h"
|
@ -1,298 +0,0 @@
|
||||
# Copyright 2021-2022 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
|
||||
dosen't -> doesn't
|
||||
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, Iterator, 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 = ('apparent', 'association', 'available', 'classification',
|
||||
'effect', 'entertainment', 'fantastic', 'information',
|
||||
'integrate', 'international', 'language', 'loosest',
|
||||
'manual', 'nothing', 'provides', 'reference', 'statehood',
|
||||
'technology', 'virtually', 'wealthier', 'wonderful')
|
||||
|
||||
KC_A = 4
|
||||
KC_SPC = 0x2c
|
||||
KC_QUOT = 0x34
|
||||
|
||||
TYPO_CHARS = dict(
|
||||
[
|
||||
("'", KC_QUOT),
|
||||
(':', KC_SPC), # "Word break" character.
|
||||
] +
|
||||
# Characters a-z.
|
||||
[(chr(c), c + KC_A - ord('a')) for c in range(ord('a'), ord('z') + 1)]
|
||||
)
|
||||
|
||||
|
||||
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 in TYPO_CHARS, that
|
||||
typos are not substrings of other typos, and checking that typos don't trigger
|
||||
on CORRECT_WORDS.
|
||||
|
||||
Args:
|
||||
file_name: String, path of the autocorrections dictionary.
|
||||
Returns:
|
||||
List of (typo, correction) tuples.
|
||||
"""
|
||||
correct_words = ('information', 'available', 'international', 'language', 'loosest', 'reference', 'wealthier', 'entertainment', 'association', 'provides', 'technology', 'statehood')
|
||||
autocorrections = []
|
||||
typos = set()
|
||||
for line_number, typo, correction in parse_file_lines(file_name):
|
||||
if typo in typos:
|
||||
print(f'Warning:{line_number}: Ignoring duplicate typo: "{typo}"')
|
||||
continue
|
||||
|
||||
# Check that `typo` is valid.
|
||||
if not(all([c in TYPO_CHARS for c in typo])):
|
||||
print(f'Error:{line_number}: Typo "{typo}" has '
|
||||
'characters other than ' + ''.join(TYPO_CHARS.keys()))
|
||||
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}"')
|
||||
|
||||
check_typo_against_dictionary(typo, line_number, correct_words)
|
||||
|
||||
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 parse_file_lines(file_name: str) -> Iterator[Tuple[int, str, str]]:
|
||||
"""Parses lines read from `file_name` into typo-correction pairs."""
|
||||
|
||||
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(' ', ':')
|
||||
|
||||
yield line_number, typo, correction
|
||||
|
||||
|
||||
def check_typo_against_dictionary(typo: str, line_number: int, correct_words) -> None:
|
||||
"""Checks `typo` against English dictionary words."""
|
||||
|
||||
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 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 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 on correctly spelled word "{word}".')
|
||||
|
||||
|
||||
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: Dict[str, Any]) -> Dict[str, Any]:
|
||||
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: Dict[str, Any]) -> List[int]:
|
||||
if not e['links']: # Handle a leaf table entry.
|
||||
return e['data']
|
||||
elif len(e['links']) == 1: # Handle a chain table entry.
|
||||
return [TYPO_CHARS[c] for c in e['chars']] + [0]
|
||||
else: # Handle a branch table entry.
|
||||
data = []
|
||||
for c, link in zip(e['chars'], e['links']):
|
||||
data += [TYPO_CHARS[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))
|
||||
|
||||
return [b for e in table for b in serialize(e)] # Serialize final table.
|
||||
|
||||
|
||||
def encode_link(link: Dict[str, Any]) -> List[int]:
|
||||
"""Encodes a node link as two bytes."""
|
||||
byte_offset = link['byte_offset']
|
||||
if not (0 <= byte_offset <= 0xffff):
|
||||
print('Error: The autocorrection table is too large, a node link exceeds '
|
||||
'64KB limit. Try reducing the autocorrection dict to fewer entries.')
|
||||
sys.exit(1)
|
||||
return [byte_offset & 255, byte_offset >> 8]
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def typo_len(e: Tuple[str, str]) -> int:
|
||||
return 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)
|
File diff suppressed because it is too large
Load Diff
@ -3,9 +3,6 @@
|
||||
|
||||
#include "drashna.h"
|
||||
#include "version.h"
|
||||
#ifdef AUTOCORRECTION_ENABLE
|
||||
# include "autocorrection/autocorrection.h"
|
||||
#endif
|
||||
|
||||
uint16_t copy_paste_timer;
|
||||
bool host_driver_disabled = false;
|
||||
@ -64,9 +61,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
#endif
|
||||
#if defined(CUSTOM_POINTING_DEVICE)
|
||||
&& process_record_pointing(keycode, record)
|
||||
#endif
|
||||
#ifdef AUTOCORRECTION_ENABLE
|
||||
&& process_autocorrection(keycode, record)
|
||||
#endif
|
||||
&& true)) {
|
||||
return false;
|
||||
|
@ -46,9 +46,6 @@ enum userspace_custom_keycodes {
|
||||
KC_ZALGO,
|
||||
KC_SUPER,
|
||||
KC_ACCEL,
|
||||
AUTOCORRECT_ON,
|
||||
AUTOCORRECT_OFF,
|
||||
AUTOCORRECT_TOGGLE,
|
||||
NEW_SAFE_RANGE // use "NEWPLACEHOLDER for keymap specific codes
|
||||
};
|
||||
|
||||
|
@ -23,9 +23,6 @@
|
||||
#ifdef AUDIO_CLICKY
|
||||
# include "process_clicky.h"
|
||||
#endif
|
||||
#if defined(AUTOCORRECTION_ENABLE)
|
||||
# include "keyrecords/autocorrection/autocorrection.h"
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
bool is_oled_enabled = true;
|
||||
@ -458,10 +455,6 @@ void render_bootmagic_status(uint8_t col, uint8_t line) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CUSTOM_POINTING_DEVICE)
|
||||
extern bool tap_toggling;
|
||||
#endif
|
||||
|
||||
void render_user_status(uint8_t col, uint8_t line) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
bool is_audio_on = false, l_is_clicky_on = false;
|
||||
@ -490,9 +483,9 @@ void render_user_status(uint8_t col, uint8_t line) {
|
||||
# if !defined(OLED_DISPLAY_VERBOSE)
|
||||
oled_write_P(PSTR(" "), false);
|
||||
# endif
|
||||
#elif defined(CUSTOM_POINTING_DEVICE)
|
||||
#elif defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
||||
static const char PROGMEM mouse_lock[3] = {0xF2, 0xF3, 0};
|
||||
oled_write_P(mouse_lock, tap_toggling);
|
||||
oled_write_P(mouse_lock, get_auto_mouse_toggle());
|
||||
#endif
|
||||
#ifdef AUDIO_ENABLE
|
||||
static const char PROGMEM audio_status[2][3] = {{0xE0, 0xE1, 0}, {0xE2, 0xE3, 0}};
|
||||
@ -771,8 +764,8 @@ void render_unicode_mode(uint8_t col, uint8_t line) {
|
||||
|
||||
uint32_t kitty_animation_phases(uint32_t triger_time, void *cb_arg) {
|
||||
static uint32_t anim_frame_duration = 500;
|
||||
#ifdef CUSTOM_POINTING_DEVICE
|
||||
if (tap_toggling) {
|
||||
#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
||||
if (get_auto_mouse_toggle()) {
|
||||
animation_frame = (animation_frame + 1) % OLED_RTOGI_FRAMES;
|
||||
animation_type = 3;
|
||||
anim_frame_duration = 300;
|
||||
|
@ -3,10 +3,8 @@
|
||||
|
||||
#include "pointing.h"
|
||||
|
||||
static uint16_t mouse_timer = 0;
|
||||
static uint16_t mouse_debounce_timer = 0;
|
||||
static uint8_t mouse_keycode_tracker = 0;
|
||||
bool tap_toggling = false, enable_acceleration = false;
|
||||
static uint16_t mouse_debounce_timer = 0;
|
||||
bool enable_acceleration = false;
|
||||
|
||||
#ifdef TAPPING_TERM_PER_KEY
|
||||
# define TAP_CHECK get_tapping_term(KC_BTN1, NULL)
|
||||
@ -17,6 +15,15 @@ bool tap_toggling = false, enable_acceleration = false;
|
||||
# define TAP_CHECK TAPPING_TERM
|
||||
#endif
|
||||
|
||||
__attribute__((weak)) void pointing_device_init_keymap(void) {}
|
||||
|
||||
void pointing_device_init_user(void) {
|
||||
set_auto_mouse_layer(_MOUSE);
|
||||
set_auto_mouse_enable(true);
|
||||
|
||||
pointing_device_init_keymap();
|
||||
}
|
||||
|
||||
__attribute__((weak)) report_mouse_t pointing_device_task_keymap(report_mouse_t mouse_report) {
|
||||
return mouse_report;
|
||||
}
|
||||
@ -26,28 +33,16 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
||||
mouse_report.x = 0;
|
||||
mouse_report.y = 0;
|
||||
|
||||
if (x != 0 && y != 0) {
|
||||
mouse_timer = timer_read();
|
||||
if (x != 0 && y != 0 && (timer_elapsed(mouse_debounce_timer) > TAP_CHECK)) {
|
||||
#ifdef OLED_ENABLE
|
||||
oled_timer_reset();
|
||||
#endif
|
||||
if (timer_elapsed(mouse_debounce_timer) > TAP_CHECK) {
|
||||
if (enable_acceleration) {
|
||||
x = (mouse_xy_report_t)(x > 0 ? x * x / 16 + x : -x * x / 16 + x);
|
||||
y = (mouse_xy_report_t)(y > 0 ? y * y / 16 + y : -y * y / 16 + y);
|
||||
}
|
||||
mouse_report.x = x;
|
||||
mouse_report.y = y;
|
||||
if (!layer_state_is(_MOUSE)) {
|
||||
layer_on(_MOUSE);
|
||||
}
|
||||
}
|
||||
} else if (timer_elapsed(mouse_timer) > 650 && layer_state_is(_MOUSE) && !mouse_keycode_tracker && !tap_toggling) {
|
||||
layer_off(_MOUSE);
|
||||
} else if (tap_toggling) {
|
||||
if (!layer_state_is(_MOUSE)) {
|
||||
layer_on(_MOUSE);
|
||||
if (enable_acceleration) {
|
||||
x = (mouse_xy_report_t)(x > 0 ? x * x / 16 + x : -x * x / 16 + x);
|
||||
y = (mouse_xy_report_t)(y > 0 ? y * y / 16 + y : -y * y / 16 + y);
|
||||
}
|
||||
mouse_report.x = x;
|
||||
mouse_report.y = y;
|
||||
}
|
||||
|
||||
return pointing_device_task_keymap(mouse_report);
|
||||
@ -55,64 +50,10 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
||||
|
||||
bool process_record_pointing(uint16_t keycode, keyrecord_t* record) {
|
||||
switch (keycode) {
|
||||
case TT(_MOUSE):
|
||||
if (record->event.pressed) {
|
||||
mouse_keycode_tracker++;
|
||||
} else {
|
||||
#if TAPPING_TOGGLE != 0
|
||||
if (record->tap.count == TAPPING_TOGGLE) {
|
||||
tap_toggling ^= 1;
|
||||
# if TAPPING_TOGGLE == 1
|
||||
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count + 1;
|
||||
# else
|
||||
if (!tap_toggling) mouse_keycode_tracker -= record->tap.count;
|
||||
# endif
|
||||
} else {
|
||||
mouse_keycode_tracker--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
mouse_timer = timer_read();
|
||||
break;
|
||||
case TG(_MOUSE):
|
||||
if (record->event.pressed) {
|
||||
tap_toggling ^= 1;
|
||||
}
|
||||
break;
|
||||
case MO(_MOUSE):
|
||||
#if defined(KEYBOARD_ploopy)
|
||||
case DPI_CONFIG:
|
||||
#elif (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && !defined(NO_CHARYBDIS_KEYCODES)
|
||||
case SAFE_RANGE ... (CHARYBDIS_SAFE_RANGE-1):
|
||||
#endif
|
||||
case KC_MS_UP ... KC_MS_WH_RIGHT:
|
||||
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
||||
mouse_timer = timer_read();
|
||||
break;
|
||||
case KC_ACCEL:
|
||||
enable_acceleration = record->event.pressed;
|
||||
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
||||
mouse_timer = timer_read();
|
||||
break;
|
||||
#if 0
|
||||
case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
|
||||
break;
|
||||
#endif
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
if (record->event.pressed || !record->tap.count) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (IS_NOEVENT(record->event)) break;
|
||||
if ((keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) && (((keycode >> 0x8) & 0xF) == _MOUSE)) {
|
||||
record->event.pressed ? mouse_keycode_tracker++ : mouse_keycode_tracker--;
|
||||
mouse_timer = timer_read();
|
||||
break;
|
||||
}
|
||||
if (layer_state_is(_MOUSE) && !mouse_keycode_tracker && !tap_toggling) {
|
||||
layer_off(_MOUSE);
|
||||
}
|
||||
mouse_keycode_tracker = 0;
|
||||
mouse_debounce_timer = timer_read();
|
||||
break;
|
||||
}
|
||||
@ -122,6 +63,32 @@ bool process_record_pointing(uint16_t keycode, keyrecord_t* record) {
|
||||
layer_state_t layer_state_set_pointing(layer_state_t state) {
|
||||
if (layer_state_cmp(state, _GAMEPAD) || layer_state_cmp(state, _DIABLO) || layer_state_cmp(state, _DIABLOII)) {
|
||||
state |= ((layer_state_t)1 << _MOUSE);
|
||||
set_auto_mouse_enable(false); // auto mouse can be disabled any time during run time
|
||||
} else {
|
||||
set_auto_mouse_enable(true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
||||
__attribute__((weak)) bool is_mouse_record_keymap(uint16_t keycode, keyrecord_t *record) { return false; }
|
||||
|
||||
bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record) {
|
||||
if (is_mouse_record_keymap(keycode, record)) {
|
||||
return true;
|
||||
}
|
||||
switch (keycode) {
|
||||
# if defined(KEYBOARD_ploopy)
|
||||
case DPI_CONFIG:
|
||||
# elif (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && !defined(NO_CHARYBDIS_KEYCODES)
|
||||
case SAFE_RANGE ...(CHARYBDIS_SAFE_RANGE - 1):
|
||||
# elif (defined(KEYBOARD_bastardkb_dilemma) && !defined(NO_DILEMMA_KEYCODES))
|
||||
case SAFE_RANGE ...(DILEMMA_SAFE_RANGE - 1):
|
||||
# endif
|
||||
case KC_ACCEL:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
#include "drashna.h"
|
||||
|
||||
void pointing_device_init_keymap(void);
|
||||
report_mouse_t pointing_device_task_keymap(report_mouse_t mouse_report);
|
||||
void matrix_scan_pointing(void);
|
||||
bool process_record_pointing(uint16_t keycode, keyrecord_t* record);
|
||||
layer_state_t layer_state_set_pointing(layer_state_t state);
|
||||
extern bool tap_toggling, enable_acceleration;
|
||||
|
@ -127,3 +127,7 @@
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SPLIT_KEYBOARD) && defined(PROTOCOL_CHIBIOS) && !defined(USB_SUSPEND_WAKEUP_DELAY)
|
||||
# define USB_SUSPEND_WAKEUP_DELAY 200
|
||||
#endif
|
||||
|
@ -9,9 +9,9 @@ ifneq ($(PLATFORM),CHIBIOS)
|
||||
ifneq ($(strip $(LTO_SUPPORTED)), no)
|
||||
LTO_ENABLE = yes
|
||||
endif
|
||||
SPACE_CADET_ENABLE = no
|
||||
GRAVE_ESC_ENABLE = no
|
||||
endif
|
||||
SPACE_CADET_ENABLE = no
|
||||
GRAVE_ESC_ENABLE = no
|
||||
# DEBUG_MATRIX_SCAN_RATE_ENABLE = api
|
||||
|
||||
ifneq ($(strip $(NO_SECRETS)), yes)
|
||||
@ -115,6 +115,7 @@ ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
|
||||
ifeq ($(strip $(CUSTOM_POINTING_DEVICE)), yes)
|
||||
SRC += $(USER_PATH)/pointing/pointing.c
|
||||
OPT_DEFS += -DCUSTOM_POINTING_DEVICE
|
||||
OPT_DEFS += -DPOINTING_DEVICE_AUTO_MOUSE_ENABLE
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -127,11 +128,8 @@ ifeq ($(strip $(CUSTOM_SPLIT_TRANSPORT_SYNC)), yes)
|
||||
|
||||
endif
|
||||
|
||||
AUTOCORRECTION_ENABLE ?= no
|
||||
ifeq ($(strip $(AUTOCORRECTION_ENABLE)), yes)
|
||||
SRC += $(USER_PATH)/keyrecords/autocorrection/autocorrection.c
|
||||
$(shell touch $(USER_PATH)/keyrecords/autocorrection/autocorrection.c)
|
||||
OPT_DEFS += -DAUTOCORRECTION_ENABLE
|
||||
AUTOCORRECT_ENABLE = yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes)
|
||||
|
@ -98,8 +98,8 @@ void user_transport_update(void) {
|
||||
#if defined(OLED_ENABLE) && !defined(SPLIT_OLED_ENABLE) && defined(CUSTOM_OLED_DRIVER)
|
||||
user_state.is_oled_enabled = is_oled_enabled;
|
||||
#endif
|
||||
#if defined(CUSTOM_POINTING_DEVICE)
|
||||
user_state.tap_toggling = tap_toggling;
|
||||
#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
||||
user_state.tap_toggling = get_auto_mouse_toggle();
|
||||
#endif
|
||||
#ifdef UNICODE_COMMON_ENABLE
|
||||
user_state.unicode_mode = unicode_config.input_mode;
|
||||
@ -122,8 +122,10 @@ void user_transport_update(void) {
|
||||
#if defined(OLED_ENABLE) && !defined(SPLIT_OLED_ENABLE) && defined(CUSTOM_OLED_DRIVER)
|
||||
is_oled_enabled = user_state.is_oled_enabled;
|
||||
#endif
|
||||
#if defined(CUSTOM_POINTING_DEVICE)
|
||||
tap_toggling = user_state.tap_toggling;
|
||||
#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
|
||||
if (get_auto_mouse_toggle() != user_state.tap_toggling) {
|
||||
auto_mouse_toggle();
|
||||
}
|
||||
#endif
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
swap_hands = user_state.swap_hands;
|
||||
|
Reference in New Issue
Block a user