]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/keycode_config.c
[Keymap] Add missing tap dance action and fix RGB hues in personal keymaps (#6312)
[qmk_firmware.git] / quantum / keycode_config.c
1 /* Copyright 2016 Jack Humbert
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 #include "keycode_config.h"
18
19 extern keymap_config_t keymap_config;
20
21 uint16_t keycode_config(uint16_t keycode) {
22
23     switch (keycode) {
24         case KC_CAPSLOCK:
25         case KC_LOCKING_CAPS:
26             if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
27                 return KC_LCTL;
28             }
29             return keycode;
30         case KC_LCTL:
31             if (keymap_config.swap_control_capslock) {
32                 return KC_CAPSLOCK;
33             }
34             return KC_LCTL;
35         case KC_LALT:
36             if (keymap_config.swap_lalt_lgui) {
37                 if (keymap_config.no_gui) {
38                     return KC_NO;
39                 }
40                 return KC_LGUI;
41             }
42             return KC_LALT;
43         case KC_LGUI:
44             if (keymap_config.swap_lalt_lgui) {
45                 return KC_LALT;
46             }
47             if (keymap_config.no_gui) {
48                 return KC_NO;
49             }
50             return KC_LGUI;
51         case KC_RALT:
52             if (keymap_config.swap_ralt_rgui) {
53                 if (keymap_config.no_gui) {
54                     return KC_NO;
55                 }
56                 return KC_RGUI;
57             }
58             return KC_RALT;
59         case KC_RGUI:
60             if (keymap_config.swap_ralt_rgui) {
61                 return KC_RALT;
62             }
63             if (keymap_config.no_gui) {
64                 return KC_NO;
65             }
66             return KC_RGUI;
67         case KC_GRAVE:
68             if (keymap_config.swap_grave_esc) {
69                 return KC_ESC;
70             }
71             return KC_GRAVE;
72         case KC_ESC:
73             if (keymap_config.swap_grave_esc) {
74                 return KC_GRAVE;
75             }
76             return KC_ESC;
77         case KC_BSLASH:
78             if (keymap_config.swap_backslash_backspace) {
79                 return KC_BSPACE;
80             }
81             return KC_BSLASH;
82         case KC_BSPACE:
83             if (keymap_config.swap_backslash_backspace) {
84                 return KC_BSLASH;
85             }
86             return KC_BSPACE;
87         default:
88             return keycode;
89     }
90 }
91
92 uint8_t mod_config(uint8_t mod) {
93     if (keymap_config.swap_lalt_lgui) {
94         if ((mod & MOD_RGUI) == MOD_LGUI) {
95             mod &= ~MOD_LGUI;
96             mod |= MOD_LALT;
97         } else if ((mod & MOD_RALT) == MOD_LALT) {
98             mod &= ~MOD_LALT;
99             mod |= MOD_LGUI;
100         }
101     }
102     if (keymap_config.swap_ralt_rgui) {
103         if ((mod & MOD_RGUI) == MOD_RGUI) {
104             mod &= ~MOD_RGUI;
105             mod |= MOD_RALT;
106         } else if ((mod & MOD_RALT) == MOD_RALT) {
107             mod &= ~MOD_RALT;
108             mod |= MOD_RGUI;
109         }
110     }
111     if (keymap_config.no_gui) {
112         mod &= ~MOD_LGUI;
113         mod &= ~MOD_RGUI;
114     }
115
116     return mod;
117 }