aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorKonstantin Đorđević <vomindoraan@gmail.com>2020-05-09 10:22:02 +0200
committerGitHub <noreply@github.com>2020-05-09 01:22:02 -0700
commit94fc32f43135ac4afb14849c7fb5e99f95455078 (patch)
tree86d13bcaac1af61f53c6cc7a4bc09845dac1de66 /quantum/process_keycode
parent1f7bbf279c925240630daacd3c29d51719112c3f (diff)
downloadqmk_firmware-94fc32f43135ac4afb14849c7fb5e99f95455078.tar.gz
qmk_firmware-94fc32f43135ac4afb14849c7fb5e99f95455078.zip
Fix bug in UC_RMOD, add shift and audio support for UC_MOD/UC_RMOD(#8674)
* Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_rgb.c2
-rw-r--r--quantum/process_keycode/process_unicode_common.c118
-rw-r--r--quantum/process_keycode/process_unicode_common.h2
-rw-r--r--quantum/process_keycode/process_unicodemap.c3
4 files changed, 74 insertions, 51 deletions
diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c
index 627e5986f..21164b8f9 100644
--- a/quantum/process_keycode/process_rgb.c
+++ b/quantum/process_keycode/process_rgb.c
@@ -56,7 +56,7 @@ bool process_rgb(const uint16_t keycode, const keyrecord_t *record) {
56 // Split keyboards need to trigger on key-up for edge-case issue 56 // Split keyboards need to trigger on key-up for edge-case issue
57 if (!record->event.pressed) { 57 if (!record->event.pressed) {
58#endif 58#endif
59 uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); 59 uint8_t shifted = get_mods() & MOD_MASK_SHIFT;
60 switch (keycode) { 60 switch (keycode) {
61 case RGB_TOG: 61 case RGB_TOG:
62 rgblight_toggle(); 62 rgblight_toggle();
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index 48ce3961a..fb5021501 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -24,8 +24,8 @@ uint8_t unicode_saved_mods;
24 24
25#if UNICODE_SELECTED_MODES != -1 25#if UNICODE_SELECTED_MODES != -1
26static uint8_t selected[] = {UNICODE_SELECTED_MODES}; 26static uint8_t selected[] = {UNICODE_SELECTED_MODES};
27static uint8_t selected_count = sizeof selected / sizeof *selected; 27static int8_t selected_count = sizeof selected / sizeof *selected;
28static uint8_t selected_index; 28static int8_t selected_index;
29#endif 29#endif
30 30
31void unicode_input_mode_init(void) { 31void unicode_input_mode_init(void) {
@@ -33,7 +33,7 @@ void unicode_input_mode_init(void) {
33#if UNICODE_SELECTED_MODES != -1 33#if UNICODE_SELECTED_MODES != -1
34# if UNICODE_CYCLE_PERSIST 34# if UNICODE_CYCLE_PERSIST
35 // Find input_mode in selected modes 35 // Find input_mode in selected modes
36 uint8_t i; 36 int8_t i;
37 for (i = 0; i < selected_count; i++) { 37 for (i = 0; i < selected_count; i++) {
38 if (selected[i] == unicode_config.input_mode) { 38 if (selected[i] == unicode_config.input_mode) {
39 selected_index = i; 39 selected_index = i;
@@ -60,9 +60,12 @@ void set_unicode_input_mode(uint8_t mode) {
60 dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); 60 dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
61} 61}
62 62
63void cycle_unicode_input_mode(uint8_t offset) { 63void cycle_unicode_input_mode(int8_t offset) {
64#if UNICODE_SELECTED_MODES != -1 64#if UNICODE_SELECTED_MODES != -1
65 selected_index = (selected_index + offset) % selected_count; 65 selected_index = (selected_index + offset) % selected_count;
66 if (selected_index < 0) {
67 selected_index += selected_count;
68 }
66 unicode_config.input_mode = selected[selected_index]; 69 unicode_config.input_mode = selected[selected_index];
67# if UNICODE_CYCLE_PERSIST 70# if UNICODE_CYCLE_PERSIST
68 persist_unicode_input_mode(); 71 persist_unicode_input_mode();
@@ -168,6 +171,8 @@ void register_hex32(uint32_t hex) {
168 } 171 }
169} 172}
170 173
174// clang-format off
175
171void send_unicode_hex_string(const char *str) { 176void send_unicode_hex_string(const char *str) {
172 if (!str) { 177 if (!str) {
173 return; 178 return;
@@ -175,12 +180,11 @@ void send_unicode_hex_string(const char *str) {
175 180
176 while (*str) { 181 while (*str) {
177 // Find the next code point (token) in the string 182 // Find the next code point (token) in the string
178 for (; *str == ' '; str++) 183 for (; *str == ' '; str++); // Skip leading spaces
179 ;
180 size_t n = strcspn(str, " "); // Length of the current token 184 size_t n = strcspn(str, " "); // Length of the current token
181 char code_point[n + 1]; 185 char code_point[n+1];
182 strncpy(code_point, str, n); 186 strncpy(code_point, str, n); // Copy token into buffer
183 code_point[n] = '\0'; // Make sure it's null-terminated 187 code_point[n] = '\0'; // Make sure it's null-terminated
184 188
185 // Normalize the code point: make all hex digits lowercase 189 // Normalize the code point: make all hex digits lowercase
186 for (char *p = code_point; *p; p++) { 190 for (char *p = code_point; *p; p++) {
@@ -196,8 +200,10 @@ void send_unicode_hex_string(const char *str) {
196 } 200 }
197} 201}
198 202
203// clang-format on
204
199// Borrowed from https://nullprogram.com/blog/2017/10/06/ 205// Borrowed from https://nullprogram.com/blog/2017/10/06/
200const char *decode_utf8(const char *str, int32_t *code_point) { 206static const char *decode_utf8(const char *str, int32_t *code_point) {
201 const char *next; 207 const char *next;
202 208
203 if (str[0] < 0x80) { // U+0000-007F 209 if (str[0] < 0x80) { // U+0000-007F
@@ -231,7 +237,6 @@ void send_unicode_string(const char *str) {
231 } 237 }
232 238
233 int32_t code_point = 0; 239 int32_t code_point = 0;
234
235 while (*str) { 240 while (*str) {
236 str = decode_utf8(str, &code_point); 241 str = decode_utf8(str, &code_point);
237 242
@@ -243,53 +248,70 @@ void send_unicode_string(const char *str) {
243 } 248 }
244} 249}
245 250
251// clang-format off
252
253static void audio_helper(void) {
254#ifdef AUDIO_ENABLE
255 switch (get_unicode_input_mode()) {
256# ifdef UNICODE_SONG_MAC
257 static float song_mac[][2] = UNICODE_SONG_MAC;
258 case UC_MAC:
259 PLAY_SONG(song_mac);
260 break;
261# endif
262# ifdef UNICODE_SONG_LNX
263 static float song_lnx[][2] = UNICODE_SONG_LNX;
264 case UC_LNX:
265 PLAY_SONG(song_lnx);
266 break;
267# endif
268# ifdef UNICODE_SONG_WIN
269 static float song_win[][2] = UNICODE_SONG_WIN;
270 case UC_WIN:
271 PLAY_SONG(song_win);
272 break;
273# endif
274# ifdef UNICODE_SONG_BSD
275 static float song_bsd[][2] = UNICODE_SONG_BSD;
276 case UC_BSD:
277 PLAY_SONG(song_bsd);
278 break;
279# endif
280# ifdef UNICODE_SONG_WINC
281 static float song_winc[][2] = UNICODE_SONG_WINC;
282 case UC_WINC:
283 PLAY_SONG(song_winc);
284 break;
285# endif
286 }
287#endif
288}
289
290// clang-format on
291
246bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { 292bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
247 if (record->event.pressed) { 293 if (record->event.pressed) {
294 bool shifted = get_mods() & MOD_MASK_SHIFT;
248 switch (keycode) { 295 switch (keycode) {
249 case UNICODE_MODE_FORWARD: 296 case UNICODE_MODE_FORWARD:
250 cycle_unicode_input_mode(+1); 297 cycle_unicode_input_mode(shifted ? -1 : +1);
298 audio_helper();
251 break; 299 break;
252 case UNICODE_MODE_REVERSE: 300 case UNICODE_MODE_REVERSE:
253 cycle_unicode_input_mode(-1); 301 cycle_unicode_input_mode(shifted ? +1 : -1);
302 audio_helper();
254 break; 303 break;
255 304
256 case UNICODE_MODE_MAC: 305 case UNICODE_MODE_MAC ... UNICODE_MODE_WINC: {
257 set_unicode_input_mode(UC_MAC); 306 // Keycodes and input modes follow the same ordering
258#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_MAC) 307 uint8_t delta = keycode - UNICODE_MODE_MAC;
259 static float song_mac[][2] = UNICODE_SONG_MAC; 308 set_unicode_input_mode(UC_MAC + delta);
260 PLAY_SONG(song_mac); 309 audio_helper();
261#endif
262 break;
263 case UNICODE_MODE_LNX:
264 set_unicode_input_mode(UC_LNX);
265#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
266 static float song_lnx[][2] = UNICODE_SONG_LNX;
267 PLAY_SONG(song_lnx);
268#endif
269 break;
270 case UNICODE_MODE_WIN:
271 set_unicode_input_mode(UC_WIN);
272#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
273 static float song_win[][2] = UNICODE_SONG_WIN;
274 PLAY_SONG(song_win);
275#endif
276 break;
277 case UNICODE_MODE_BSD:
278 set_unicode_input_mode(UC_BSD);
279#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
280 static float song_bsd[][2] = UNICODE_SONG_BSD;
281 PLAY_SONG(song_bsd);
282#endif
283 break;
284 case UNICODE_MODE_WINC:
285 set_unicode_input_mode(UC_WINC);
286#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
287 static float song_winc[][2] = UNICODE_SONG_WINC;
288 PLAY_SONG(song_winc);
289#endif
290 break; 310 break;
311 }
291 } 312 }
292 } 313 }
314
293#if defined(UNICODE_ENABLE) 315#if defined(UNICODE_ENABLE)
294 return process_unicode(keycode, record); 316 return process_unicode(keycode, record);
295#elif defined(UNICODEMAP_ENABLE) 317#elif defined(UNICODEMAP_ENABLE)
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h
index 5421c28c7..4579fde8d 100644
--- a/quantum/process_keycode/process_unicode_common.h
+++ b/quantum/process_keycode/process_unicode_common.h
@@ -80,7 +80,7 @@ extern uint8_t unicode_saved_mods;
80void unicode_input_mode_init(void); 80void unicode_input_mode_init(void);
81uint8_t get_unicode_input_mode(void); 81uint8_t get_unicode_input_mode(void);
82void set_unicode_input_mode(uint8_t mode); 82void set_unicode_input_mode(uint8_t mode);
83void cycle_unicode_input_mode(uint8_t offset); 83void cycle_unicode_input_mode(int8_t offset);
84void persist_unicode_input_mode(void); 84void persist_unicode_input_mode(void);
85 85
86void unicode_input_start(void); 86void unicode_input_start(void);
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
index 5445cde12..2f402a2fd 100644
--- a/quantum/process_keycode/process_unicodemap.c
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -21,7 +21,8 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
21 // Keycode is a pair: extract index based on Shift / Caps Lock state 21 // Keycode is a pair: extract index based on Shift / Caps Lock state
22 uint16_t index = keycode - QK_UNICODEMAP_PAIR; 22 uint16_t index = keycode - QK_UNICODEMAP_PAIR;
23 23
24 bool shift = unicode_saved_mods & MOD_MASK_SHIFT, caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK); 24 bool shift = unicode_saved_mods & MOD_MASK_SHIFT;
25 bool caps = IS_HOST_LED_ON(USB_LED_CAPS_LOCK);
25 if (shift ^ caps) { 26 if (shift ^ caps) {
26 index >>= 7; 27 index >>= 7;
27 } 28 }