summaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_auto_shift.c7
-rw-r--r--quantum/process_keycode/process_combo.c11
-rw-r--r--quantum/process_keycode/process_joystick.c36
-rw-r--r--quantum/process_keycode/process_secure.c39
-rw-r--r--quantum/process_keycode/process_secure.h15
-rw-r--r--quantum/process_keycode/process_space_cadet.c7
-rw-r--r--quantum/process_keycode/process_tap_dance.c6
-rw-r--r--quantum/process_keycode/process_unicode_common.c63
-rw-r--r--quantum/process_keycode/process_unicode_common.h1
9 files changed, 70 insertions, 115 deletions
diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c
index 2150edd7b2..e6a7c01f2a 100644
--- a/quantum/process_keycode/process_auto_shift.c
+++ b/quantum/process_keycode/process_auto_shift.c
@@ -182,12 +182,7 @@ static bool autoshift_press(uint16_t keycode, uint16_t now, keyrecord_t *record)
# endif
) &&
# endif
- TIMER_DIFF_16(now, autoshift_time) <
-# ifdef TAPPING_TERM_PER_KEY
- get_tapping_term(autoshift_lastkey, record)
-# else
- TAPPING_TERM
-# endif
+ TIMER_DIFF_16(now, autoshift_time) < GET_TAPPING_TERM(autoshift_lastkey, record)
) {
// clang-format on
// Allow a tap-then-hold for keyrepeat.
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c
index efaf8fe0e9..d5a649adb3 100644
--- a/quantum/process_keycode/process_combo.c
+++ b/quantum/process_keycode/process_combo.c
@@ -88,8 +88,6 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
#define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH
-#define COMBO_KEY_POS ((keypos_t){.col = 254, .row = 254})
-
#ifndef EXTRA_SHORT_COMBOS
/* flags are their own elements in combo_t struct. */
# define COMBO_ACTIVE(combo) (combo->active)
@@ -140,12 +138,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
static inline void release_combo(uint16_t combo_index, combo_t *combo) {
if (combo->keycode) {
keyrecord_t record = {
- .event =
- {
- .key = COMBO_KEY_POS,
- .time = timer_read() | 1,
- .pressed = false,
- },
+ .event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false),
.keycode = combo->keycode,
};
#ifndef NO_ACTION_TAPPING
@@ -325,7 +318,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) {
// this in the end executes the combo when the key_buffer is dumped.
record->keycode = combo->keycode;
- record->event.key = COMBO_KEY_POS;
+ record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO);
qrecord->combo_index = combo_index;
ACTIVATE_COMBO(combo);
diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c
index 2fb092c573..8c3e71616f 100644
--- a/quantum/process_keycode/process_joystick.c
+++ b/quantum/process_keycode/process_joystick.c
@@ -6,41 +6,25 @@
#include <string.h>
#include <math.h>
-bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record);
-
bool process_joystick(uint16_t keycode, keyrecord_t *record) {
- if (process_joystick_buttons(keycode, record) && (joystick_status.status & JS_UPDATED) > 0) {
- send_joystick_packet(&joystick_status);
- joystick_status.status &= ~JS_UPDATED;
+ switch (keycode) {
+ case JS_BUTTON0 ... JS_BUTTON_MAX:
+ if (record->event.pressed) {
+ register_joystick_button(keycode - JS_BUTTON0);
+ } else {
+ unregister_joystick_button(keycode - JS_BUTTON0);
+ }
+ return false;
}
-
return true;
}
__attribute__((weak)) void joystick_task(void) {
- if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) {
- send_joystick_packet(&joystick_status);
- joystick_status.status &= ~JS_UPDATED;
+ if (process_joystick_analogread()) {
+ joystick_flush();
}
}
-bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record) {
- if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX) {
- return true;
- } else {
- uint8_t button_idx = (keycode - JS_BUTTON0);
- if (record->event.pressed) {
- joystick_status.buttons[button_idx / 8] |= 1 << (button_idx % 8);
- } else {
- joystick_status.buttons[button_idx / 8] &= ~(1 << (button_idx % 8));
- }
-
- joystick_status.status |= JS_UPDATED;
- }
-
- return true;
-}
-
uint16_t savePinState(pin_t pin) {
#ifdef __AVR__
uint8_t pinNumber = pin & 0xF;
diff --git a/quantum/process_keycode/process_secure.c b/quantum/process_keycode/process_secure.c
new file mode 100644
index 0000000000..827ace597a
--- /dev/null
+++ b/quantum/process_keycode/process_secure.c
@@ -0,0 +1,39 @@
+// Copyright 2022 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "secure.h"
+#include "process_secure.h"
+#include "quantum_keycodes.h"
+
+bool preprocess_secure(uint16_t keycode, keyrecord_t *record) {
+ if (secure_is_unlocking()) {
+ if (!record->event.pressed) {
+ secure_keypress_event(record->event.key.row, record->event.key.col);
+ }
+
+ // Normal keypresses should be disabled until the sequence is completed
+ return false;
+ }
+
+ return true;
+}
+
+bool process_secure(uint16_t keycode, keyrecord_t *record) {
+#ifndef SECURE_DISABLE_KEYCODES
+ if (!record->event.pressed) {
+ if (keycode == SECURE_LOCK) {
+ secure_lock();
+ return false;
+ }
+ if (keycode == SECURE_UNLOCK) {
+ secure_unlock();
+ return false;
+ }
+ if (keycode == SECURE_TOGGLE) {
+ secure_is_locked() ? secure_unlock() : secure_lock();
+ return false;
+ }
+ }
+#endif
+ return true;
+} \ No newline at end of file
diff --git a/quantum/process_keycode/process_secure.h b/quantum/process_keycode/process_secure.h
new file mode 100644
index 0000000000..2814264b92
--- /dev/null
+++ b/quantum/process_keycode/process_secure.h
@@ -0,0 +1,15 @@
+// Copyright 2022 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <stdbool.h>
+#include "action.h"
+
+/** \brief Intercept keycodes and detect unlock sequences
+ */
+bool preprocess_secure(uint16_t keycode, keyrecord_t *record);
+
+/** \brief Handle any secure specific keycodes
+ */
+bool process_secure(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c
index 46b2648c35..0997e7b7f3 100644
--- a/quantum/process_keycode/process_space_cadet.c
+++ b/quantum/process_keycode/process_space_cadet.c
@@ -93,12 +93,7 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM
register_mods(MOD_BIT(holdMod));
}
} else {
-#ifdef TAPPING_TERM_PER_KEY
- if (sc_last == holdMod && timer_elapsed(sc_timer) < get_tapping_term(sc_keycode, record))
-#else
- if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM)
-#endif
- {
+ if (sc_last == holdMod && timer_elapsed(sc_timer) < GET_TAPPING_TERM(sc_keycode, record)) {
if (holdMod != tapMod) {
if (IS_MOD(holdMod)) {
unregister_mods(MOD_BIT(holdMod));
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index e99119b2ae..db8df5f870 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -174,11 +174,7 @@ void tap_dance_task() {
if (action->custom_tapping_term > 0) {
tap_user_defined = action->custom_tapping_term;
} else {
-#ifdef TAPPING_TERM_PER_KEY
- tap_user_defined = get_tapping_term(action->state.keycode, &(keyrecord_t){});
-#else
- tap_user_defined = TAPPING_TERM;
-#endif
+ tap_user_defined = GET_TAPPING_TERM(action->state.keycode, &(keyrecord_t){});
}
if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) {
process_tap_dance_action_on_dance_finished(action);
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index 46b77e14ba..652becbc9a 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -16,8 +16,7 @@
#include "process_unicode_common.h"
#include "eeprom.h"
-#include <ctype.h>
-#include <string.h>
+#include "utf8.h"
unicode_config_t unicode_config;
uint8_t unicode_saved_mods;
@@ -231,66 +230,6 @@ void register_unicode(uint32_t code_point) {
unicode_input_finish();
}
-// clang-format off
-
-void send_unicode_hex_string(const char *str) {
- if (!str) {
- return;
- }
-
- while (*str) {
- // Find the next code point (token) in the string
- for (; *str == ' '; str++); // Skip leading spaces
- size_t n = strcspn(str, " "); // Length of the current token
- char code_point[n+1];
- strncpy(code_point, str, n); // Copy token into buffer
- code_point[n] = '\0'; // Make sure it's null-terminated
-
- // Normalize the code point: make all hex digits lowercase
- for (char *p = code_point; *p; p++) {
- *p = tolower((unsigned char)*p);
- }
-
- // Send the code point as a Unicode input string
- unicode_input_start();
- send_string(code_point);
- unicode_input_finish();
-
- str += n; // Move to the first ' ' (or '\0') after the current token
- }
-}
-
-// clang-format on
-
-// Borrowed from https://nullprogram.com/blog/2017/10/06/
-static const char *decode_utf8(const char *str, int32_t *code_point) {
- const char *next;
-
- if (str[0] < 0x80) { // U+0000-007F
- *code_point = str[0];
- next = str + 1;
- } else if ((str[0] & 0xE0) == 0xC0) { // U+0080-07FF
- *code_point = ((int32_t)(str[0] & 0x1F) << 6) | ((int32_t)(str[1] & 0x3F) << 0);
- next = str + 2;
- } else if ((str[0] & 0xF0) == 0xE0) { // U+0800-FFFF
- *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0);
- next = str + 3;
- } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF
- *code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0);
- next = str + 4;
- } else {
- *code_point = -1;
- next = str + 1;
- }
-
- // part of a UTF-16 surrogate pair - invalid
- if (*code_point >= 0xD800 && *code_point <= 0xDFFF) {
- *code_point = -1;
- }
-
- return next;
-}
-
void send_unicode_string(const char *str) {
if (!str) {
return;
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h
index 1a6607c757..8a4494c939 100644
--- a/quantum/process_keycode/process_unicode_common.h
+++ b/quantum/process_keycode/process_unicode_common.h
@@ -90,7 +90,6 @@ void register_hex(uint16_t hex);
void register_hex32(uint32_t hex);
void register_unicode(uint32_t code_point);
-void send_unicode_hex_string(const char *str);
void send_unicode_string(const char *str);
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);