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

New keycode macro (XP) for shifted character pairs using UNICODEMAP + bug fixes and improvements #4803

Merged
merged 30 commits into from
May 3, 2019

Conversation

vomindoraan
Copy link
Contributor

@vomindoraan vomindoraan commented Jan 8, 2019

Add XP(i, j), a keycode macro1 like UC and X that allows users to easily input pairs of Unicode characters. The most common use case for this is inputting lower and upper case versions of a character, for example å/Å, based on whether Shift or Caps Lock are active.

Also improve parts of the existing Unicode code, for example by adding a unicode_input_cancel() function and fixing an off-by-one error in a range check in process_unicode(). The latest version of WinCompose increased the range of supported code points, so I implemented this as well.

I've also made some substantial improvements to the Unicode docs in this PR.

Description

Currently, to add a key that sends å or Å you would need to define a custom keycode, then handle the Shift/Caps logic yourself and output the corresponding character. XP makes this a lot easier: you just need to add XP(i, j) to your keymap, where i is the index of the first (lower case) and j the index of the second (upper case) character in unicode_map.

This was done by expanding the QK_UNICODEMAP range from 0x8000–0x83FF to 0x8000–0xFFFF. This makes the UNICODEMAP range equal to the range for UNICODE. This shouldn't be an issue as the two are feature flagged and guaranteed to be mutually exclusive. It also doesn't affect existing keycode ordering and keymap storage in EEPROM as there can be no keycodes above 0xFFFF anyway.

The two character indices are then packed into the 16-bit keycode as follows:

11ii iiii ijjj jjjj
├┘└───┬───┘└──┬───┘
│     │       7 bits for second char index (0–127)
│     7 bits for first char index (0–127)
Denotes QK_UNICODEMAP_PAIR range

process_unicodemap() unpacks this value, checks the Shift and Caps states, then outputs the appropriate character from unicode_map.

Changes

  • Add new keycode macro1 XP(i, j) for the feature.
  • Expand UNICODEMAP Quantum keycode range2 from 0x8000–0x83FF to 0x8000–0xFFFF.
  • Fix bugged range check (OB1 error) in process_unicode() (> was being used instead of >=); make this check more robust by comparing keycodes with the upper bound as well.
  • Replace unicodemap_input_error() (unused) with more generic unicode_input_cancel().
  • Tweak how unicode_input_start() and unicode_input_finish() are called in process_unicodemap() as part of the XP implementation.
  • Tweak Unicode headers (add missing declarations, newlines; remove redundant includes).
  • Rename UNICODE_OSX_KEYUNICODE_KEY_OSX and UNICODE_WINC_KEYUNICODE_KEY_WINC for consistency and ease of search.3
  • Add UNICODE_KEY_LNX since the input combo for Linux may have changed in newer versions of IBus.3
  • Update related documentation.

1 Doesn't affect keycode ordering and EEPROM keymap storage since it's a macro.
2 Doesn't affect keycode ordering and EEPROM keymap storage since the space above 0x8000 is already reserved for UNICODE/UNICODEMAP.
3 Slightly outside the scope of this PR, but I figured I might as well do it now.


Thanks @asmand for giving me the idea for this feature and providing the use case.

Tested and confirmed working on Windows, Mac and Linux. Currently it doesn't work correctly on Linux if Caps Lock is on, but it turns out that's a preexisting issue with how we send Unicode input. I will open an issue and make a separate PR for that.

Types of changes

  • Core
  • Bugfix
  • New Feature
  • Enhancement/Optimization
  • Keyboard (addition or update)
  • Keymap/Layout/Userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document. (https://docs.qmk.fm/#/contributing)
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@vomindoraan vomindoraan changed the title New keycode macro (XS) for shifted character pairs in UNICODEMAP New keycode macro (XS) for shifted character pairs using UNICODEMAP Jan 8, 2019
@vomindoraan vomindoraan changed the title New keycode macro (XS) for shifted character pairs using UNICODEMAP New keycode macro (XS) for shifted character pairs using UNICODEMAP + bug fixes and improvements Jan 8, 2019
@vomindoraan
Copy link
Contributor Author

I will retest these latest changes on Mac and Linux tomorrow.

@vomindoraan
Copy link
Contributor Author

vomindoraan commented Jan 8, 2019

I renamed the keycode range from QK_UNICODEMAP_SHIFT to QK_UNICODEMAP_PAIR, but I'm not sure if XP(i, j) is better than XS(i, j).

Edit: I decided to go with XP.

@vomindoraan vomindoraan changed the title New keycode macro (XS) for shifted character pairs using UNICODEMAP + bug fixes and improvements New keycode macro (XP) for shifted character pairs using UNICODEMAP + bug fixes and improvements Jan 9, 2019
@vomindoraan
Copy link
Contributor Author

Updated docs per review feedback.

@jackhumbert @drashna Any chance you could take a look at this PR again and merge it?

@vomindoraan
Copy link
Contributor Author

vomindoraan commented Mar 24, 2019

This PR should probably be labeled documentation as well, given the large set of changes/improvements to the Unicode docs.

Copy link
Member

@skullydazed skullydazed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still like @jackhumbert to weigh in on the expanded keycode issue.

@vomindoraan
Copy link
Contributor Author

@jackhumbert Could you please take a look at the keycode ranges so this can be merged? It's the only thing that's left to do.

@vomindoraan
Copy link
Contributor Author

vomindoraan commented May 3, 2019

Retested with latest master merged in, and confirmed working on Windows, Mac and Linux (thanks to my wonderful coworkers who let me use their machines).

@drashna drashna merged commit bdc8d89 into qmk:master May 3, 2019
@vomindoraan vomindoraan deleted the unicodemap_shift branch May 3, 2019 16:39
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request May 6, 2019
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
foosinn pushed a commit to foosinn/qmk_firmware that referenced this pull request May 6, 2019
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
KauyonKais pushed a commit to KauyonKais/qmk_firmware that referenced this pull request May 8, 2019
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
KauyonKais pushed a commit to KauyonKais/qmk_firmware that referenced this pull request May 8, 2019
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
Timbus pushed a commit to Timbus/qmk_firmware that referenced this pull request Jun 23, 2019
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
ridingqwerty pushed a commit to ridingqwerty/qmk_firmware that referenced this pull request Jan 10, 2020
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
JeffreyPalmer pushed a commit to JeffreyPalmer/qmk_firmware that referenced this pull request Feb 27, 2020
… bug fixes and improvements (qmk#4803)

* Expose unicode_saved_mods

* Add UNICODEMAP shift pair functionality and XS keycode

* Add XS to keycode reference documentation

* Pick pair index based on both Shift and Caps Lock state

* Add XS to Unicode feature docs

* Clean up process_unicode* headers

* Extract unicode_map index calculation into function

* Pick pair index as XOR rather than OR of Shift and Caps states

* unicode_input_start() has to be called before the unicode_map index is calculated

* Replace unicodemap_input_error() with more generic unicode_input_cancel()

* Replace register+tap+unregister with tap_code16(LCTL(LSFT(KC_U)))

* UNICODE_OSX_KEY → UNICODE_KEY_OSX, UNICODE_WINC_KEY → UNICODE_KEY_WINC

* Make keycode range checks more robust

* Fix keycode range checks for different input modes

* Add UNICODE_KEY_LNX, update docs

* QK_UNICODEMAP_SHIFT → QK_UNICODEMAP_PAIR

* XS → XP, update docs

* Tweak Unicode docs

* Use recently added MOD_MASK_SHIFT and IS_HOST_LED_ON helpers

* Update Unicode table in docs/keycodes.md

* Update Unicode docs per review comments

* Replace references to Mac OS X with macOS in Unicode docs

* As of v0.9.0, WinCompose supports all possible code points

* Expand descriptions in XP docs

* Update keycode table and cycling docs

* Further expand cycling docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants