Add unicode mode change callbacks (#18235)

This commit is contained in:
Joshua Diamond 2022-08-31 19:39:16 -04:00 committed by GitHub
parent b9effc94db
commit e4bf832368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 28 deletions

View file

@ -206,6 +206,17 @@ The functions for starting and finishing Unicode input on your platform can be o
You can find the default implementations of these functions in [`process_unicode_common.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_unicode_common.c).
### Input Mode Callbacks
There are callbacks functions available that are called whenever the unicode input mode changes. The new input mode is passed to the function.
|Callback |Description |
|---------------------------------------------------|-----------------------------------------------------|
| `unicode_input_mode_set_kb(uint8_t input_mode)` | Callback for unicode input mode set, for keyboard. |
| `unicode_input_mode_set_user(uint8_t input_mode)` | Callback for unicode input mode set, for users. |
This feature can be used, for instance, to implement LED indicators for the current unicode input mode.
### Input Key Configuration
You can customize the keys used to trigger Unicode input for macOS, Linux and WinCompose by adding corresponding defines to your `config.h`. The default values match the platforms' default settings, so you shouldn't need to change this unless Unicode input isn't working, or you want to use a different key (e.g. in order to free up left or right Alt).

View file

@ -29,6 +29,20 @@ static int8_t selected_count = ARRAY_SIZE(selected);
static int8_t selected_index;
#endif
/** \brief Uunicode input mode set at user level
*
* Run user code on unicode input mode change
*/
__attribute__((weak)) void unicode_input_mode_set_user(uint8_t input_mode) {}
/** \brief unicode input mode set at keyboard level
*
* Run keyboard code on unicode input mode change
*/
__attribute__((weak)) void unicode_input_mode_set_kb(uint8_t input_mode) {
unicode_input_mode_set_user(input_mode);
}
void unicode_input_mode_init(void) {
unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
#if UNICODE_SELECTED_MODES != -1
@ -50,6 +64,7 @@ void unicode_input_mode_init(void) {
unicode_config.input_mode = selected[selected_index = 0];
# endif
#endif
unicode_input_mode_set_kb(unicode_config.input_mode);
dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
}
@ -60,6 +75,7 @@ uint8_t get_unicode_input_mode(void) {
void set_unicode_input_mode(uint8_t mode) {
unicode_config.input_mode = mode;
persist_unicode_input_mode();
unicode_input_mode_set_kb(mode);
dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
}
@ -73,6 +89,7 @@ void cycle_unicode_input_mode(int8_t offset) {
# if UNICODE_CYCLE_PERSIST
persist_unicode_input_mode();
# endif
unicode_input_mode_set_kb(unicode_config.input_mode);
dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
#endif
}

View file

@ -87,6 +87,9 @@ void unicode_input_start(void);
void unicode_input_finish(void);
void unicode_input_cancel(void);
void unicode_input_mode_set_user(uint8_t input_mode);
void unicode_input_mode_set_kb(uint8_t input_mode);
void register_hex(uint16_t hex);
void register_hex32(uint32_t hex);
void register_unicode(uint32_t code_point);

View file

@ -112,8 +112,7 @@ void do_rgb_layers(layer_state_t state, uint8_t start, uint8_t end) {
}
}
void do_rgb_unicode(void) {
uint8_t uc_mode = get_unicode_input_mode();
void do_rgb_unicode(uint8_t uc_mode) {
for (uint8_t i = 0; i < UC__COUNT; i++) {
bool is_on = i == uc_mode;
rgblight_set_layer_state(UNICODE_OFFSET + i, is_on);
@ -123,7 +122,7 @@ void do_rgb_unicode(void) {
void do_rgb_all(void) {
do_rgb_layers(default_layer_state, LAYER_BASE_DEFAULT, LAYER_BASE_REGULAR);
do_rgb_layers(layer_state, LAYER_BASE_REGULAR, LAYER_BASE_END);
do_rgb_unicode();
do_rgb_unicode(get_unicode_input_mode());
rgblight_set_layer_state(MISC_OFFSET + 0, spi_gflock);
rgblight_set_layer_state(MISC_OFFSET + 1, spi_replace_mode != SPI_NORMAL);
}
@ -382,6 +381,13 @@ bool led_update_user_rgb(led_t led_state) {
return true;
}
#if defined(UNICODE_COMMON_ENABLE)
void unicode_input_mode_set_user_rgb(uint8_t input_mode) {
rgb_layer_ack(ACK_MEH);
do_rgb_unicode(input_mode);
}
#endif
void rgb_layer_ack_yn(bool yn) { rgb_layer_ack(yn ? ACK_YES : ACK_NO); }
void rgb_layer_ack(layer_ack_t n) {
@ -476,20 +482,5 @@ void post_process_record_user_rgb(uint16_t keycode, keyrecord_t *record) {
rgb_layer_ack_yn(keymap_config.nkro);
break;
#endif
#if defined(UNICODE_COMMON_ENABLE)
case UC_M_MA:
case UC_M_LN:
case UC_M_WI:
case UC_M_BS:
case UC_M_WC:
case UC_M_EM:
case UC_MOD:
case UC_RMOD:
rgb_layer_ack(ACK_MEH);
do_rgb_unicode();
break;
#endif
}
}

View file

@ -387,3 +387,11 @@ bool led_update_user(led_t led_state) {
return true;
#endif
}
#if defined(UNICODE_COMMON_ENABLE)
void unicode_input_mode_set_user(uint8_t input_mode) {
# ifdef RGBLIGHT_ENABLE
unicode_input_mode_set_user_rgb(input_mode);
# endif
}
#endif

View file

@ -65,6 +65,11 @@ void rgb_layer_ack(layer_ack_t n);
void rgb_layer_ack_yn(bool yn);
void clear_rgb_layers(void);
void shutdown_user_rgb(void);
# if defined(UNICODE_COMMON_ENABLE)
void unicode_input_mode_set_user_rgb(uint8_t input_mode);
# endif
#endif
#ifdef UNICODEMAP_ENABLE