diff options
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_space_cadet.c | 151 | ||||
| -rw-r--r-- | quantum/process_keycode/process_space_cadet.h | 21 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 6 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode.h | 2 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 38 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.h | 13 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicodemap.c | 36 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicodemap.h | 4 | 
8 files changed, 236 insertions, 35 deletions
| diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c new file mode 100644 index 0000000000..ac39df8089 --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.c @@ -0,0 +1,151 @@ +/* Copyright 2019 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 <http://www.gnu.org/licenses/>. + */ +#include "process_space_cadet.h" + +#ifndef TAPPING_TERM +  #define TAPPING_TERM 200 +#endif + +// ********** OBSOLETE DEFINES, STOP USING! (pls?) ********** +// Shift / paren setup +#ifndef LSPO_KEY +  #define LSPO_KEY KC_9 +#endif +#ifndef RSPC_KEY +  #define RSPC_KEY KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEY +  #define SFTENT_KEY KC_ENT +#endif + +#ifdef DISABLE_SPACE_CADET_MODIFIER +  #ifndef LSPO_MOD +    #define LSPO_MOD KC_TRNS +  #endif +  #ifndef RSPC_MOD +    #define RSPC_MOD KC_TRNS +  #endif +#else +  #ifndef LSPO_MOD +    #define LSPO_MOD KC_LSFT +  #endif +  #ifndef RSPC_MOD +    #define RSPC_MOD KC_RSFT +  #endif +#endif +// ********************************************************** + +// Shift / paren setup +#ifndef LSPO_KEYS +  #define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY +#endif +#ifndef RSPC_KEYS +  #define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY +#endif + +// Control / paren setup +#ifndef LCPO_KEYS +  #define LCPO_KEYS KC_LCTL, KC_LCTL, KC_9 +#endif +#ifndef RCPC_KEYS +  #define RCPC_KEYS KC_RCTL, KC_RCTL, KC_0 +#endif + +// Alt / paren setup +#ifndef LAPO_KEYS +  #define LAPO_KEYS KC_LALT, KC_LALT, KC_9 +#endif +#ifndef RAPC_KEYS +  #define RAPC_KEYS KC_RALT, KC_RALT, KC_0 +#endif + +// Shift / Enter setup +#ifndef SFTENT_KEYS +  #define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY +#endif + +static uint8_t sc_last = 0; +static uint16_t sc_timer = 0; + +void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) { +  if (record->event.pressed) { +    sc_last = holdMod; +    sc_timer = timer_read (); +    if (IS_MOD(holdMod)) { +      register_mods(MOD_BIT(holdMod)); +    } +  } +  else { +    if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) { +      if (holdMod != tapMod) { +        if (IS_MOD(holdMod)) { +          unregister_mods(MOD_BIT(holdMod)); +        } +        if (IS_MOD(tapMod)) { +          register_mods(MOD_BIT(tapMod)); +        } +      } +      tap_code(keycode); +      if (IS_MOD(tapMod)) { +        unregister_mods(MOD_BIT(tapMod)); +      } +    } else { +      if (IS_MOD(holdMod)) { +        unregister_mods(MOD_BIT(holdMod)); +      } +    } +  } +} + +bool process_space_cadet(uint16_t keycode, keyrecord_t *record) { +  switch(keycode) { +    case KC_LSPO: { +      perform_space_cadet(record, LSPO_KEYS); +      return false; +    } +    case KC_RSPC: { +      perform_space_cadet(record, RSPC_KEYS); +      return false; +    } +    case KC_LCPO: { +      perform_space_cadet(record, LCPO_KEYS); +      return false; +    } +    case KC_RCPC: { +      perform_space_cadet(record, RCPC_KEYS); +      return false; +    } +    case KC_LAPO: { +      perform_space_cadet(record, LAPO_KEYS); +      return false; +    } +    case KC_RAPC: { +      perform_space_cadet(record, RAPC_KEYS); +      return false; +    } +    case KC_SFTENT: { +      perform_space_cadet(record, SFTENT_KEYS); +      return false; +    } +    default: { +      sc_last = 0; +      break; +    } +  } +  return true; +} diff --git a/quantum/process_keycode/process_space_cadet.h b/quantum/process_keycode/process_space_cadet.h new file mode 100644 index 0000000000..c823143504 --- /dev/null +++ b/quantum/process_keycode/process_space_cadet.h @@ -0,0 +1,21 @@ +/* Copyright 2019 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 <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include "quantum.h" + +void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode); +bool process_space_cadet(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 19beb84520..2c914013ac 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -13,15 +13,15 @@   * You should have received a copy of the GNU General Public License   * along with this program.  If not, see <http://www.gnu.org/licenses/>.   */ +  #include "process_unicode.h"  #include "action_util.h"  #include "eeprom.h"  bool process_unicode(uint16_t keycode, keyrecord_t *record) { -  if (keycode > QK_UNICODE && record->event.pressed) { -    uint16_t unicode = keycode & 0x7FFF; +  if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) {      unicode_input_start(); -    register_hex(unicode); +    register_hex(keycode & 0x7FFF);      unicode_input_finish();    }    return true; diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index 0913e99107..22765ad560 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -13,9 +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/>.   */ +  #pragma once -#include "quantum.h"  #include "process_unicode_common.h"  bool process_unicode(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index d0a9cf2324..21ac2291db 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -20,6 +20,8 @@  #include <string.h>  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; @@ -75,30 +77,24 @@ 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) { -  saved_mods = get_mods(); // Save current mods +  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_OSX_KEY); +    register_code(UNICODE_KEY_OSX);      break;    case UC_LNX: -    register_code(KC_LCTL); -    register_code(KC_LSFT); -    tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test -    unregister_code(KC_LSFT); -    unregister_code(KC_LCTL); +    tap_code16(UNICODE_KEY_LNX);      break;    case UC_WIN:      register_code(KC_LALT);      tap_code(KC_PPLS);      break;    case UC_WINC: -    tap_code(UNICODE_WINC_KEY); +    tap_code(UNICODE_KEY_WINC);      tap_code(KC_U);      break;    } @@ -110,7 +106,7 @@ __attribute__((weak))  void unicode_input_finish(void) {    switch (unicode_config.input_mode) {    case UC_OSX: -    unregister_code(UNICODE_OSX_KEY); +    unregister_code(UNICODE_KEY_OSX);      break;    case UC_LNX:      tap_code(KC_SPC); @@ -123,7 +119,25 @@ void unicode_input_finish(void) {      break;    } -  set_mods(saved_mods); // Reregister previously set mods +  set_mods(unicode_saved_mods); // Reregister previously set mods +} + +__attribute__((weak)) +void unicode_input_cancel(void) { +  switch (unicode_config.input_mode) { +  case UC_OSX: +    unregister_code(UNICODE_KEY_OSX); +    break; +  case UC_LNX: +  case UC_WINC: +    tap_code(KC_ESC); +    break; +  case UC_WIN: +    unregister_code(KC_LALT); +    break; +  } + +  set_mods(unicode_saved_mods); // Reregister previously set mods  }  __attribute__((weak)) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index e608ab76be..7340800e56 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -23,11 +23,14 @@  #endif  // Keycodes used for starting Unicode input on different platforms -#ifndef UNICODE_OSX_KEY -  #define UNICODE_OSX_KEY  KC_LALT +#ifndef UNICODE_KEY_OSX +  #define UNICODE_KEY_OSX  KC_LALT  #endif -#ifndef UNICODE_WINC_KEY -  #define UNICODE_WINC_KEY KC_RALT +#ifndef UNICODE_KEY_LNX +  #define UNICODE_KEY_LNX  LCTL(LSFT(KC_U)) +#endif +#ifndef UNICODE_KEY_WINC +  #define UNICODE_KEY_WINC KC_RALT  #endif  // Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) @@ -63,6 +66,7 @@ typedef union {  } unicode_config_t;  extern unicode_config_t unicode_config; +extern uint8_t          unicode_saved_mods;  void unicode_input_mode_init(void);  uint8_t get_unicode_input_mode(void); @@ -72,6 +76,7 @@ void persist_unicode_input_mode(void);  void unicode_input_start(void);  void unicode_input_finish(void); +void unicode_input_cancel(void);  void register_hex(uint16_t hex);  void send_unicode_hex_string(const char *str); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 3274027613..b887879860 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -15,7 +15,6 @@   */  #include "process_unicodemap.h" -#include "process_unicode_common.h"  void register_hex32(uint32_t hex) {    bool onzerostart = true; @@ -38,28 +37,39 @@ void register_hex32(uint32_t hex) {  }  __attribute__((weak)) -void unicodemap_input_error() {} +uint16_t unicodemap_index(uint16_t keycode) { +  if (keycode >= QK_UNICODEMAP_PAIR) { +    // Keycode is a pair: extract index based on Shift / Caps Lock state +    uint16_t index = keycode - QK_UNICODEMAP_PAIR; + +    bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); +    if (shift ^ caps) { index >>= 7; } + +    return index & 0x7F; +  } else { +    // Keycode is a regular index +    return keycode - QK_UNICODEMAP; +  } +}  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); +  if (keycode >= QK_UNICODEMAP && keycode <= QK_UNICODEMAP_PAIR_MAX && record->event.pressed) { +    unicode_input_start(); + +    uint32_t code = pgm_read_dword(unicode_map + unicodemap_index(keycode));      uint8_t input_mode = get_unicode_input_mode(); -    if (code > 0xFFFF && code <= 0x10FFFF && input_mode == UC_OSX) { -      // Convert to UTF-16 surrogate pair +    if (code > 0x10FFFF || (code > 0xFFFF && input_mode == UC_WIN)) { +      // Character is out of range supported by the platform +      unicode_input_cancel(); +    } else if (code > 0xFFFF && input_mode == UC_OSX) { +      // Convert to UTF-16 surrogate pair on Mac        code -= 0x10000;        uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; - -      unicode_input_start();        register_hex32(hi + 0xD800);        register_hex32(lo + 0xDC00);        unicode_input_finish(); -    } 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);        unicode_input_finish();      } diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index fe4f979155..51709c5dc8 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -16,10 +16,10 @@  #pragma once -#include "quantum.h"  #include "process_unicode_common.h"  extern const uint32_t PROGMEM unicode_map[]; -void unicodemap_input_error(void); +void register_hex32(uint32_t hex); +uint16_t unicodemap_index(uint16_t keycode);  bool process_unicodemap(uint16_t keycode, keyrecord_t *record); | 
