]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/keycode_config.c
I corrected my name.
[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 /** \brief keycode_config
22  *
23  * This function is used to check a specific keycode against the bootmagic config,
24  * and will return the corrected keycode, when appropriate.
25  */
26 uint16_t keycode_config(uint16_t keycode) {
27     switch (keycode) {
28         case KC_CAPSLOCK:
29         case KC_LOCKING_CAPS:
30             if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
31                 return KC_LCTL;
32             }
33             return keycode;
34         case KC_LCTL:
35             if (keymap_config.swap_control_capslock) {
36                 return KC_CAPSLOCK;
37             }
38             if (keymap_config.swap_lctl_lgui) {
39                 if (keymap_config.no_gui) {
40                     return KC_NO;
41                 }
42                 return KC_LGUI;
43             }
44             return KC_LCTL;
45         case KC_LALT:
46             if (keymap_config.swap_lalt_lgui) {
47                 if (keymap_config.no_gui) {
48                     return KC_NO;
49                 }
50                 return KC_LGUI;
51             }
52             return KC_LALT;
53         case KC_LGUI:
54             if (keymap_config.swap_lalt_lgui) {
55                 return KC_LALT;
56             }
57             if (keymap_config.swap_lctl_lgui) {
58                 return KC_LCTRL;
59             }
60             if (keymap_config.no_gui) {
61                 return KC_NO;
62             }
63             return KC_LGUI;
64         case KC_RCTL:
65             if (keymap_config.swap_rctl_rgui) {
66                 if (keymap_config.no_gui) {
67                     return KC_NO;
68                 }
69                 return KC_RGUI;
70             }
71             return KC_RCTL;
72         case KC_RALT:
73             if (keymap_config.swap_ralt_rgui) {
74                 if (keymap_config.no_gui) {
75                     return KC_NO;
76                 }
77                 return KC_RGUI;
78             }
79             return KC_RALT;
80         case KC_RGUI:
81             if (keymap_config.swap_ralt_rgui) {
82                 return KC_RALT;
83             }
84             if (keymap_config.swap_rctl_rgui) {
85                 return KC_RCTL;
86             }
87             if (keymap_config.no_gui) {
88                 return KC_NO;
89             }
90             return KC_RGUI;
91         case KC_GRAVE:
92             if (keymap_config.swap_grave_esc) {
93                 return KC_ESC;
94             }
95             return KC_GRAVE;
96         case KC_ESC:
97             if (keymap_config.swap_grave_esc) {
98                 return KC_GRAVE;
99             }
100             return KC_ESC;
101         case KC_BSLASH:
102             if (keymap_config.swap_backslash_backspace) {
103                 return KC_BSPACE;
104             }
105             return KC_BSLASH;
106         case KC_BSPACE:
107             if (keymap_config.swap_backslash_backspace) {
108                 return KC_BSLASH;
109             }
110             return KC_BSPACE;
111         default:
112             return keycode;
113     }
114 }
115
116 /** \brief mod_config
117  *
118  *  This function checks the mods passed to it against the bootmagic config,
119  *  and will remove or replace mods, based on that.
120  */
121
122 uint8_t mod_config(uint8_t mod) {
123     if (keymap_config.swap_lalt_lgui) {
124         if ((mod & MOD_RGUI) == MOD_LGUI) {
125             mod &= ~MOD_LGUI;
126             mod |= MOD_LALT;
127         } else if ((mod & MOD_RALT) == MOD_LALT) {
128             mod &= ~MOD_LALT;
129             mod |= MOD_LGUI;
130         }
131     }
132     if (keymap_config.swap_ralt_rgui) {
133         if ((mod & MOD_RGUI) == MOD_RGUI) {
134             mod &= ~MOD_RGUI;
135             mod |= MOD_RALT;
136         } else if ((mod & MOD_RALT) == MOD_RALT) {
137             mod &= ~MOD_RALT;
138             mod |= MOD_RGUI;
139         }
140     }
141     if (keymap_config.swap_lctl_lgui) {
142         if ((mod & MOD_RGUI) == MOD_LGUI) {
143             mod &= ~MOD_LGUI;
144             mod |= MOD_LCTL;
145         } else if ((mod & MOD_RCTL) == MOD_LCTL) {
146             mod &= ~MOD_LCTL;
147             mod |= MOD_LGUI;
148         }
149     }
150     if (keymap_config.swap_rctl_rgui) {
151         if ((mod & MOD_RGUI) == MOD_RGUI) {
152             mod &= ~MOD_RGUI;
153             mod |= MOD_RCTL;
154         } else if ((mod & MOD_RCTL) == MOD_RCTL) {
155             mod &= ~MOD_RCTL;
156             mod |= MOD_RGUI;
157         }
158     }
159     if (keymap_config.no_gui) {
160         mod &= ~MOD_LGUI;
161         mod &= ~MOD_RGUI;
162     }
163
164     return mod;
165 }