Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCIS: remove qk_ prefix #19302

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/feature_unicode.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ UCIS_ENABLE = yes
Then define a table like this in your keymap file:

```c
const qk_ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
const ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
UCIS_SYM("poop", 0x1F4A9), // 💩
UCIS_SYM("rofl", 0x1F923), // 🤣
UCIS_SYM("cuba", 0x1F1E8, 0x1F1FA), // 🇨🇺
Expand All @@ -93,15 +93,15 @@ const qk_ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(

By default, each table entry may be up to 3 code points long. This number can be changed by adding `#define UCIS_MAX_CODE_POINTS n` to your `config.h` file.

To use UCIS input, call `qk_ucis_start()`. Then, type the mnemonic for the character (such as "rofl") and hit Space, Enter or Esc. QMK should erase the "rofl" text and insert the laughing emoji.
To use UCIS input, call `ucis_start()`. Then, type the mnemonic for the character (such as "rofl") and hit Space, Enter or Esc. QMK should erase the "rofl" text and insert the laughing emoji.

#### Customization

There are several functions that you can define in your keymap to customize the functionality of this feature.

* `void qk_ucis_start_user(void)` – This runs when you call the "start" function, and can be used to provide feedback. By default, it types out a keyboard emoji.
* `void qk_ucis_success(uint8_t symbol_index)` – This runs when the input has matched something and has completed. By default, it doesn't do anything.
* `void qk_ucis_symbol_fallback (void)` – This runs when the input doesn't match anything. By default, it falls back to trying that input as a Unicode code.
* `void ucis_start_user(void)` – This runs when you call the "start" function, and can be used to provide feedback. By default, it types out a keyboard emoji.
* `void ucis_success(uint8_t symbol_index)` – This runs when the input has matched something and has completed. By default, it doesn't do anything.
* `void ucis_symbol_fallback (void)` – This runs when the input doesn't match anything. By default, it falls back to trying that input as a Unicode code.

You can find the default implementations of these functions in [`process_ucis.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_ucis.c).

Expand Down
52 changes: 26 additions & 26 deletions quantum/process_keycode/process_ucis.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
#include "keycode.h"
#include "wait.h"

qk_ucis_state_t qk_ucis_state;
ucis_state_t ucis_state;

void qk_ucis_start(void) {
qk_ucis_state.count = 0;
qk_ucis_state.in_progress = true;
void ucis_start(void) {
ucis_state.count = 0;
ucis_state.in_progress = true;

qk_ucis_start_user();
ucis_start_user();
}

__attribute__((weak)) void qk_ucis_start_user(void) {
__attribute__((weak)) void ucis_start_user(void) {
register_unicode(0x2328); // ⌨
}

__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {}
__attribute__((weak)) void ucis_success(uint8_t symbol_index) {}

static bool is_uni_seq(char *seq) {
uint8_t i;
Expand All @@ -43,20 +43,20 @@ static bool is_uni_seq(char *seq) {
} else {
keycode = seq[i] - 'a' + KC_A;
}
if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != keycode) {
if (i > ucis_state.count || ucis_state.codes[i] != keycode) {
return false;
}
}
return qk_ucis_state.codes[i] == KC_ENTER || qk_ucis_state.codes[i] == KC_SPACE;
return ucis_state.codes[i] == KC_ENTER || ucis_state.codes[i] == KC_SPACE;
}

__attribute__((weak)) void qk_ucis_symbol_fallback(void) {
for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
tap_code(qk_ucis_state.codes[i]);
__attribute__((weak)) void ucis_symbol_fallback(void) {
for (uint8_t i = 0; i < ucis_state.count - 1; i++) {
tap_code(ucis_state.codes[i]);
}
}

__attribute__((weak)) void qk_ucis_cancel(void) {}
__attribute__((weak)) void ucis_cancel(void) {}

void register_ucis(const uint32_t *code_points) {
for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) {
Expand All @@ -65,38 +65,38 @@ void register_ucis(const uint32_t *code_points) {
}

bool process_ucis(uint16_t keycode, keyrecord_t *record) {
if (!qk_ucis_state.in_progress || !record->event.pressed) {
if (!ucis_state.in_progress || !record->event.pressed) {
return true;
}

bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE;
if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) {
if (ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) {
return false;
}

qk_ucis_state.codes[qk_ucis_state.count] = keycode;
qk_ucis_state.count++;
ucis_state.codes[ucis_state.count] = keycode;
ucis_state.count++;

switch (keycode) {
case KC_BACKSPACE:
if (qk_ucis_state.count >= 2) {
qk_ucis_state.count -= 2;
if (ucis_state.count >= 2) {
ucis_state.count -= 2;
return true;
} else {
qk_ucis_state.count--;
ucis_state.count--;
return false;
}

case KC_SPACE:
case KC_ENTER:
case KC_ESCAPE:
for (uint8_t i = 0; i < qk_ucis_state.count; i++) {
for (uint8_t i = 0; i < ucis_state.count; i++) {
tap_code(KC_BACKSPACE);
}

if (keycode == KC_ESCAPE) {
qk_ucis_state.in_progress = false;
qk_ucis_cancel();
ucis_state.in_progress = false;
ucis_cancel();
return false;
}

Expand All @@ -110,12 +110,12 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) {
}
}
if (symbol_found) {
qk_ucis_success(i);
ucis_success(i);
} else {
qk_ucis_symbol_fallback();
ucis_symbol_fallback();
}

qk_ucis_state.in_progress = false;
ucis_state.in_progress = false;
return false;

default:
Expand Down
16 changes: 8 additions & 8 deletions quantum/process_keycode/process_ucis.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
typedef struct {
char * symbol;
uint32_t code_points[UCIS_MAX_CODE_POINTS];
} qk_ucis_symbol_t;
} ucis_symbol_t;

typedef struct {
uint8_t count;
uint16_t codes[UCIS_MAX_SYMBOL_LENGTH];
bool in_progress : 1;
} qk_ucis_state_t;
} ucis_state_t;

extern qk_ucis_state_t qk_ucis_state;
extern ucis_state_t ucis_state;

// clang-format off

Expand All @@ -53,12 +53,12 @@ extern qk_ucis_state_t qk_ucis_state;

// clang-format on

extern const qk_ucis_symbol_t ucis_symbol_table[];
extern const ucis_symbol_t ucis_symbol_table[];

void qk_ucis_start(void);
void qk_ucis_start_user(void);
void qk_ucis_symbol_fallback(void);
void qk_ucis_success(uint8_t symbol_index);
void ucis_start(void);
void ucis_start_user(void);
void ucis_symbol_fallback(void);
void ucis_success(uint8_t symbol_index);

void register_ucis(const uint32_t *code_points);

Expand Down
4 changes: 2 additions & 2 deletions users/uqs/uqs.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void matrix_scan_user(void) {

#ifdef UCIS_ENABLE
SEQ_ONE_KEY(KC_U) {
qk_ucis_start();
ucis_start();
}
#endif
SEQ_ONE_KEY(KC_H) {
Expand Down Expand Up @@ -576,7 +576,7 @@ void matrix_scan_user(void) {

#ifdef UCIS_ENABLE
// 3 codepoints at most, otherwise increase UCIS_MAX_CODE_POINTS
const qk_ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
const ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
UCIS_SYM("poop", 0x1F4A9), // 💩
UCIS_SYM("rofl", 0x1F923), // 🤣
UCIS_SYM("look", 0x0CA0, 0x005F, 0x0CA0) // ಠ_ಠ
Expand Down