Upstream merge up to 02d44beb44

This commit is contained in:
jonathan.liu
2019-07-11 23:21:18 -07:00
parent a0fac849eb
commit 441b212c86
4854 changed files with 157570 additions and 41535 deletions
+14 -12
View File
@@ -32,7 +32,7 @@ extern bool midi_activated;
void clicky_play(void) {
#ifndef NO_MUSIC_MODE
if (music_activated || midi_activated) return;
if (music_activated || midi_activated || !audio_config.enable) return;
#endif // !NO_MUSIC_MODE
clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
clicky_song[1][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
@@ -73,27 +73,29 @@ void clicky_off(void) {
}
bool is_clicky_on(void) {
return (audio_config.clicky_enable != 0);
return (audio_config.clicky_enable != 0);
}
bool process_clicky(uint16_t keycode, keyrecord_t *record) {
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
if ( audio_config.clicky_enable ) {
if (record->event.pressed) {
clicky_play();;
if (audio_config.enable && audio_config.clicky_enable) {
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
clicky_play();
}
}
return true;
}
return true;
}
#endif //AUDIO_CLICKY
+134 -111
View File
@@ -14,141 +14,164 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "process_combo.h"
#include "print.h"
#include "process_combo.h"
#define COMBO_TIMER_ELAPSED -1
__attribute__ ((weak))
combo_t key_combos[COMBO_COUNT] = {
__attribute__((weak)) combo_t key_combos[COMBO_COUNT] = {
};
__attribute__ ((weak))
void process_combo_event(uint8_t combo_index, bool pressed) {
}
__attribute__((weak)) void process_combo_event(uint8_t combo_index,
bool pressed) {}
static uint16_t timer = 0;
static uint8_t current_combo_index = 0;
static bool drop_buffer = false;
static bool is_active = false;
static inline void send_combo(uint16_t action, bool pressed)
{
if (action) {
if (pressed) {
register_code16(action);
} else {
unregister_code16(action);
}
static uint8_t buffer_size = 0;
#ifdef COMBO_ALLOW_ACTION_KEYS
static keyrecord_t key_buffer[MAX_COMBO_LENGTH];
#else
static uint16_t key_buffer[MAX_COMBO_LENGTH];
#endif
static inline void send_combo(uint16_t action, bool pressed) {
if (action) {
if (pressed) {
register_code16(action);
} else {
process_combo_event(current_combo_index, pressed);
unregister_code16(action);
}
} else {
process_combo_event(current_combo_index, pressed);
}
}
#define ALL_COMBO_KEYS_ARE_DOWN (((1<<count)-1) == combo->state)
#define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state)
#define KEY_STATE_DOWN(key) do{ combo->state |= (1<<key); } while(0)
#define KEY_STATE_UP(key) do{ combo->state &= ~(1<<key); } while(0)
static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record)
{
uint8_t count = 0;
uint8_t index = -1;
/* Find index of keycode and number of combo keys */
for (const uint16_t *keys = combo->keys; ;++count) {
uint16_t key = pgm_read_word(&keys[count]);
if (keycode == key) index = count;
if (COMBO_END == key) break;
}
static inline void dump_key_buffer(bool emit) {
if (buffer_size == 0) {
return;
}
/* Return if not a combo key */
if (-1 == (int8_t)index) return false;
/* The combos timer is used to signal whether the combo is active */
bool is_combo_active = COMBO_TIMER_ELAPSED == combo->timer ? false : true;
if (record->event.pressed) {
KEY_STATE_DOWN(index);
if (is_combo_active) {
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
send_combo(combo->keycode, true);
combo->timer = COMBO_TIMER_ELAPSED;
} else { /* Combo key was pressed */
combo->timer = timer_read();
if (emit) {
for (uint8_t i = 0; i < buffer_size; i++) {
#ifdef COMBO_ALLOW_ACTION_KEYS
combo->prev_record = *record;
const action_t action = store_or_get_action(key_buffer[i].event.pressed,
key_buffer[i].event.key);
process_action(&(key_buffer[i]), action);
#else
combo->prev_key = keycode;
register_code16(key_buffer[i]);
send_keyboard_report();
#endif
}
}
}
}
buffer_size = 0;
}
#define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state)
#define KEY_STATE_DOWN(key) \
do { \
combo->state |= (1 << key); \
} while (0)
#define KEY_STATE_UP(key) \
do { \
combo->state &= ~(1 << key); \
} while (0)
static bool process_single_combo(combo_t *combo, uint16_t keycode,
keyrecord_t *record) {
uint8_t count = 0;
uint8_t index = -1;
/* Find index of keycode and number of combo keys */
for (const uint16_t *keys = combo->keys;; ++count) {
uint16_t key = pgm_read_word(&keys[count]);
if (keycode == key)
index = count;
if (COMBO_END == key)
break;
}
/* Continue processing if not a combo key */
if (-1 == (int8_t)index)
return false;
bool is_combo_active = is_active;
if (record->event.pressed) {
KEY_STATE_DOWN(index);
if (is_combo_active) {
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
send_combo(combo->keycode, true);
drop_buffer = true;
}
}
} else {
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
send_combo(combo->keycode, false);
} else {
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
send_combo(combo->keycode, false);
}
/* continue processing without immediately returning */
is_combo_active = false;
}
if (is_combo_active) { /* Combo key was tapped */
KEY_STATE_UP(index);
}
return is_combo_active;
}
#define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state)
bool process_combo(uint16_t keycode, keyrecord_t *record) {
bool is_combo_key = false;
drop_buffer = false;
bool no_combo_keys_pressed = false;
for (current_combo_index = 0; current_combo_index < COMBO_COUNT;
++current_combo_index) {
combo_t *combo = &key_combos[current_combo_index];
is_combo_key |= process_single_combo(combo, keycode, record);
no_combo_keys_pressed |= NO_COMBO_KEYS_ARE_DOWN;
}
if (drop_buffer) {
/* buffer is only dropped when we complete a combo, so we refresh the timer
* here */
timer = timer_read();
dump_key_buffer(false);
} else if (!is_combo_key) {
/* if no combos claim the key we need to emit the keybuffer */
dump_key_buffer(true);
// reset state if there are no combo keys pressed at all
if (no_combo_keys_pressed) {
timer = 0;
is_active = true;
}
} else if (record->event.pressed && is_active) {
/* otherwise the key is consumed and placed in the buffer */
timer = timer_read();
if (buffer_size < MAX_COMBO_LENGTH) {
#ifdef COMBO_ALLOW_ACTION_KEYS
record->event.pressed = true;
process_action(record, store_or_get_action(record->event.pressed, record->event.key));
record->event.pressed = false;
process_action(record, store_or_get_action(record->event.pressed, record->event.key));
key_buffer[buffer_size++] = *record;
#else
register_code16(keycode);
send_keyboard_report();
unregister_code16(keycode);
key_buffer[buffer_size++] = keycode;
#endif
combo->timer = 0;
}
KEY_STATE_UP(index);
}
}
if (NO_COMBO_KEYS_ARE_DOWN) {
combo->timer = 0;
}
return is_combo_active;
return !is_combo_key;
}
bool process_combo(uint16_t keycode, keyrecord_t *record)
{
bool is_combo_key = false;
void matrix_scan_combo(void) {
if (is_active && timer && timer_elapsed(timer) > COMBO_TERM) {
for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) {
combo_t *combo = &key_combos[current_combo_index];
is_combo_key |= process_single_combo(combo, keycode, record);
}
return !is_combo_key;
}
void matrix_scan_combo(void)
{
for (int i = 0; i < COMBO_COUNT; ++i) {
// Do not treat the (weak) key_combos too strict.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
combo_t *combo = &key_combos[i];
#pragma GCC diagnostic pop
if (combo->timer &&
combo->timer != COMBO_TIMER_ELAPSED &&
timer_elapsed(combo->timer) > COMBO_TERM) {
/* This disables the combo, meaning key events for this
* combo will be handled by the next processors in the chain
*/
combo->timer = COMBO_TIMER_ELAPSED;
#ifdef COMBO_ALLOW_ACTION_KEYS
process_action(&combo->prev_record,
store_or_get_action(combo->prev_record.event.pressed,
combo->prev_record.event.key));
#else
unregister_code16(combo->prev_key);
register_code16(combo->prev_key);
#endif
}
}
/* This disables the combo, meaning key events for this
* combo will be handled by the next processors in the chain
*/
is_active = false;
dump_key_buffer(true);
}
}
+17 -15
View File
@@ -17,32 +17,34 @@
#ifndef PROCESS_COMBO_H
#define PROCESS_COMBO_H
#include <stdint.h>
#include "progmem.h"
#include "quantum.h"
#include <stdint.h>
typedef struct
{
const uint16_t *keys;
uint16_t keycode;
#ifdef EXTRA_EXTRA_LONG_COMBOS
uint32_t state;
#define MAX_COMBO_LENGTH 32
#elif EXTRA_LONG_COMBOS
uint16_t state;
#define MAX_COMBO_LENGTH 16
#else
uint8_t state;
#define MAX_COMBO_LENGTH 8
#endif
uint16_t timer;
#ifdef COMBO_ALLOW_ACTION_KEYS
keyrecord_t prev_record;
typedef struct {
const uint16_t *keys;
uint16_t keycode;
#ifdef EXTRA_EXTRA_LONG_COMBOS
uint32_t state;
#elif EXTRA_LONG_COMBOS
uint16_t state;
#else
uint16_t prev_key;
uint8_t state;
#endif
} combo_t;
#define COMBO(ck, ca) {.keys = &(ck)[0], .keycode = (ca)}
#define COMBO_ACTION(ck) {.keys = &(ck)[0]}
#define COMBO(ck, ca) \
{ .keys = &(ck)[0], .keycode = (ca) }
#define COMBO_ACTION(ck) \
{ .keys = &(ck)[0] }
#define COMBO_END 0
#ifndef COMBO_COUNT
+31 -16
View File
@@ -35,25 +35,40 @@ uint16_t leader_time = 0;
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
uint8_t leader_sequence_size = 0;
void qk_leader_start(void) {
if (leading) { return; }
leader_start();
leading = true;
leader_time = timer_read();
leader_sequence_size = 0;
leader_sequence[0] = 0;
leader_sequence[1] = 0;
leader_sequence[2] = 0;
leader_sequence[3] = 0;
leader_sequence[4] = 0;
}
bool process_leader(uint16_t keycode, keyrecord_t *record) {
// Leader key set-up
if (record->event.pressed) {
if (!leading && keycode == KC_LEAD) {
leader_start();
leading = true;
leader_time = timer_read();
leader_sequence_size = 0;
leader_sequence[0] = 0;
leader_sequence[1] = 0;
leader_sequence[2] = 0;
leader_sequence[3] = 0;
leader_sequence[4] = 0;
return false;
}
if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
leader_sequence[leader_sequence_size] = keycode;
leader_sequence_size++;
return false;
if (leading) {
if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
#ifndef LEADER_KEY_STRICT_KEY_PROCESSING
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
keycode = keycode & 0xFF;
}
#endif // LEADER_KEY_STRICT_KEY_PROCESSING
leader_sequence[leader_sequence_size] = keycode;
leader_sequence_size++;
#ifdef LEADER_PER_KEY_TIMING
leader_time = timer_read();
#endif
return false;
}
} else {
if (keycode == KC_LEAD) {
qk_leader_start();
}
}
}
return true;
+1 -1
View File
@@ -24,7 +24,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record);
void leader_start(void);
void leader_end(void);
void qk_leader_start(void);
#define SEQ_ONE_KEY(key) if (leader_sequence[0] == (key) && leader_sequence[1] == 0 && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0)
#define SEQ_TWO_KEYS(key1, key2) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == 0 && leader_sequence[3] == 0 && leader_sequence[4] == 0)
+24 -22
View File
@@ -114,13 +114,13 @@ static void send_steno_chord(void) {
if (send_steno_chord_user(mode, chord)) {
switch(mode) {
case STENO_MODE_BOLT:
send_steno_state(BOLT_STATE_SIZE, false);
virtser_send(0); // terminating byte
break;
send_steno_state(BOLT_STATE_SIZE, false);
virtser_send(0); // terminating byte
break;
case STENO_MODE_GEMINI:
chord[0] |= 0x80; // Indicate start of packet
send_steno_state(GEMINI_STATE_SIZE, true);
break;
chord[0] |= 0x80; // Indicate start of packet
send_steno_state(GEMINI_STATE_SIZE, true);
break;
}
}
steno_clear_state();
@@ -161,7 +161,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case QK_STENO_BOLT:
if (!process_steno_user(keycode, record)) {
return false;
return false;
}
if (IS_PRESSED(record->event)) {
steno_set_mode(STENO_MODE_BOLT);
@@ -170,7 +170,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
case QK_STENO_GEMINI:
if (!process_steno_user(keycode, record)) {
return false;
return false;
}
if (IS_PRESSED(record->event)) {
steno_set_mode(STENO_MODE_GEMINI);
@@ -179,25 +179,27 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
case STN__MIN...STN__MAX:
if (!process_steno_user(keycode, record)) {
return false;
return false;
}
switch(mode) {
case STENO_MODE_BOLT:
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
case STENO_MODE_GEMINI:
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
case STENO_MODE_BOLT:
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
break;
case STENO_MODE_GEMINI:
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
break;
}
// allow postprocessing hooks
if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
if (IS_PRESSED(record->event)) {
++pressed;
} else {
--pressed;
if (pressed <= 0) {
pressed = 0;
send_steno_chord();
}
}
if (IS_PRESSED(record->event)) {
++pressed;
} else {
--pressed;
if (pressed <= 0) {
pressed = 0;
send_steno_chord();
}
}
}
return false;
}
@@ -131,6 +131,7 @@ void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
if (keycode == action->state.keycode && keycode == last_td)
continue;
action->state.interrupted = true;
action->state.interrupting_keycode = keycode;
process_tap_dance_action_on_dance_finished (action);
reset_tap_dance (&action->state);
}
@@ -209,5 +210,6 @@ void reset_tap_dance (qk_tap_dance_state_t *state) {
state->count = 0;
state->interrupted = false;
state->finished = false;
state->interrupting_keycode = 0;
last_td = 0;
}
@@ -27,6 +27,7 @@ typedef struct
uint8_t oneshot_mods;
uint8_t weak_mods;
uint16_t keycode;
uint16_t interrupting_keycode;
uint16_t timer;
bool interrupted;
bool pressed;
@@ -273,11 +273,17 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) {
disable_terminal();
return false;
}
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
keycode = keycode & 0xFF;
}
if (keycode < 256) {
uint8_t str_len;
char char_to_add;
switch (keycode) {
case KC_ENTER:
case KC_KP_ENTER:
push_to_cmd_buffer();
current_cmd_buffer_pos = 0;
process_terminal_command();
-2
View File
@@ -95,8 +95,6 @@ void register_ucis(const char *hex) {
bool process_ucis (uint16_t keycode, keyrecord_t *record) {
uint8_t i;
unicode_input_mode_init();
if (!qk_ucis_state.in_progress)
return true;
+1 -4
View File
@@ -14,8 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_UCIS_H
#define PROCESS_UCIS_H
#pragma once
#include "quantum.h"
#include "process_unicode_common.h"
@@ -48,5 +47,3 @@ void qk_ucis_symbol_fallback (void);
void qk_ucis_success(uint8_t symbol_index);
void register_ucis(const char *hex);
bool process_ucis (uint16_t keycode, keyrecord_t *record);
#endif
@@ -20,11 +20,9 @@
bool process_unicode(uint16_t keycode, keyrecord_t *record) {
if (keycode > QK_UNICODE && record->event.pressed) {
uint16_t unicode = keycode & 0x7FFF;
unicode_input_mode_init();
unicode_input_start();
register_hex(unicode);
unicode_input_finish();
}
return true;
}
+1 -4
View File
@@ -13,12 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_UNICODE_H
#define PROCESS_UNICODE_H
#pragma once
#include "quantum.h"
#include "process_unicode_common.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record);
#endif
+137 -64
View File
@@ -16,98 +16,114 @@
#include "process_unicode_common.h"
#include "eeprom.h"
#include <string.h>
#include <ctype.h>
#include <string.h>
static uint8_t input_mode;
uint8_t mods;
unicode_config_t unicode_config;
#if UNICODE_SELECTED_MODES != -1
static uint8_t selected[] = { UNICODE_SELECTED_MODES };
static uint8_t selected_count = sizeof selected / sizeof *selected;
static uint8_t selected_index;
#endif
void set_unicode_input_mode(uint8_t os_target) {
input_mode = os_target;
eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
void unicode_input_mode_init(void) {
unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
#if UNICODE_SELECTED_MODES != -1
#if UNICODE_CYCLE_PERSIST
// Find input_mode in selected modes
uint8_t i;
for (i = 0; i < selected_count; i++) {
if (selected[i] == unicode_config.input_mode) {
selected_index = i;
break;
}
}
if (i == selected_count) {
// Not found: input_mode isn't selected, change to one that is
unicode_config.input_mode = selected[selected_index = 0];
}
#else
// Always change to the first selected input mode
unicode_config.input_mode = selected[selected_index = 0];
#endif
#endif
dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
}
uint8_t get_unicode_input_mode(void) {
return input_mode;
return unicode_config.input_mode;
}
void unicode_input_mode_init(void) {
static bool first_flag = false;
if (!first_flag) {
input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE);
first_flag = true;
}
void set_unicode_input_mode(uint8_t mode) {
unicode_config.input_mode = mode;
persist_unicode_input_mode();
dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
}
void cycle_unicode_input_mode(uint8_t offset) {
#if UNICODE_SELECTED_MODES != -1
selected_index = (selected_index + offset) % selected_count;
unicode_config.input_mode = selected[selected_index];
#if UNICODE_CYCLE_PERSIST
persist_unicode_input_mode();
#endif
dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
#endif
}
void persist_unicode_input_mode(void) {
eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode);
}
static uint8_t saved_mods;
__attribute__((weak))
void unicode_input_start (void) {
// save current mods
mods = keyboard_report->mods;
void unicode_input_start(void) {
saved_mods = get_mods(); // Save current mods
clear_mods(); // Unregister mods to start from a clean state
// unregister all mods to start from clean state
if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
switch(input_mode) {
switch (unicode_config.input_mode) {
case UC_OSX:
register_code(KC_LALT);
break;
case UC_OSX_RALT:
register_code(KC_RALT);
register_code(UNICODE_OSX_KEY);
break;
case UC_LNX:
register_code(KC_LCTL);
register_code(KC_LSFT);
register_code(KC_U);
unregister_code(KC_U);
tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test
unregister_code(KC_LSFT);
unregister_code(KC_LCTL);
break;
case UC_WIN:
register_code(KC_LALT);
register_code(KC_PPLS);
unregister_code(KC_PPLS);
tap_code(KC_PPLS);
break;
case UC_WINC:
register_code(KC_RALT);
unregister_code(KC_RALT);
register_code(KC_U);
unregister_code(KC_U);
tap_code(UNICODE_WINC_KEY);
tap_code(KC_U);
break;
}
wait_ms(UNICODE_TYPE_DELAY);
}
__attribute__((weak))
void unicode_input_finish (void) {
switch(input_mode) {
case UC_OSX:
case UC_WIN:
unregister_code(KC_LALT);
break;
case UC_OSX_RALT:
unregister_code(KC_RALT);
break;
case UC_LNX:
register_code(KC_SPC);
unregister_code(KC_SPC);
break;
void unicode_input_finish(void) {
switch (unicode_config.input_mode) {
case UC_OSX:
unregister_code(UNICODE_OSX_KEY);
break;
case UC_LNX:
tap_code(KC_SPC);
break;
case UC_WIN:
unregister_code(KC_LALT);
break;
case UC_WINC:
tap_code(KC_ENTER);
break;
}
// reregister previously set mods
if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
set_mods(saved_mods); // Reregister previously set mods
}
__attribute__((weak))
@@ -124,13 +140,12 @@ uint16_t hex_to_keycode(uint8_t hex) {
void register_hex(uint16_t hex) {
for(int i = 3; i >= 0; i--) {
uint8_t digit = ((hex >> (i*4)) & 0xF);
register_code(hex_to_keycode(digit));
unregister_code(hex_to_keycode(digit));
tap_code(hex_to_keycode(digit));
}
}
void send_unicode_hex_string(const char *str) {
if (!str) { return; } // Safety net
if (!str) { return; }
while (*str) {
// Find the next code point (token) in the string
@@ -153,3 +168,61 @@ void send_unicode_hex_string(const char *str) {
str += n; // Move to the first ' ' (or '\0') after the current token
}
}
bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case UNICODE_MODE_FORWARD:
cycle_unicode_input_mode(+1);
break;
case UNICODE_MODE_REVERSE:
cycle_unicode_input_mode(-1);
break;
case UNICODE_MODE_OSX:
set_unicode_input_mode(UC_OSX);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX)
static float song_osx[][2] = UNICODE_SONG_OSX;
PLAY_SONG(song_osx);
#endif
break;
case UNICODE_MODE_LNX:
set_unicode_input_mode(UC_LNX);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
static float song_lnx[][2] = UNICODE_SONG_LNX;
PLAY_SONG(song_lnx);
#endif
break;
case UNICODE_MODE_WIN:
set_unicode_input_mode(UC_WIN);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
static float song_win[][2] = UNICODE_SONG_WIN;
PLAY_SONG(song_win);
#endif
break;
case UNICODE_MODE_BSD:
set_unicode_input_mode(UC_BSD);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
static float song_bsd[][2] = UNICODE_SONG_BSD;
PLAY_SONG(song_bsd);
#endif
break;
case UNICODE_MODE_WINC:
set_unicode_input_mode(UC_WINC);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
static float song_winc[][2] = UNICODE_SONG_WINC;
PLAY_SONG(song_winc);
#endif
break;
}
}
#if defined(UNICODE_ENABLE)
return process_unicode(keycode, record);
#elif defined(UNICODEMAP_ENABLE)
return process_unicodemap(keycode, record);
#elif defined(UCIS_ENABLE)
return process_ucis(keycode, record);
#else
return true;
#endif
}
@@ -14,35 +14,71 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_UNICODE_COMMON_H
#define PROCESS_UNICODE_COMMON_H
#pragma once
#include "quantum.h"
#ifndef UNICODE_TYPE_DELAY
#define UNICODE_TYPE_DELAY 10
#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
#error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
#endif
__attribute__ ((unused))
static uint8_t input_mode;
// Keycodes used for starting Unicode input on different platforms
#ifndef UNICODE_OSX_KEY
#define UNICODE_OSX_KEY KC_LALT
#endif
#ifndef UNICODE_WINC_KEY
#define UNICODE_WINC_KEY KC_RALT
#endif
// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
#ifndef UNICODE_SELECTED_MODES
#define UNICODE_SELECTED_MODES -1
#endif
// Whether input mode changes in cycle should be written to EEPROM
#ifndef UNICODE_CYCLE_PERSIST
#define UNICODE_CYCLE_PERSIST true
#endif
// Delay between starting Unicode input and sending a sequence, in ms
#ifndef UNICODE_TYPE_DELAY
#define UNICODE_TYPE_DELAY 10
#endif
enum unicode_input_modes {
UC_OSX, // Mac OS X using Unicode Hex Input
UC_LNX, // Linux using IBus
UC_WIN, // Windows using EnableHexNumpad
UC_BSD, // BSD (not implemented)
UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
UC__COUNT // Number of available input modes (always leave at the end)
};
typedef union {
uint32_t raw;
struct {
uint8_t input_mode : 8;
};
} unicode_config_t;
extern unicode_config_t unicode_config;
void set_unicode_input_mode(uint8_t os_target);
uint8_t get_unicode_input_mode(void);
void unicode_input_mode_init(void);
uint8_t get_unicode_input_mode(void);
void set_unicode_input_mode(uint8_t mode);
void cycle_unicode_input_mode(uint8_t offset);
void persist_unicode_input_mode(void);
void unicode_input_start(void);
void unicode_input_finish(void);
void register_hex(uint16_t hex);
void send_unicode_hex_string(const char *str);
#define UC_OSX 0 // Mac OS X
#define UC_LNX 1 // Linux
#define UC_WIN 2 // Windows 'HexNumpad'
#define UC_BSD 3 // BSD (not implemented)
#define UC_WINC 4 // WinCompose https://github.com/samhocevar/wincompose
#define UC_OSX_RALT 5 // Mac OS X using Right Alt key for Unicode Compose
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
#define UC_BSPC UC(0x0008)
#define UC_SPC UC(0x0020)
#define UC_EXLM UC(0x0021)
@@ -147,5 +183,3 @@ void send_unicode_hex_string(const char *str);
#define UC_RCBR UC(0x007D)
#define UC_TILD UC(0x007E)
#define UC_DEL UC(0x007F)
#endif
+15 -20
View File
@@ -17,10 +17,6 @@
#include "process_unicodemap.h"
#include "process_unicode_common.h"
__attribute__((weak))
const uint32_t PROGMEM unicode_map[] = {
};
void register_hex32(uint32_t hex) {
bool onzerostart = true;
for(int i = 7; i >= 0; i--) {
@@ -42,27 +38,26 @@ void register_hex32(uint32_t hex) {
}
__attribute__((weak))
void unicode_map_input_error() {}
void unicodemap_input_error() {}
bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
unicode_input_mode_init();
uint8_t input_mode = get_unicode_input_mode();
if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
const uint32_t* map = unicode_map;
uint16_t index = keycode - QK_UNICODE_MAP;
uint32_t code = pgm_read_dword(&map[index]);
if (code > 0xFFFF && code <= 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) {
bool process_unicodemap(uint16_t keycode, keyrecord_t *record) {
if ((keycode & QK_UNICODEMAP) == QK_UNICODEMAP && record->event.pressed) {
uint16_t index = keycode - QK_UNICODEMAP;
uint32_t code = pgm_read_dword(unicode_map + index);
uint8_t input_mode = get_unicode_input_mode();
if (code > 0xFFFF && code <= 0x10FFFF && input_mode == UC_OSX) {
// Convert to UTF-16 surrogate pair
code -= 0x10000;
uint32_t lo = code & 0x3ff;
uint32_t hi = (code & 0xffc00) >> 10;
uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10;
unicode_input_start();
register_hex32(hi + 0xd800);
register_hex32(lo + 0xdc00);
register_hex32(hi + 0xD800);
register_hex32(lo + 0xDC00);
unicode_input_finish();
} else if ((code > 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) || (code > 0xFFFFF && input_mode == UC_LNX)) {
// when character is out of range supported by the OS
unicode_map_input_error();
} else if ((code > 0x10FFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
// Character is out of range supported by the OS
unicodemap_input_error();
} else {
unicode_input_start();
register_hex32(code);
+5 -5
View File
@@ -14,12 +14,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_UNICODEMAP_H
#define PROCESS_UNICODEMAP_H
#pragma once
#include "quantum.h"
#include "process_unicode_common.h"
void unicode_map_input_error(void);
bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
#endif
extern const uint32_t PROGMEM unicode_map[];
void unicodemap_input_error(void);
bool process_unicodemap(uint16_t keycode, keyrecord_t *record);