Correct the construction of Consumer Control Key objects

There were a few minor problems in the way Consumer `Key` objects were
constructed (using `CONSUMER_KEY()`). First, no masking of the high
bits was being done, so it was possible to create a "Consumer" key
with the `RESERVED` bit set (e.g. `Key_Transparent`), or the
`SWITCH_TO_KEYMAP` bit (in fact, any `Key` value with both the
`SYNTHETIC` and `IS_CONSUMER` bits set was possible).

Second, the high six bits of the raw `Key` value should always be
`010010` (`SYNTHETIC | IS_CONSUMER`), as Consumer keys don't have any
flags. The macro should really only take one argument: a 16-bit
integer keycode value. The `HID_TYPE_*` constants really shouldn't be
used at all in defining the keys in key_defs_consumer.h, because
setting those bits could potentially cause a key to be misidentified
by some plugin.

This change fixes these potential problems by ignoring the `flags`
parameter, masking the high six bits of the `code` supplied, and
setting those high six bits to the correct value.
pull/915/head
Michael Richters 4 years ago committed by Jesse Vincent
parent ad5031f64a
commit 5cecf381c3
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -238,6 +238,8 @@ typedef kaleidoscope::Key Key_;
#define HID_TYPE_OSC B00010000
#define HID_TYPE_RTC B00010100
#define HID_TYPE_SEL B00011000
// Mask defining the allowed usage type flag bits:
#define HID_TYPE_MASK B00110000
#define Key_NoKey Key(0, KEY_FLAGS)
@ -263,8 +265,11 @@ typedef kaleidoscope::Key Key_;
use the 10 lsb as the HID Consumer code. If you need to get the keycode of a Consumer key
use the CONSUMER(key) macro this will return the 10bit keycode.
*/
#define CONSUMER(key) (key.getRaw() & 0x03FF)
#define CONSUMER_KEY(code, flags) Key((code) | ((flags | SYNTHETIC|IS_CONSUMER) << 8))
constexpr uint16_t CONSUMER_KEYCODE_MASK = 0x03FF;
#define CONSUMER(key) (key.getRaw() & CONSUMER_KEYCODE_MASK)
#define CONSUMER_KEY(code, hid_type) \
Key((code & CONSUMER_KEYCODE_MASK) | \
((SYNTHETIC | IS_CONSUMER | (hid_type & HID_TYPE_MASK)) << 8))
namespace kaleidoscope {
constexpr Key bad_keymap_key{0, RESERVED};

Loading…
Cancel
Save