summaryrefslogtreecommitdiff
path: root/quantum/keymap_common.c
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-24 14:28:37 +0100
committerGitHub <noreply@github.com>2021-08-24 14:28:37 +0100
commitc4dbf4bf0118dd785802861beb247433b5b7411d (patch)
tree91e5142e9c280db4fbee6c0d7e64f1abdad79109 /quantum/keymap_common.c
parentc4a2dc9a2d1b0c053272aec7672ab8df92550e88 (diff)
Tidy up quantum.c now some of tmk_core has been merged (#14083)
Diffstat (limited to 'quantum/keymap_common.c')
-rw-r--r--quantum/keymap_common.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 780c71ab9b..008177bbee 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -36,6 +36,31 @@ extern keymap_config_t keymap_config;
#include <inttypes.h>
+uint8_t extract_mod_bits(uint16_t code) {
+ switch (code) {
+ case QK_MODS ... QK_MODS_MAX:
+ break;
+ default:
+ return 0;
+ }
+
+ uint8_t mods_to_send = 0;
+
+ if (code & QK_RMODS_MIN) { // Right mod flag is set
+ if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
+ if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
+ if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
+ if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
+ } else {
+ if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
+ if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
+ if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
+ if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
+ }
+
+ return mods_to_send;
+}
+
/* converts key to action */
action_t action_for_key(uint8_t layer, keypos_t key) {
// 16bit keycodes - important