/* Copyright 2017 Jack Humbert
*
* 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 "process_unicode_common.h"
#include "eeprom.h"
#include
#include
unicode_config_t unicode_config;
uint8_t unicode_saved_mods;
#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 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 unicode_config.input_mode; }
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); }
__attribute__((weak)) void unicode_input_start(void) {
unicode_saved_mods = get_mods(); // Save current mods
clear_mods(); // Unregister mods to start from a clean state
switch (unicode_config.input_mode) {
case UC_OSX:
register_code(UNICODE_KEY_OSX);
break;
case UC_LNX:
tap_code16(UNICODE_KEY_LNX);
break;
case UC_WIN:
register_code(KC_LALT);
tap_code(KC_PPLS);
break;
case UC_WINC:
tap_code(UNICODE_KEY_WINC);
tap_code(KC_U);
break;
}
wait_ms(UNICODE_TYPE_DELAY);
}
__attribute__((weak)) void unicode_input_finish(void) {
switch (unicode_config.input_mode) {
case UC_OSX:
unregister_code(UNICODE_KEY_OSX);
break;
case UC_LNX:
tap_code(KC_SPC);
break;
case UC_WIN:
unregister_code(KC_LALT);