From 95d20e6d8bb1ffaf3024af793daf789ee0b75727 Mon Sep 17 00:00:00 2001 From: Pascal Getreuer <50221757+getreuer@users.noreply.github.com> Date: Sun, 5 Jun 2022 00:14:02 -0700 Subject: Fix and add unit tests for Caps Word to work with Unicode Map, Auto Shift, Retro Shift. (#17284) * Fix Caps Word and Unicode Map * Tests for Caps Word + Auto Shift and Unicode Map. * Fix formatting * Add additional keyboard report expectation macros This commit defines five test utilities, EXPECT_REPORT, EXPECT_UNICODE, EXPECT_EMPTY_REPORT, EXPECT_ANY_REPORT and EXPECT_NO_REPORT for use with TestDriver. EXPECT_REPORT sets a gmock expectation that a given keyboard report will be sent. For instance, EXPECT_REPORT(driver, (KC_LSFT, KC_A)); is shorthand for EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); EXPECT_UNICODE sets a gmock expectation that a given Unicode code point will be sent using UC_LNX input mode. For instance for U+2013, EXPECT_UNICODE(driver, 0x2013); expects the sequence of keys: "Ctrl+Shift+U, 2, 0, 1, 3, space". EXPECT_EMPTY_REPORT sets a gmock expectation that a given keyboard report will be sent. For instance EXPECT_EMPTY_REPORT(driver); expects a single report without keypresses or modifiers. EXPECT_ANY_REPORT sets a gmock expectation that a arbitrary keyboard report will be sent, without matching its contents. For instance EXPECT_ANY_REPORT(driver).Times(1); expects a single arbitrary keyboard report will be sent. EXPECT_NO_REPORT sets a gmock expectation that no keyboard report will be sent at all. * Add tap_key() and tap_keys() to TestFixture. This commit adds a `tap_key(key)` method to TestFixture that taps a given KeymapKey, optionally with a specified delay between press and release. Similarly, the method `tap_keys(key_a, key_b, key_c)` taps a sequence of KeymapKeys. * Use EXPECT_REPORT, tap_keys, etc. in most tests. This commit uses EXPECT_REPORT, EXPECT_UNICODE, EXPECT_EMPTY_REPORT, EXPECT_NO_REPORT, tap_key() and tap_keys() test utilities from the previous two commits in most tests. Particularly the EXPECT_REPORT macro is frequently useful and makes a nice reduction in boilerplate needed to express many tests. Co-authored-by: David Kosorin --- quantum/process_keycode/process_unicode_common.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum/process_keycode/process_unicode_common.c') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 652becbc9a..6cb2ba8dbb 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -95,6 +95,7 @@ __attribute__((weak)) void unicode_input_start(void) { unicode_saved_mods = get_mods(); // Save current mods clear_mods(); // Unregister mods to start from a clean state + clear_weak_mods(); switch (unicode_config.input_mode) { case UC_MAC: -- cgit v1.2.3 From 6fc7c03e9581ddde68b32f2f76f8053628da6465 Mon Sep 17 00:00:00 2001 From: Chewxy Date: Mon, 15 Aug 2022 05:24:52 +1000 Subject: Added emacs as an "operating system" for input mode. (#16949) --- quantum/process_keycode/process_unicode_common.c | 40 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'quantum/process_keycode/process_unicode_common.c') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 6cb2ba8dbb..8de31c055c 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -117,6 +117,12 @@ __attribute__((weak)) void unicode_input_start(void) { tap_code(UNICODE_KEY_WINC); tap_code(KC_U); break; + case UC_EMACS: + // The usual way to type unicode in emacs is C-x-8 then the unicode number in hex + tap_code16(LCTL(KC_X)); + tap_code16(KC_8); + tap_code16(KC_ENTER); + break; } wait_ms(UNICODE_TYPE_DELAY); @@ -142,6 +148,9 @@ __attribute__((weak)) void unicode_input_finish(void) { case UC_WINC: tap_code(KC_ENTER); break; + case UC_EMACS: + tap_code16(KC_ENTER); + break; } set_mods(unicode_saved_mods); // Reregister previously set mods @@ -167,6 +176,9 @@ __attribute__((weak)) void unicode_input_cancel(void) { tap_code(KC_NUM_LOCK); } break; + case UC_EMACS: + tap_code16(LCTL(KC_G)); // C-g cancels + break; } set_mods(unicode_saved_mods); // Reregister previously set mods @@ -299,14 +311,30 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { cycle_unicode_input_mode(shifted ? +1 : -1); audio_helper(); break; - - case UNICODE_MODE_MAC ... UNICODE_MODE_WINC: { - // Keycodes and input modes follow the same ordering - uint8_t delta = keycode - UNICODE_MODE_MAC; - set_unicode_input_mode(UC_MAC + delta); + case UNICODE_MODE_MAC: + set_unicode_input_mode(UC_MAC); + audio_helper(); + break; + case UNICODE_MODE_LNX: + set_unicode_input_mode(UC_LNX); + audio_helper(); + break; + case UNICODE_MODE_WIN: + set_unicode_input_mode(UC_WIN); + audio_helper(); + break; + case UNICODE_MODE_BSD: + set_unicode_input_mode(UC_BSD); + audio_helper(); + break; + case UNICODE_MODE_WINC: + set_unicode_input_mode(UC_WINC); + audio_helper(); + break; + case UNICODE_MODE_EMACS: + set_unicode_input_mode(UC_EMACS); audio_helper(); break; - } } } -- cgit v1.2.3