Skip to content

Commit

Permalink
Add Unicode Input method Cycling support (#19)
Browse files Browse the repository at this point in the history
* Standardize the Unicode EEPROM code

* Remove unicode init from process_record_* functions

* Add unicode init to where it belongs: matrix_init_quantum

* Move Unicode proccessing to unicode common

* Add audio feedback to input mode keys to drive konstantin up a wall

* Tap_code cleanup

* Update keycodes

* Update unicode documentation

* Update unicode keycodes for consistency/easier merge

* Add Audio Feedback section

* Remove Functions from feature page

And link to the file instead.  Link to specific lines later on.

* Fix white spaces

Co-Authored-By: drashna <drashna@live.com>

* Fix spacing

Co-Authored-By: drashna <drashna@live.com>

* Because I missed it!

Co-Authored-By: drashna <drashna@live.com>

* Fix spacing

Co-Authored-By: drashna <drashna@live.com>

* SPAAAAAAAAAACing

Co-Authored-By: drashna <drashna@live.com>

* white spaces

Co-Authored-By: drashna <drashna@live.com>

* Add BSD for future compatibility

* Thought I fixed that!

Co-Authored-By: drashna <drashna@live.com>

* non-breaking

Co-Authored-By: drashna <drashna@live.com>

* Considered that

Co-Authored-By: drashna <drashna@live.com>

* Yuuup

Co-Authored-By: drashna <drashna@live.com>

* consistency

Co-Authored-By: drashna <drashna@live.com>

* white spaces .... copied from elsewhere

Co-Authored-By: drashna <drashna@live.com>

* white spaces

Co-Authored-By: drashna <drashna@live.com>

* white spaces

Co-Authored-By: drashna <drashna@live.com>

* Update keycode defines

* Fix Linux Song

* Update all of the songs

* Cleanup

* Move and update check to ensure only one unicode method is enabled

* Update quantum/quantum_keycodes.h

* Update documentation

* Wordsmithing and cleanup

* Format unicode_common (#13)

* case alignment

* process_record_unicode_common → process_unicode_common

* Move song arrays into function where they're used, align preprocessor directives

* Swap the order of UC_WIN and UC_BSD

* Update Unicode docs

* Reorder Unicode mode stuff to match the order of input mode constants

* Fix capitalization in doc subtitle

* Readd BSD and OSX_RALT songs

* Reword BSD note in docs

* Readd BSD keycode description

* Reword explanation of input on different platforms

* Steal vomindoraan's input mode documentation

Co-Authored-By: vomindoraan (vomindoraan@gmail.com)

* Willingly give Drashna the rest of my Unicode doc improvements

* Wordsmithing

Co-Authored-By: drashna <drashna@live.com>

* Rearrange process_unicode_common functions

* Make Unicode input mode constants (UC_*) an enum

* Simplify unicode_input_start/finish code

* Make the key used for WinCompose configurable

* Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY

* Update Unicode input mode doc

* Add descriptions and rearrange definitions in process_unicode_common.h

* Add registry command to Unicode docs + misc updates

* Reword an explanation in Unicode docs

* Add TODO comment

* Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro

* Add an option for making cycle changes persistent

* Add debug prints to functions that change input_mode

* Use cycle_unicode_input_mode in whitefox/konstantin

* Add persist_unicode_input_mode function

* Add offset to cycle to allow stepping in reverse

* Add keycodes: UNICODE_MODE_FORWARD, UNICODE_MODE_REVERSE

Aliases: UC_MOD, UC_RMOD (respectively)

* REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts

* Fix wrong constant name

* Revert "REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts"

This reverts commit 42676bf.

* Change dprintf text

* Give selected modes priority over EEPROM when !UNICODE_CYCLE_PERSIST

* Remove trailing whitespace
  • Loading branch information
vomindoraan authored and drashna committed Dec 6, 2018
1 parent 5cfd48d commit 464c9aa
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
14 changes: 6 additions & 8 deletions docs/feature_unicode.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ The following input modes are available:
* **`UC_OSX`**: Mac OS X built-in Unicode hex input. Supports code points up to `0xFFFF` (`0x10FFFF` with `UNICODEMAP`).

To enable, go to _System Preferences > Keyboard > Input Sources_, add _Unicode Hex Input_ to the list (it's under _Other_), then activate it from the input dropdown in the Menu Bar.

* By default, this mode uses the left Option key (KC_LALT), but this can be changed by defining UNICODE_OSX_KEY with another keycode.
By default, this mode uses the left Option key (`KC_LALT`), but this can be changed by defining [`UNICODE_OSX_KEY`](#input-key-configuration) with another keycode.

* **`UC_LNX`**: Linux built-in IBus Unicode input. Supports all possible code points (`0x10FFFF`).

Expand All @@ -81,7 +80,7 @@ The following input modes are available:
* **`UC_WINC`**: Windows Unicode input using [WinCompose](https://github.com/samhocevar/wincompose). As of v0.8.2, supports code points up to `0xFFFFF`.

To enable, install the [latest release](https://github.com/samhocevar/wincompose/releases/latest). Once installed, WinCompose will automatically run on startup. Works reliably under all version of Windows supported by the app.
This mode relies on the Compose key being set to Right Alt (`KC_RALT`). If you change it to something else in the WinCompose settings, this mode will not work.
By default, this mode uses the right Alt key (`KC_RALT`), but this can be changed in the WinCompose settings and by defining [`UNICODE_WINC_KEY`](#input-key-configuration) with another keycode.

### Switching Input Modes

Expand All @@ -91,13 +90,13 @@ You can switch the input mode at any time by using one of the following keycodes

|Keycode |Alias |Input mode |Description |
|-----------------------|---------|-------------|-----------------------------------------|
|`UNICODE_MODE_FORWARD` |`UC_MOD` | |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
|`UNICODE_MODE_REVERSE` |`UC_RMOD`| |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Switch to Mac OS X input. |
|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Switch to Linux input. |
|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Switch to Windows input. |
|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Switch to BSD input (not implemented). |
|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Switch to Windows input using WinCompose.|
|`UNICODE_MODE_FORWARD` |`UC_MOD` | |Cycles forwards through the available modes.[(Disabled by default)](#input-method-cycling)|
|`UNICODE_MODE_REVERSE` |`UC_RMOD`|` |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|

You can also switch the input mode by calling `set_unicode_input_mode(x)` in your code, where _x_ is one of the above input mode constants (e.g. `UC_LNX`). Since the function only needs to be called once, it's recommended that you do it in `eeconfig_init_user` (or a similar function). For example:

Expand Down Expand Up @@ -143,16 +142,15 @@ Additionally, you can customize the keys used to trigger the unicode input for m
#define UNICODE_OSX_KEY KC_LALT
#define UNICODE_WINC_KEY KC_RALT
```
#### Input method Cycling
#### Input Method Cycling
Also, you can choose which input methods are availble for cycling through. By default, this is disabled. But if you want to enabled it, then limiting it to just those modes makes sense. Note that `UNICODE_SELECTED_MODES` define is comma delimited.
```c
#define UNICODE_SELECTED_MODES UC_OSX, UC_LNX, UC_WIN, UC_BSD, UC_WINC
```



## `send_unicode_hex_string`

To type multiple characters for things like (ノಠ痊ಠ)ノ彡┻━┻, you can use `send_unicode_hex_string()` much like `SEND_STRING()` except you would use hex values separate by spaces.
Expand Down
4 changes: 4 additions & 0 deletions keyboards/whitefox/keymaps/konstantin/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
#define PERMISSIVE_HOLD
#define TAPPING_TERM 200
#define TAPPING_TOGGLE 2

#define UNICODE_CYCLE_PERSIST false
#define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
#define UNICODE_WINC_KEY KC_RGUI
8 changes: 2 additions & 6 deletions keyboards/whitefox/keymaps/konstantin/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#define DIVIDE UC(0x00F7)
#define MINUS UC(0x2212)

void eeconfig_init_user(void) {
set_unicode_input_mode(UC_WINC);
}

enum layers {
L_BASE,
L_FN,
Expand Down Expand Up @@ -162,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
* │ │F1 │F2 │F3 │F4 │F5 │F6 │F7 │F8 │F9 │F10│F11│F12│Num│Scr│Pau│
* ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┼───┤
* │ M4 │M2 │M↑ │M1 │M3 │M5 │ │ │ │Stp│Ply│Prv│Nxt│Clear│Ins│
* │ M4 │M2 │M↑ │M1 │M3 │M5 │ │UCM│ │Stp│Ply│Prv│Nxt│Clear│Ins│
* ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┼───┤
* │ │M← │M↓ │M→ │MW↑│ │ │ │ │ │ │ │ │Top│
* ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┼───┤
Expand All @@ -173,7 +169,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
*/
[L_FN] = LAYOUT_truefox( \
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, NUMPAD, KC_SLCK, KC_PAUS, \
KC_BTN4, KC_BTN2, KC_MS_U, KC_BTN1, KC_BTN3, KC_BTN5, _______, _______, _______, KC_MSTP, KC_MPLY, KC_MPRV, KC_MNXT, CLEAR, KC_INS, \
KC_BTN4, KC_BTN2, KC_MS_U, KC_BTN1, KC_BTN3, KC_BTN5, _______, UC_MOD, _______, KC_MSTP, KC_MPLY, KC_MPRV, KC_MNXT, CLEAR, KC_INS, \
_______, KC_MS_L, KC_MS_D, KC_MS_R, KC_WH_U, _______, _______, _______, _______, _______, _______, _______, _______, TOP, \
_______, KC_ACL0, KC_ACL2, KC_WH_L, KC_WH_R, _______, _______, _______, KC_VOLD, KC_VOLU, KC_MUTE, KC_APP, KC_PGUP, BOTTOM, \
_______, DESKTOP, DSKTP_L, KC_WH_D, DSKTP_R, _______, KC_HOME, KC_PGDN, KC_END \
Expand Down
58 changes: 52 additions & 6 deletions quantum/process_keycode/process_unicode_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,34 @@
#include <string.h>

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 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) {
Expand All @@ -31,7 +56,23 @@ uint8_t get_unicode_input_mode(void) {

void set_unicode_input_mode(uint8_t mode) {
unicode_config.input_mode = mode;
eeprom_update_byte(EECONFIG_UNICODEMODE, 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;
Expand All @@ -52,8 +93,6 @@ void unicode_input_start(void) {
unregister_code(KC_LSFT);
unregister_code(KC_LCTL);
break;
case UC_BSD:
break;
case UC_WIN:
register_code(KC_LALT);
tap_code(KC_PPLS);
Expand All @@ -73,12 +112,12 @@ void unicode_input_finish(void) {
case UC_OSX:
unregister_code(UNICODE_OSX_KEY);
break;
case UC_WIN:
unregister_code(KC_LALT);
break;
case UC_LNX:
tap_code(KC_SPC);
break;
case UC_WIN:
unregister_code(KC_LALT);
break;
}

set_mods(saved_mods); // Reregister previously set mods
Expand Down Expand Up @@ -130,6 +169,13 @@ void send_unicode_hex_string(const char *str) {
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)
Expand Down
13 changes: 13 additions & 0 deletions quantum/process_keycode/process_unicode_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
#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
Expand All @@ -56,6 +67,8 @@ extern unicode_config_t unicode_config;
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);
Expand Down
6 changes: 6 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ enum quantum_keycodes {

EEPROM_RESET,

UNICODE_MODE_FORWARD,
UNICODE_MODE_REVERSE,

UNICODE_MODE_OSX,
UNICODE_MODE_LNX,
UNICODE_MODE_WIN,
Expand Down Expand Up @@ -687,6 +690,9 @@ enum quantum_keycodes {
#define X(n) (QK_UNICODE_MAP | (n))
#endif

#define UC_MOD UNICODE_MODE_FORWARD
#define UC_RMOD UNICODE_MODE_REVERSE

#define UC_M_OS UNICODE_MODE_OSX
#define UC_M_LN UNICODE_MODE_LNX
#define UC_M_WI UNICODE_MODE_WIN
Expand Down

0 comments on commit 464c9aa

Please sign in to comment.