From b01d34e1dd930c326ef3a0515ca51f0671b3b200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Tue, 23 Oct 2018 17:05:22 +0200 Subject: [PATCH] Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro --- .../process_keycode/process_unicode_common.c | 29 +++++++++++++++++++ .../process_keycode/process_unicode_common.h | 8 +++++ 2 files changed, 37 insertions(+) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4285d20a19f..a9fbd11b0f4 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -20,6 +20,11 @@ #include static uint8_t input_mode; +#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 uint8_t mods; void set_unicode_input_mode(uint8_t os_target) { @@ -35,10 +40,34 @@ void unicode_input_mode_init(void) { static bool first_flag = false; if (!first_flag) { input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE); + +#if UNICODE_SELECTED_MODES != -1 + // Find input_mode in selected modes + uint8_t i; + for (i = 0; i < selected_count; i++) { + if (selected[i] == input_mode) { + selected_index = i; + break; + } + } + if (i == selected_count) { + // input_mode isn't selected, change to one that is + input_mode = selected[selected_index = 0]; + } +#endif + first_flag = true; } } +void cycle_unicode_input_mode(void) { +#if UNICODE_SELECTED_MODES != -1 + unicode_input_mode_init(); // Init selected_index + selected_index = (selected_index + 1) % selected_count; + input_mode = selected[selected_index]; +#endif +} + __attribute__((weak)) void unicode_input_start (void) { // save current mods diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index e78e1cec6ce..390d6b5e819 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -19,6 +19,12 @@ #include "quantum.h" +// 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 + #ifndef UNICODE_TYPE_DELAY #define UNICODE_TYPE_DELAY 10 #endif @@ -29,6 +35,8 @@ static uint8_t input_mode; void set_unicode_input_mode(uint8_t os_target); uint8_t get_unicode_input_mode(void); void unicode_input_mode_init(void); +void cycle_unicode_input_mode(void); + void unicode_input_start(void); void unicode_input_finish(void); void register_hex(uint16_t hex);