Skip to content

Commit

Permalink
Refactor Unicode feature (qmk#18333)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored and ramonimbao committed Nov 28, 2022
1 parent 95af2a5 commit 88629ad
Show file tree
Hide file tree
Showing 15 changed files with 591 additions and 506 deletions.
4 changes: 3 additions & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,10 @@ endif

ifeq ($(strip $(UNICODE_COMMON)), yes)
OPT_DEFS += -DUNICODE_COMMON_ENABLE
COMMON_VPATH += $(QUANTUM_DIR)/unicode
SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c \
$(QUANTUM_DIR)/utf8.c
$(QUANTUM_DIR)/unicode/unicode.c \
$(QUANTUM_DIR)/unicode/utf8.c
endif

MAGIC_ENABLE ?= yes
Expand Down
5 changes: 3 additions & 2 deletions quantum/painter/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ VALID_QUANTUM_PAINTER_DRIVERS := ili9163_spi ili9341_spi ili9488_spi st7789_spi
#-------------------------------------------------------------------------------

OPT_DEFS += -DQUANTUM_PAINTER_ENABLE
COMMON_VPATH += $(QUANTUM_DIR)/painter
COMMON_VPATH += $(QUANTUM_DIR)/painter \
$(QUANTUM_DIR)/unicode
SRC += \
$(QUANTUM_DIR)/utf8.c \
$(QUANTUM_DIR)/unicode/utf8.c \
$(QUANTUM_DIR)/color.c \
$(QUANTUM_DIR)/painter/qp.c \
$(QUANTUM_DIR)/painter/qp_stream.c \
Expand Down
17 changes: 6 additions & 11 deletions quantum/process_keycode/process_ucis.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/

#include "process_ucis.h"
#include "unicode.h"
#include "keycode.h"
#include "wait.h"

qk_ucis_state_t qk_ucis_state;

Expand All @@ -26,9 +29,7 @@ void qk_ucis_start(void) {
}

__attribute__((weak)) void qk_ucis_start_user(void) {
unicode_input_start();
register_hex(0x2328); // ⌨
unicode_input_finish();
register_unicode(0x2328); // ⌨
}

__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {}
Expand All @@ -51,10 +52,7 @@ static bool is_uni_seq(char *seq) {

__attribute__((weak)) void qk_ucis_symbol_fallback(void) {
for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
uint8_t keycode = qk_ucis_state.codes[i];
register_code(keycode);
unregister_code(keycode);
wait_ms(UNICODE_TYPE_DELAY);
tap_code(qk_ucis_state.codes[i]);
}
}

Expand All @@ -63,7 +61,6 @@ __attribute__((weak)) void qk_ucis_cancel(void) {}
void register_ucis(const uint32_t *code_points) {
for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) {
register_unicode(code_points[i]);
wait_ms(UNICODE_TYPE_DELAY);
}
}

Expand Down Expand Up @@ -94,9 +91,7 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) {
case KC_ENTER:
case KC_ESCAPE:
for (uint8_t i = 0; i < qk_ucis_state.count; i++) {
register_code(KC_BACKSPACE);
unregister_code(KC_BACKSPACE);
wait_ms(UNICODE_TYPE_DELAY);
tap_code(KC_BACKSPACE);
}

if (keycode == KC_ESCAPE) {
Expand Down
6 changes: 4 additions & 2 deletions quantum/process_keycode/process_ucis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#pragma once

#include "quantum.h"
#include "process_unicode_common.h"
#include <stdbool.h>
#include <stdint.h>

#include "action.h"

#ifndef UCIS_MAX_SYMBOL_LENGTH
# define UCIS_MAX_SYMBOL_LENGTH 32
Expand Down
12 changes: 6 additions & 6 deletions quantum/process_keycode/process_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/

#include "process_unicode.h"
#include "action_util.h"
#include "eeprom.h"
#include "unicode.h"
#include "quantum_keycodes.h"

bool process_unicode(uint16_t keycode, keyrecord_t *record) {
if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) {
unicode_input_start();
register_hex(keycode & 0x7FFF);
unicode_input_finish();
if (record->event.pressed) {
if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX) {
register_unicode(keycode & 0x7FFF);
}
}
return true;
}
5 changes: 4 additions & 1 deletion quantum/process_keycode/process_unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#pragma once

#include "process_unicode_common.h"
#include <stdbool.h>
#include <stdint.h>

#include "action.h"

bool process_unicode(uint16_t keycode, keyrecord_t *record);
Loading

0 comments on commit 88629ad

Please sign in to comment.